Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/branchmap.py @ 49233:f923bdd7477d
branchmap: use a context manager when writing the branchmap
This is cleaner and safer. The previous code date from long before we had
context manager available.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 13 May 2022 15:19:57 +0200 |
parents | 642e31cb55f0 |
children | 227124098e14 |
comparison
equal
deleted
inserted
replaced
49232:71774d799de7 | 49233:f923bdd7477d |
---|---|
426 # | 426 # |
427 # (The cache warming setup by localrepo will update the file later.) | 427 # (The cache warming setup by localrepo will update the file later.) |
428 self._delayed = True | 428 self._delayed = True |
429 return | 429 return |
430 try: | 430 try: |
431 f = repo.cachevfs(self._filename(repo), b"w", atomictemp=True) | 431 filename = self._filename(repo) |
432 cachekey = [hex(self.tipnode), b'%d' % self.tiprev] | 432 with repo.cachevfs(filename, b"w", atomictemp=True) as f: |
433 if self.filteredhash is not None: | 433 cachekey = [hex(self.tipnode), b'%d' % self.tiprev] |
434 cachekey.append(hex(self.filteredhash)) | 434 if self.filteredhash is not None: |
435 f.write(b" ".join(cachekey) + b'\n') | 435 cachekey.append(hex(self.filteredhash)) |
436 nodecount = 0 | 436 f.write(b" ".join(cachekey) + b'\n') |
437 for label, nodes in sorted(self._entries.items()): | 437 nodecount = 0 |
438 label = encoding.fromlocal(label) | 438 for label, nodes in sorted(self._entries.items()): |
439 for node in nodes: | 439 label = encoding.fromlocal(label) |
440 nodecount += 1 | 440 for node in nodes: |
441 if node in self._closednodes: | 441 nodecount += 1 |
442 state = b'c' | 442 if node in self._closednodes: |
443 else: | 443 state = b'c' |
444 state = b'o' | 444 else: |
445 f.write(b"%s %s %s\n" % (hex(node), state, label)) | 445 state = b'o' |
446 f.close() | 446 f.write(b"%s %s %s\n" % (hex(node), state, label)) |
447 repo.ui.log( | 447 repo.ui.log( |
448 b'branchcache', | 448 b'branchcache', |
449 b'wrote %s with %d labels and %d nodes\n', | 449 b'wrote %s with %d labels and %d nodes\n', |
450 _branchcachedesc(repo), | 450 _branchcachedesc(repo), |
451 len(self._entries), | 451 len(self._entries), |