changeset 397:1d3aa6410b56

Updated hg-git
author unexist
date Fri, 04 Nov 2011 23:24:07 +0100
parents 86e934638667
children 87bc06cdeb5f
files .hgext/hg-git/Makefile .hgext/hg-git/hggit/__init__.py .hgext/hg-git/hggit/git_handler.py .hgext/hg-git/hggit/overlay.py .hgext/hg-git/setup.py
diffstat 5 files changed, 57 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/.hgext/hg-git/Makefile	Fri Nov 04 23:18:24 2011 +0100
+++ b/.hgext/hg-git/Makefile	Fri Nov 04 23:24:07 2011 +0100
@@ -20,6 +20,7 @@
 	(cd $(CREW) ; $(MAKE) clean ) && \
 	cd tests && $(PYTHON) $(CREW)/tests/run-tests.py $(TESTFLAGS)
 
-all-version-tests: tests-1.4.3 tests-1.5.4 tests-1.6.2 tests-1.7.2 tests-tip
+all-version-tests: tests-1.4.3 tests-1.5.4 tests-1.6.2 tests-1.7.2 \
+                   tests-1.9.2 tests-tip
 
 .PHONY: tests all-version-tests
--- a/.hgext/hg-git/hggit/__init__.py	Fri Nov 04 23:18:24 2011 +0100
+++ b/.hgext/hg-git/hggit/__init__.py	Fri Nov 04 23:24:07 2011 +0100
@@ -37,8 +37,9 @@
 
 # support for `hg clone git://github.com/defunkt/facebox.git`
 # also hg clone git+ssh://git@github.com/schacon/simplegit.git
-hg.schemes['git'] = gitrepo
-hg.schemes['git+ssh'] = gitrepo
+_gitschemes = ('git', 'git+ssh', 'git+http', 'git+https')
+for _scheme in _gitschemes:
+    hg.schemes[_scheme] = gitrepo
 
 # support for `hg clone localgitrepo`
 _oldlocal = hg.schemes['file']
@@ -70,7 +71,7 @@
 
 hgdefaultdest = hg.defaultdest
 def defaultdest(source):
-    for scheme in ('git', 'git+ssh'):
+    for scheme in _gitschemes:
         if source.startswith('%s://' % scheme) and source.endswith('.git'):
             source = source[:-4]
             break
@@ -130,6 +131,10 @@
         kwname = 'onlyheads'
     def findoutgoing(orig, local, remote, *args, **kwargs):
         if isinstance(remote, gitrepo.gitrepo):
+            hgver = hg.util.version()
+            if hgver >= '1.8.9' or (hgver > '1.8' and '+' in hgver):
+                raise hgutil.Abort(
+                    'hg-git outgoing support is broken on hg 1.9.x')
             # clean up this cruft when we're 1.7-only, remoteheads and
             # the return value change happened between 1.6 and 1.7.
             kw = {}
@@ -158,7 +163,10 @@
 
 def getremotechanges(orig, ui, repo, other, *args, **opts):
     if isinstance(other, gitrepo.gitrepo):
-        revs = opts.get('onlyheads', opts.get('revs'))
+        if args:
+            revs = args[0]
+        else:
+            revs = opts.get('onlyheads', opts.get('revs'))
         git = GitHandler(repo, ui)
         r, c, cleanup = git.getremotechanges(other, revs)
         # ugh. This is ugly even by mercurial API compatibility standards
--- a/.hgext/hg-git/hggit/git_handler.py	Fri Nov 04 23:18:24 2011 +0100
+++ b/.hgext/hg-git/hggit/git_handler.py	Fri Nov 04 23:24:07 2011 +0100
@@ -13,6 +13,11 @@
     from mercurial import commands
 except ImportError:
     from hgext import bookmarks
+try:
+    from mercurial.error import RepoError
+except ImportError:
+    from mercurial.repo import RepoError
+
 from mercurial.i18n import _
 from mercurial.node import hex, bin, nullid
 from mercurial import context, util as hgutil
@@ -113,7 +118,10 @@
         file = self.repo.opener(self.mapfile, 'w+', atomictemp=True)
         for hgsha, gitsha in sorted(self._map_hg.iteritems()):
             file.write("%s %s\n" % (gitsha, hgsha))
-        file.rename()
+        # If this complains that NoneType is not callable, then
+        # atomictempfile no longer has either of rename (pre-1.9) or
+        # close (post-1.9)
+        getattr(file, 'rename', getattr(file, 'close', None))()
 
     def load_tags(self):
         self.tags = {}
@@ -127,7 +135,10 @@
         for name, sha in sorted(self.tags.iteritems()):
             if not self.repo.tagtype(name) == 'global':
                 file.write("%s %s\n" % (sha, name))
-        file.rename()
+        # If this complains that NoneType is not callable, then
+        # atomictempfile no longer has either of rename (pre-1.9) or
+        # close (post-1.9)
+        getattr(file, 'rename', getattr(file, 'close', None))()
 
     ## END FILE LOAD AND SAVE METHODS
 
@@ -135,6 +146,7 @@
 
     def import_commits(self, remote_name):
         self.import_git_objects(remote_name)
+        self.update_hg_bookmarks(self.git.get_refs())
         self.save_map()
 
     def fetch(self, remote, heads):
@@ -337,24 +349,27 @@
         self.swap_out_encoding(oldenc)
         return commit.id
 
+    def get_valid_git_username_email(self, name):
+        return name.lstrip('< ').rstrip('> ')
+
     def get_git_author(self, ctx):
         # hg authors might not have emails
         author = ctx.user()
 
         # check for git author pattern compliance
-        regex = re.compile('^(.*?) \<(.*?)\>(.*)$')
+        regex = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')
         a = regex.match(author)
 
         if a:
             name = a.group(1)
             email = a.group(2)
-            if len(a.group(3)) > 0:
+            if a.group(3) != None and len(a.group(3)) != 0:
                 name += ' ext:(' + urllib.quote(a.group(3)) + ')'
-            author = name + ' <' + email + '>'
+            author = self.get_valid_git_username_email(name) + ' <' + self.get_valid_git_username_email(email) + '>'
         elif '@' in author:
-            author = author + ' <' + author + '>'
+            author = self.get_valid_git_username_email(author) + ' <' + self.get_valid_git_username_email(author) + '>'
         else:
-            author = author + ' <none@none>'
+            author = self.get_valid_git_username_email(author) + ' <none@none>'
 
         if 'author' in ctx.extra():
             author = "".join(apply_delta(author, ctx.extra()['author']))
@@ -1079,5 +1094,17 @@
                         transportpath = path
 
                 return transport(host, thin_packs=False, port=port), transportpath
+
+        httpclient = getattr(client, 'HttpGitClient', None)
+
+        if uri.startswith('git+http://') or uri.startswith('git+https://'):
+            uri = uri[4:]
+
+        if uri.startswith('http://') or uri.startswith('https://'):
+            if not httpclient:
+                raise RepoError('git via HTTP requires dulwich 0.8.1 or later')
+            else:
+                return client.HttpGitClient(uri, thin_packs=False), uri
+
         # if its not git or git+ssh, try a local url..
         return client.SubprocessGitClient(thin_packs=False), uri
--- a/.hgext/hg-git/hggit/overlay.py	Fri Nov 04 23:18:24 2011 +0100
+++ b/.hgext/hg-git/hggit/overlay.py	Fri Nov 04 23:24:07 2011 +0100
@@ -42,15 +42,15 @@
         self._flagmap = {}
 
         def addtree(tree, dirname):
-            for entry in tree.entries():
-                if entry[0] & 040000:
+            for entry in tree.iteritems():
+                if entry.mode & 040000:
                     # expand directory
-                    subtree = self.repo.handler.git.get_object(entry[2])
-                    addtree(subtree, dirname + entry[1] + '/')
+                    subtree = self.repo.handler.git.get_object(entry.sha)
+                    addtree(subtree, dirname + entry.path + '/')
                 else:
-                    path = dirname + entry[1]
-                    self._map[path] = bin(entry[2])
-                    self._flagmap[path] = entry[0]
+                    path = dirname + entry.path
+                    self._map[path] = bin(entry.sha)
+                    self._flagmap[path] = entry.mode
 
         addtree(self.tree, '')
 
--- a/.hgext/hg-git/setup.py	Fri Nov 04 23:18:24 2011 +0100
+++ b/.hgext/hg-git/setup.py	Fri Nov 04 23:24:07 2011 +0100
@@ -5,7 +5,7 @@
 
 setup(
     name='hg-git',
-    version='0.2.6',
+    version='0.3.1',
     author='Scott Chacon',
     maintainer='Augie Fackler',
     maintainer_email='durin42@gmail.com',
@@ -19,5 +19,5 @@
     keywords='hg git mercurial',
     license='GPLv2',
     packages=['hggit'],
-    install_requires=['dulwich>=0.6.0'],
+    install_requires=['dulwich>=0.8.0'],
 )