diff hggit/git_handler.py @ 305:ad2ea8d6ef94

update_remote_branches: refactor head usage Splice the ref name only once, and don't loop through refs/heads multiple times. This changes the order in which hg tags are created; update test output to reflect this.
author Tay Ray Chuan <rctay89@gmail.com>
date Mon, 29 Mar 2010 13:05:59 +0800
parents 60acfbd75382
children aba4284f41ec
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -710,24 +710,24 @@
                          ' bookmarks enabled?\n'))
 
     def update_remote_branches(self, remote_name, refs):
-        heads = dict([(ref[11:],refs[ref]) for ref in refs
-                      if ref.startswith('refs/heads/')])
-
-        for head, sha in heads.iteritems():
+        def _set_hg_tag(head, sha):
             # refs contains all the refs in the server, not just the ones
             # we are pulling
             if sha not in self.git.object_store:
-                continue
+                return
             hgsha = bin(self.map_hg_get(sha))
             tag = '%s/%s' % (remote_name, head)
             self.repo.tag(tag, hgsha, '', True, None, None)
 
-        for ref_name in refs:
+        for ref_name, sha in refs.iteritems():
             if ref_name.startswith('refs/heads'):
-                new_ref = 'refs/remotes/%s/%s' % (remote_name, ref_name[11:])
-                self.git.refs[new_ref] = refs[ref_name]
+                head = ref_name[11:]
+                _set_hg_tag(head, sha)
+
+                new_ref = 'refs/remotes/%s/%s' % (remote_name, head)
+                self.git.refs[new_ref] = sha
             elif ref_name.startswith('refs/tags'):
-                self.git.refs[ref_name] = refs[ref_name]
+                self.git.refs[ref_name] = sha
 
 
     ## UTILITY FUNCTIONS