Commits

Waldemar Kornewald  committed e4e9475

made "clone" command override more robust (it was incompatible with the latest stable release)

  • Participants
  • Parent commits 87e8778

Comments (0)

Files changed (1)

File rewriteurls.py

 a rewritten "default" URL. The rewrite rules are defined via regexes in hgrc.
 '''
 
-from mercurial import hg, ui, util
+from mercurial import commands, extensions, ui, util
+import os
 import re
 
 def rewrite_url(ui, path, section):
                              % (ui.source(section, pattern), e))
     return path
 
-def clone(ui, source, *args, **kwargs):
+def clone(orig, ui, source, dest=None, **kwargs):
     new_source = rewrite_url(ui, source, 'rewriteurls')
-    src_repo, dst_repo = _orig_clone(ui, new_source, *args, **kwargs)
-    fp = dst_repo.opener('hgrc', 'r', text=True)
-    content = fp.read()
-    fp.close()
-    fp = dst_repo.opener('hgrc', 'w', text=True)
+    result = orig(ui, new_source, dest=dest, **kwargs)
+    if result:
+        return result
+
+    if not dest:
+        dest = source.replace('\\', '/').rsplit('/', 1)[-1]
+    with open(os.path.join(dest, '.hg', 'hgrc'), 'r') as fp:
+        content = fp.read()
     source = ui.expandpath(source)
-    fp.write(content.replace(' %s\n' % new_source, ' %s\n' % source))
-    fp.close()
-    return src_repo, dst_repo
+    with open(os.path.join(dest, '.hg', 'hgrc'), 'w') as fp:
+        fp.write(content.replace(' %s\n' % new_source, ' %s\n' % source))
+    return result
 
-_orig_clone = None
 def uisetup(ui):
-    global _orig_clone
-    _orig_clone = hg.clone
-    hg.clone = clone
+    extensions.wrapcommand(commands.table, 'clone', clone)
 
 def reposetup(ui, repo):
     for name, path in list(ui.configitems('paths')):