comparison git_handler.py @ 127:695a90e72e4f

merge from ian dees
author Scott Chacon <schacon@gmail.com>
date Tue, 19 May 2009 09:33:46 -0700
parents 76a0e1ee7cf7 705b88c9f3d1
children 8cabda8ae1c6
comparison
equal deleted inserted replaced
122:76a0e1ee7cf7 127:695a90e72e4f
122 self.save_map() 122 self.save_map()
123 123
124 def push(self, remote_name): 124 def push(self, remote_name):
125 self.ui.status(_("pushing to : %s\n") % remote_name) 125 self.ui.status(_("pushing to : %s\n") % remote_name)
126 self.export() 126 self.export()
127 self.update_remote_references(remote_name)
127 self.upload_pack(remote_name) 128 self.upload_pack(remote_name)
128 129
129 def remote_add(self, remote_name, git_url): 130 def remote_add(self, remote_name, git_url):
130 self._config['remote.' + remote_name + '.url'] = git_url 131 self._config['remote.' + remote_name + '.url'] = git_url
131 self.save_config() 132 self.save_config()
152 153
153 def remote_name_to_url(self, remote_name): 154 def remote_name_to_url(self, remote_name):
154 return self._config['remote.' + remote_name + '.url'] 155 return self._config['remote.' + remote_name + '.url']
155 156
156 def update_references(self): 157 def update_references(self):
157 # TODO : if bookmarks exist, add them as git branches 158 try:
159 # We only care about bookmarks of the form 'name',
160 # not 'remote/name'.
161 def is_local_ref(item): return item[0].count('/') == 0
162 bms = bookmarks.parse(self.repo)
163 bms = dict(filter(is_local_ref, bms.items()))
164
165 # Create a local Git branch name for each
166 # Mercurial bookmark.
167 for key in bms:
168 hg_sha = hex(bms[key])
169 git_sha = self.map_git_get(hg_sha)
170 self.git.set_ref('refs/heads/' + key, git_sha)
171 except AttributeError:
172 # No bookmarks extension
173 pass
174
158 c = self.map_git_get(hex(self.repo.changelog.tip())) 175 c = self.map_git_get(hex(self.repo.changelog.tip()))
159 self.git.set_ref('refs/heads/master', c) 176 self.git.set_ref('refs/heads/master', c)
177
178 # Make sure there's a refs/remotes/remote_name/name
179 # for every refs/heads/name
180 def update_remote_references(self, remote_name):
181 self.git.set_remote_refs(self.local_heads(), remote_name)
182
183 def local_heads(self):
184 def is_local_head(item): return item[0].startswith('refs/heads')
185 refs = self.git.get_refs()
186 return dict(filter(is_local_head, refs.items()))
160 187
161 def export_git_objects(self): 188 def export_git_objects(self):
162 self.ui.status(_("exporting git objects\n")) 189 self.ui.status(_("exporting git objects\n"))
163 total = len(self.repo.changelog) 190 total = len(self.repo.changelog)
164 magnitude = int(math.log(total, 10)) + 1 if total else 1 191 magnitude = int(math.log(total, 10)) + 1 if total else 1
368 head = "/".join([v for v in parts[2:]]) 395 head = "/".join([v for v in parts[2:]])
369 local_ref = self.git.ref(ref_name) 396 local_ref = self.git.ref(ref_name)
370 if local_ref: 397 if local_ref:
371 if not local_ref == refs[ref_name]: 398 if not local_ref == refs[ref_name]:
372 changed[ref_name] = local_ref 399 changed[ref_name] = local_ref
400
401 # Also push any local branches not on the server yet
402 for head in self.local_heads():
403 if not head in refs:
404 ref = self.git.ref(head)
405 changed[head] = ref
406
373 return changed 407 return changed
374 408
375 # takes a list of shas the server wants and shas the server has 409 # takes a list of shas the server wants and shas the server has
376 # and generates a list of commit shas we need to push up 410 # and generates a list of commit shas we need to push up
377 def generate_pack_contents(self, want, have): 411 def generate_pack_contents(self, want, have):