changeset 814:345919960ea4

git_handler.get_changed_refs: switch to using get_exportable This also means we get to clean up a lot of the code around here. It isn't really feasible to break this up into several commits because the assumptions in the old calling code are too closely tied to the old local_heads() way of doing things.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 29 Oct 2014 12:30:23 -0700
parents 2e77e332f3b3
children 6cdeafb8ca46
files hggit/git_handler.py
diffstat 1 files changed, 19 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -287,9 +287,8 @@
         new_refs = {}
         def changed(refs):
             old_refs.update(refs)
-            to_push = set([v[1] for v in self.local_heads().itervalues()] +
-                          self.tags.values())
-            new_refs.update(self.get_changed_refs(refs, to_push, True))
+            exportable = self.get_exportable()
+            new_refs.update(self.get_changed_refs(refs, exportable, True))
             return refs # always return the same refs to make the send a no-op
 
         try:
@@ -912,10 +911,18 @@
         def changed(refs):
             self.ui.status(_("searching for changes\n"))
             old_refs.update(refs)
-            to_push = revs or set(
-                [v[1] for v in self.local_heads().itervalues()] +
-                self.tags.values())
-            return self.get_changed_refs(refs, to_push, force)
+            all_exportable = self.get_exportable()
+            if revs is None:
+                exportable = all_exportable
+            else:
+                exportable = {}
+                for rev in (hex(r) for r in revs):
+                    if rev not in all_exportable:
+                        raise hgutil.Abort("revision %s cannot be pushed since"
+                                           " it doesn't have a ref" %
+                                           self.repo[rev])
+                    exportable[rev] = all_exportable[rev]
+            return self.get_changed_refs(refs, exportable, force)
 
         def genpack(have, want):
             commits = []
@@ -947,7 +954,7 @@
         except (HangupException, GitProtocolError), e:
             raise hgutil.Abort(_("git remote error: ") + str(e))
 
-    def get_changed_refs(self, refs, revs, force):
+    def get_changed_refs(self, refs, exportable, force):
         new_refs = refs.copy()
         all_heads = self.local_heads()
 
@@ -965,18 +972,9 @@
                     bookmarks.setcurrent(self.repo, 'master')
                     new_refs['refs/heads/master'] = self.map_git_get(tip)
 
-        for rev in revs:
+        for rev, rev_refs in exportable.iteritems():
             ctx = self.repo[rev]
-            labels = lambda c: ctx.tags() + [
-                fltr for fltr, bm
-                in self._filter_for_bookmarks(ctx.bookmarks())
-            ]
-            prep = lambda itr: [i.replace(' ', '_') for i in itr]
-
-            heads = [t for t in prep(labels(ctx)) if t in all_heads]
-            tags = [t for t in prep(labels(ctx)) if t in self.tags]
-
-            if not (heads or tags):
+            if not rev_refs:
                 raise hgutil.Abort("revision %s cannot be pushed since"
                                    " it doesn't have a ref" % ctx)
 
@@ -988,8 +986,7 @@
             # dereferenced and stored as lightweight ones, as the annotated tag
             # is still stored in the git repo.
             uptodate_annotated_tags = []
-            for r in tags:
-                ref = 'refs/tags/'+r
+            for ref in rev_refs.tags:
                 # Check tag.
                 if not ref in refs:
                     continue
@@ -1004,12 +1001,7 @@
                 # If we've reached here, the tag's good.
                 uptodate_annotated_tags.append(ref)
 
-            for r in heads + tags:
-                if r in heads:
-                    ref = 'refs/heads/'+r
-                else:
-                    ref = 'refs/tags/'+r
-
+            for ref in rev_refs:
                 if ref not in refs:
                     new_refs[ref] = self.map_git_get(ctx.hex())
                 elif new_refs[ref] in self._map_git: