Mercurial > hg > hg-git
comparison hggit/git_handler.py @ 930:1a1d90e38651
refs: use dulwich to read remote refs
It is unclear to me why we keep a file (which can become out of sync) of remote
refs instead of just using dulwich. This caught a missing remote ref in the
test suite.
author | Sean Farley <sean@farley.io> |
---|---|
date | Sat, 16 May 2015 19:43:26 -0700 |
parents | 5f93caf337a9 |
children | a12e11d9fb11 |
comparison
equal
deleted
inserted
replaced
929:983126c08bad | 930:1a1d90e38651 |
---|---|
214 # If this complains, atomictempfile no longer has close | 214 # If this complains, atomictempfile no longer has close |
215 file.close() | 215 file.close() |
216 | 216 |
217 def load_remote_refs(self): | 217 def load_remote_refs(self): |
218 self._remote_refs = {} | 218 self._remote_refs = {} |
219 tagfile = self.repo.join(self.remote_refs_file) | 219 for k, v in self.git.refs.as_dict().iteritems(): |
220 if os.path.exists(tagfile): | 220 if k.startswith('refs/remotes'): |
221 tf = open(tagfile, 'rb') | 221 k = k.replace('refs/remotes/', '') |
222 tagdata = tf.read().split('\n') | 222 try: |
223 td = [line.split(' ', 1) for line in tagdata if line] | 223 self._remote_refs[k] = bin(self._map_git[v]) |
224 self._remote_refs.update([(name, bin(sha)) for sha, name in td]) | 224 except KeyError: |
225 | 225 pass |
226 def save_remote_refs(self): | |
227 file = self.repo.opener(self.remote_refs_file, 'w+', atomictemp=True) | |
228 for tag, node in self.remote_refs.iteritems(): | |
229 file.write('%s %s\n' % (hex(node), tag)) | |
230 # If this complains, atomictempfile no longer has close | |
231 file.close() | |
232 | 226 |
233 # END FILE LOAD AND SAVE METHODS | 227 # END FILE LOAD AND SAVE METHODS |
234 | 228 |
235 # COMMANDS METHODS | 229 # COMMANDS METHODS |
236 | 230 |
1331 new_ref = 'refs/remotes/%s/%s' % (remote_name, head) | 1325 new_ref = 'refs/remotes/%s/%s' % (remote_name, head) |
1332 self.git.refs[new_ref] = sha | 1326 self.git.refs[new_ref] = sha |
1333 elif (ref_name.startswith('refs/tags') and not | 1327 elif (ref_name.startswith('refs/tags') and not |
1334 ref_name.endswith('^{}')): | 1328 ref_name.endswith('^{}')): |
1335 self.git.refs[ref_name] = sha | 1329 self.git.refs[ref_name] = sha |
1336 | |
1337 self.save_remote_refs() | |
1338 | 1330 |
1339 # UTILITY FUNCTIONS | 1331 # UTILITY FUNCTIONS |
1340 | 1332 |
1341 def convert_git_int_mode(self, mode): | 1333 def convert_git_int_mode(self, mode): |
1342 # TODO: make these into constants | 1334 # TODO: make these into constants |