comparison hggit/git_handler.py @ 813: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
comparison
equal deleted inserted replaced
812:2e77e332f3b3 813:345919960ea4
285 client, path = self.get_transport_and_path(remote) 285 client, path = self.get_transport_and_path(remote)
286 old_refs = {} 286 old_refs = {}
287 new_refs = {} 287 new_refs = {}
288 def changed(refs): 288 def changed(refs):
289 old_refs.update(refs) 289 old_refs.update(refs)
290 to_push = set([v[1] for v in self.local_heads().itervalues()] + 290 exportable = self.get_exportable()
291 self.tags.values()) 291 new_refs.update(self.get_changed_refs(refs, exportable, True))
292 new_refs.update(self.get_changed_refs(refs, to_push, True))
293 return refs # always return the same refs to make the send a no-op 292 return refs # always return the same refs to make the send a no-op
294 293
295 try: 294 try:
296 client.send_pack(path, changed, lambda have, want: []) 295 client.send_pack(path, changed, lambda have, want: [])
297 296
910 change_totals = {} 909 change_totals = {}
911 910
912 def changed(refs): 911 def changed(refs):
913 self.ui.status(_("searching for changes\n")) 912 self.ui.status(_("searching for changes\n"))
914 old_refs.update(refs) 913 old_refs.update(refs)
915 to_push = revs or set( 914 all_exportable = self.get_exportable()
916 [v[1] for v in self.local_heads().itervalues()] + 915 if revs is None:
917 self.tags.values()) 916 exportable = all_exportable
918 return self.get_changed_refs(refs, to_push, force) 917 else:
918 exportable = {}
919 for rev in (hex(r) for r in revs):
920 if rev not in all_exportable:
921 raise hgutil.Abort("revision %s cannot be pushed since"
922 " it doesn't have a ref" %
923 self.repo[rev])
924 exportable[rev] = all_exportable[rev]
925 return self.get_changed_refs(refs, exportable, force)
919 926
920 def genpack(have, want): 927 def genpack(have, want):
921 commits = [] 928 commits = []
922 for mo in self.git.object_store.find_missing_objects(have, want): 929 for mo in self.git.object_store.find_missing_objects(have, want):
923 (sha, name) = mo 930 (sha, name) = mo
945 change_totals.get(Blob, 0))) 952 change_totals.get(Blob, 0)))
946 return old_refs, new_refs 953 return old_refs, new_refs
947 except (HangupException, GitProtocolError), e: 954 except (HangupException, GitProtocolError), e:
948 raise hgutil.Abort(_("git remote error: ") + str(e)) 955 raise hgutil.Abort(_("git remote error: ") + str(e))
949 956
950 def get_changed_refs(self, refs, revs, force): 957 def get_changed_refs(self, refs, exportable, force):
951 new_refs = refs.copy() 958 new_refs = refs.copy()
952 all_heads = self.local_heads() 959 all_heads = self.local_heads()
953 960
954 #The remote repo is empty and the local one doesn't have bookmarks/tags 961 #The remote repo is empty and the local one doesn't have bookmarks/tags
955 if refs.keys()[0] == 'capabilities^{}': 962 if refs.keys()[0] == 'capabilities^{}':
963 except NameError: 970 except NameError:
964 bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True) 971 bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True)
965 bookmarks.setcurrent(self.repo, 'master') 972 bookmarks.setcurrent(self.repo, 'master')
966 new_refs['refs/heads/master'] = self.map_git_get(tip) 973 new_refs['refs/heads/master'] = self.map_git_get(tip)
967 974
968 for rev in revs: 975 for rev, rev_refs in exportable.iteritems():
969 ctx = self.repo[rev] 976 ctx = self.repo[rev]
970 labels = lambda c: ctx.tags() + [ 977 if not rev_refs:
971 fltr for fltr, bm
972 in self._filter_for_bookmarks(ctx.bookmarks())
973 ]
974 prep = lambda itr: [i.replace(' ', '_') for i in itr]
975
976 heads = [t for t in prep(labels(ctx)) if t in all_heads]
977 tags = [t for t in prep(labels(ctx)) if t in self.tags]
978
979 if not (heads or tags):
980 raise hgutil.Abort("revision %s cannot be pushed since" 978 raise hgutil.Abort("revision %s cannot be pushed since"
981 " it doesn't have a ref" % ctx) 979 " it doesn't have a ref" % ctx)
982 980
983 # Check if the tags the server is advertising are annotated tags, 981 # Check if the tags the server is advertising are annotated tags,
984 # by attempting to retrieve it from the our git repo, and building a 982 # by attempting to retrieve it from the our git repo, and building a
986 # 984 #
987 # This is possible, even though (currently) annotated tags are 985 # This is possible, even though (currently) annotated tags are
988 # dereferenced and stored as lightweight ones, as the annotated tag 986 # dereferenced and stored as lightweight ones, as the annotated tag
989 # is still stored in the git repo. 987 # is still stored in the git repo.
990 uptodate_annotated_tags = [] 988 uptodate_annotated_tags = []
991 for r in tags: 989 for ref in rev_refs.tags:
992 ref = 'refs/tags/'+r
993 # Check tag. 990 # Check tag.
994 if not ref in refs: 991 if not ref in refs:
995 continue 992 continue
996 try: 993 try:
997 # We're not using Repo.tag(), as it's deprecated. 994 # We're not using Repo.tag(), as it's deprecated.
1002 continue 999 continue
1003 1000
1004 # If we've reached here, the tag's good. 1001 # If we've reached here, the tag's good.
1005 uptodate_annotated_tags.append(ref) 1002 uptodate_annotated_tags.append(ref)
1006 1003
1007 for r in heads + tags: 1004 for ref in rev_refs:
1008 if r in heads:
1009 ref = 'refs/heads/'+r
1010 else:
1011 ref = 'refs/tags/'+r
1012
1013 if ref not in refs: 1005 if ref not in refs:
1014 new_refs[ref] = self.map_git_get(ctx.hex()) 1006 new_refs[ref] = self.map_git_get(ctx.hex())
1015 elif new_refs[ref] in self._map_git: 1007 elif new_refs[ref] in self._map_git:
1016 rctx = self.repo[self.map_hg_get(new_refs[ref])] 1008 rctx = self.repo[self.map_hg_get(new_refs[ref])]
1017 if rctx.ancestor(ctx) == rctx or force: 1009 if rctx.ancestor(ctx) == rctx or force: