git_handler.fetch: actually return number of heads added or removed

The return value as implemented in git_handler.fetch was pretty bogus. It used
to return the number of values that changed in the 'refs/heads/' namespace,
regardless of whether multiple values in there point to the same Mercurial
commit, or whether particular heads were even imported. Fix all of that by
using the actual heads in the changelog, just like vanilla Mercurial.

The test output changes demonstrate examples where the code was buggy.
This commit is contained in:
Siddharth Agarwal 2014-03-04 16:05:19 -08:00
parent 0428a10ad5
commit 759062fbfd
4 changed files with 22 additions and 9 deletions

View File

@ -203,8 +203,10 @@ class GitHandler(object):
remote_name = self.remote_name(remote)
oldrefs = self.git.get_refs()
oldheads = self.repo.changelog.heads()
imported = 0
if refs:
self.import_git_objects(remote_name, refs)
imported = self.import_git_objects(remote_name, refs)
self.import_tags(refs)
self.update_hg_bookmarks(refs)
if remote_name:
@ -223,13 +225,24 @@ class GitHandler(object):
rn = remote_name or 'default'
return 'refs/remotes/' + rn + ref[10:]
modheads = [refs[k] for k in refs if k.startswith('refs/heads/')
and not k.endswith('^{}')
and refs[k] != oldrefs.get(remoteref(k))]
self.save_map()
return len(modheads)
if imported == 0:
return 0
# code taken from localrepo.py:addchangegroup
dh = 0
if oldheads:
heads = self.repo.changelog.heads()
dh = len(heads) - len(oldheads)
for h in heads:
if h not in oldheads and self.repo[h].closesbranch():
dh -= 1
if dh < 0:
return dh - 1
else:
return dh + 1
def export_commits(self):
try:

View File

@ -97,7 +97,7 @@ let's pull and try again
$ hg pull 2>&1 | grep -v 'divergent bookmark'
pulling from */gitrepo (glob)
importing git objects into hg
(run 'hg update' to get a working copy)
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg outgoing | sed 's/bookmark: /tag: /' | grep -v 'searching for changes'
comparing with */gitrepo (glob)
changeset: 1:0564f526fb0f

View File

@ -68,7 +68,7 @@ pull everything else
$ hg -R hgrepo pull
pulling from $TESTTMP/gitrepo
importing git objects into hg
(run 'hg update' to get a working copy)
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg -R hgrepo log --graph
o changeset: 2:37c124f2d0a0
| bookmark: master

View File

@ -71,7 +71,7 @@ this should fail
$ hg pull 2>&1 | grep -v 'divergent bookmark'
pulling from $TESTTMP/gitrepo
importing git objects into hg
(run 'hg update' to get a working copy)
(run 'hg heads' to see heads, 'hg merge' to merge)
TODO shouldn't need to do this since we're (in theory) pushing master explicitly,
which should not implicitly also push the not-master ref.
$ hg book not-master -r default/not-master --force