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.
This commit is contained in:
Tay Ray Chuan 2010-03-29 13:05:59 +08:00
parent 41495ccdb6
commit 336ec5a893
4 changed files with 15 additions and 15 deletions

View File

@ -710,24 +710,24 @@ class GitHandler(object):
' 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

View File

@ -19,8 +19,8 @@ creating and sending data
default::refs/heads/master => GIT:2b9ec6a4
@ changeset: 2:92d33c0dd6e1
| tag: master
| tag: default/master
| tag: tip
| tag: default/master
| user: test <test@example.com> (comment)
| date: Mon Jan 01 00:00:12 2007 +0000
| summary: modify beta
@ -45,8 +45,8 @@ importing Git objects into Hg
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
@ changeset: 2:92d33c0dd6e1
| tag: master
| tag: default/master
| tag: tip
| tag: default/master
| user: test <test@example.com> (comment)
| date: Mon Jan 01 00:00:12 2007 +0000
| summary: modify beta

View File

@ -21,8 +21,8 @@ creating and sending data
@ changeset: 2:d93a72262a83
| branch: gamma
| tag: master
| tag: default/master
| tag: tip
| tag: default/master
| user: test
| date: Mon Jan 01 00:00:12 2007 +0000
| summary: started branch gamma
@ -48,8 +48,8 @@ importing Git objects into Hg
o changeset: 2:d93a72262a83
| branch: gamma
| tag: master
| tag: default/master
| tag: tip
| tag: default/master
| user: test
| date: Mon Jan 01 00:00:12 2007 +0000
| summary: started branch gamma

View File

@ -15,8 +15,8 @@ creating and sending data
default::refs/heads/master => GIT:9a2616b9
@ changeset: 1:d529e9229f6d
| tag: master
| tag: default/master
| tag: tip
| tag: default/master
| user: test
| date: Mon Jan 01 00:00:11 2007 +0000
| summary: Added tag alpha for changeset 3442585be8a6
@ -39,8 +39,8 @@ importing Git objects into Hg
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
@ changeset: 1:d529e9229f6d
| tag: master
| tag: default/master
| tag: tip
| tag: default/master
| user: test
| date: Mon Jan 01 00:00:11 2007 +0000
| summary: Added tag alpha for changeset 3442585be8a6