Rather than separate updating and writing, create a subclass that doesn't write
on update. This minimises chances we forget to write out updates somewhere.
This also makes refactoring and improving the branchmap functionality easier.
| pulkit |
| hg-reviewers |
Rather than separate updating and writing, create a subclass that doesn't write
on update. This minimises chances we forget to write out updates somewhere.
This also makes refactoring and improving the branchmap functionality easier.
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
| mercurial/discovery.py | ||
|---|---|---|
| 242–243 | Indentation seems bad (seemed bad before too) | |
| mercurial/discovery.py | ||
|---|---|---|
| 242–243 | It's a generator expression as single argument. I was deliberately not making style changes in these patches, so I didn't touch the indentation here. If / when we auto-format code with black or something else, this'll be cleared up then, right? | |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/branchmap.py (15 lines) | |||
| M | mercurial/discovery.py (2 lines) |
| else: | else: | ||||
| subset = repo.filtered(subsetname) | subset = repo.filtered(subsetname) | ||||
| bcache = subset.branchmap().copy() | bcache = subset.branchmap().copy() | ||||
| extrarevs = subset.changelog.filteredrevs - cl.filteredrevs | extrarevs = subset.changelog.filteredrevs - cl.filteredrevs | ||||
| revs.extend(r for r in extrarevs if r <= bcache.tiprev) | revs.extend(r for r in extrarevs if r <= bcache.tiprev) | ||||
| revs.extend(cl.revs(start=bcache.tiprev + 1)) | revs.extend(cl.revs(start=bcache.tiprev + 1)) | ||||
| if revs: | if revs: | ||||
| bcache.update(repo, revs) | bcache.update(repo, revs) | ||||
| bcache.write(repo) | |||||
| assert bcache.validfor(repo), filtername | assert bcache.validfor(repo), filtername | ||||
| repo._branchcaches[repo.filtername] = bcache | repo._branchcaches[repo.filtername] = bcache | ||||
| def replacecache(repo, bm): | def replacecache(repo, bm): | ||||
| """Replace the branchmap cache for a repo with a branch mapping. | """Replace the branchmap cache for a repo with a branch mapping. | ||||
| This is likely only called during clone with a branch map from a remote. | This is likely only called during clone with a branch map from a remote. | ||||
| return heads | return heads | ||||
| def iterbranches(self): | def iterbranches(self): | ||||
| for bn, heads in self.iteritems(): | for bn, heads in self.iteritems(): | ||||
| yield (bn, heads) + self._branchtip(heads) | yield (bn, heads) + self._branchtip(heads) | ||||
| def copy(self): | def copy(self): | ||||
| """return an deep copy of the branchcache object""" | """return an deep copy of the branchcache object""" | ||||
| return branchcache(self, self.tipnode, self.tiprev, self.filteredhash, | return type(self)( | ||||
| self, self.tipnode, self.tiprev, self.filteredhash, | |||||
| self._closednodes) | self._closednodes) | ||||
| def write(self, repo): | def write(self, repo): | ||||
| try: | try: | ||||
| f = repo.cachevfs(self._filename(repo), "w", atomictemp=True) | f = repo.cachevfs(self._filename(repo), "w", atomictemp=True) | ||||
| cachekey = [hex(self.tipnode), '%d' % self.tiprev] | cachekey = [hex(self.tipnode), '%d' % self.tiprev] | ||||
| if self.filteredhash is not None: | if self.filteredhash is not None: | ||||
| cachekey.append(hex(self.filteredhash)) | cachekey.append(hex(self.filteredhash)) | ||||
| f.write(" ".join(cachekey) + '\n') | f.write(" ".join(cachekey) + '\n') | ||||
| self.tipnode = cl.node(tiprev) | self.tipnode = cl.node(tiprev) | ||||
| self.tiprev = tiprev | self.tiprev = tiprev | ||||
| self.filteredhash = scmutil.filteredhash(repo, self.tiprev) | self.filteredhash = scmutil.filteredhash(repo, self.tiprev) | ||||
| duration = util.timer() - starttime | duration = util.timer() - starttime | ||||
| repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n', | repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n', | ||||
| repo.filtername, duration) | repo.filtername, duration) | ||||
| self.write(repo) | |||||
| class remotebranchcache(branchcache): | |||||
| """Branchmap info for a remote connection, should not write locally""" | |||||
| def write(self, repo): | |||||
| pass | |||||
| # Revision branch info cache | # Revision branch info cache | ||||
| _rbcversion = '-v1' | _rbcversion = '-v1' | ||||
| _rbcnames = 'rbc-names' + _rbcversion | _rbcnames = 'rbc-names' + _rbcversion | ||||
| _rbcrevs = 'rbc-revs' + _rbcversion | _rbcrevs = 'rbc-revs' + _rbcversion | ||||
| # [4 byte hash prefix][4 byte branch name number with sign bit indicating open] | # [4 byte hash prefix][4 byte branch name number with sign bit indicating open] | ||||
| _rbcrecfmt = '>4sI' | _rbcrecfmt = '>4sI' | ||||
| _rbcrecsize = calcsize(_rbcrecfmt) | _rbcrecsize = calcsize(_rbcrecfmt) | ||||
Indentation seems bad (seemed bad before too)