# HG changeset patch # User Augie Fackler # Date 1465175903 14400 # Node ID 0a6b3da6d34cd0dffdecfb707563b6eb6f8b8275 # Parent b429e97666fd94b7fa3bbae14e2a86e0f37da9c5 RevMap: move lastpulled from SVNMeta down into RevMap There was a conceptual cycle present between the revmap and the meta object caused by this layering, which is nicely resolved by moving the lastpulled information down into the revmap. RevMap no longer makes use of meta outside the constructor, which is great progress. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -348,15 +348,35 @@ class RevMap(dict): def __init__(self, meta): dict.__init__(self) - self.meta = meta self._filepath = meta.revmap_file + self._lastpulled_file = os.path.join(meta.metapath, 'lastpulled') self._hashes = None + self.firstpulled = 0 + if os.path.exists(self._lastpulled_file): + with open(self._lastpulled_file) as f: + self._lastpulled = int(f.read()) + else: + self._lastpulled = 0 + if os.path.isfile(self._filepath): self._load() else: self._write() + def _writelastpulled(self): + with open(self._lastpulled_file, 'w') as f: + f.write('%d\n' % self.lastpulled) + + @property + def lastpulled(self): + return self._lastpulled + + @lastpulled.setter + def lastpulled(self, value): + self._lastpulled = value + self._writelastpulled() + def hashes(self): if self._hashes is None: self._hashes = dict((v, k) for (k, v) in self.iteritems()) @@ -390,7 +410,7 @@ class RevMap(dict): dict.clear(self) self._hashes = None - def batchset(self, items): + def batchset(self, items, lastpulled): '''Set items in batches items is an array of (rev num, branch, binary hash) @@ -402,6 +422,8 @@ class RevMap(dict): f.write(''.join('%s %s %s\n' % (revnum, hex(binhash), br or '') for revnum, br, binhash in items)) f.close() + with open(self._lastpulled_file, 'w') as f: + f.write('%s\n' % lastpulled) def _readmapfile(self): path = self._filepath @@ -422,8 +444,11 @@ class RevMap(dict): @util.gcdisable def _load(self): - lastpulled = self.meta.lastpulled - firstpulled = self.meta.firstpulled + lastpulled = self.lastpulled + firstpulled = self.firstpulled + if os.path.exists(self._lastpulled_file): + with open(self._lastpulled_file) as f: + lastpulled = int(f.read()) setitem = dict.__setitem__ for l in self._readmapfile(): revnum, ha, branch = l.split(' ', 2) @@ -437,13 +462,15 @@ class RevMap(dict): if revnum < firstpulled or not firstpulled: firstpulled = revnum setitem(self, (revnum, branch), bin(ha)) - self.meta.lastpulled = lastpulled - self.meta.firstpulled = firstpulled + if self.lastpulled != lastpulled: + self.lastpulled = lastpulled + self.firstpulled = firstpulled def _write(self): f = open(self._filepath, 'w') f.write('%s\n' % self.VERSION) f.close() + self._writelastpulled() def __setitem__(self, key, ha): revnum, branch = key @@ -451,10 +478,10 @@ class RevMap(dict): b = branch or '' f.write(str(revnum) + ' ' + hex(ha) + ' ' + b + '\n') f.close() - if revnum > self.meta.lastpulled or not self.meta.lastpulled: - self.meta.lastpulled = revnum - if revnum < self.meta.firstpulled or not self.meta.firstpulled: - self.meta.firstpulled = revnum + if revnum > self.lastpulled or not self.lastpulled: + self.lastpulled = revnum + if revnum < self.firstpulled or not self.firstpulled: + self.firstpulled = revnum dict.__setitem__(self, (revnum, branch), ha) if self._hashes is not None: self._hashes[ha] = (revnum, branch) diff --git a/hgsubversion/replay.py b/hgsubversion/replay.py --- a/hgsubversion/replay.py +++ b/hgsubversion/replay.py @@ -65,13 +65,13 @@ def _convert_rev(ui, meta, svn, r, tbdel editor.current.rev = r editor.setsvn(svn) - if firstrun and meta.firstpulled <= 0: + if firstrun and meta.revmap.firstpulled <= 0: # We know nothing about this project, so fetch everything before # trying to apply deltas. ui.debug('replay: fetching full revision\n') svn.get_revision(r.revnum, editor) else: - svn.get_replay(r.revnum, editor, meta.firstpulled) + svn.get_replay(r.revnum, editor, meta.revmap.firstpulled) editor.close() current = editor.current diff --git a/hgsubversion/stupid.py b/hgsubversion/stupid.py --- a/hgsubversion/stupid.py +++ b/hgsubversion/stupid.py @@ -708,7 +708,7 @@ def convert_rev(ui, meta, svn, r, tbdelt # path does not support this case with svn >= 1.7. We can fix # it, or we can force the existing fetch_branchrev() path. Do # the latter for now. - incremental = (meta.firstpulled > 0 and + incremental = (meta.revmap.firstpulled > 0 and parentctx.rev() != node.nullrev and not firstrun) diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -136,7 +136,6 @@ def _buildmeta(ui, repo, args, partial=F else: closed.add(parentctx.rev()) - meta.lastpulled = youngest ui.progress('prepare', None, total=numrevs) revmapbuf = [] @@ -276,7 +275,7 @@ def _buildmeta(ui, repo, args, partial=F int(parentrev), revision) - revmap.batchset(revmapbuf) + revmap.batchset(revmapbuf, youngest) ui.progress('rebuild', None, total=numrevs) # save off branch info diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -27,7 +27,6 @@ class SVNMeta(object): self.ui = repo.ui self.repo = repo self.path = os.path.normpath(repo.join('..')) - self.firstpulled = 0 self.lastdate = '1970-01-01 00:00:00 -0000' self.addedtags = {} self.deletedtags = {} @@ -52,7 +51,6 @@ class SVNMeta(object): self.subdir = subdir # generated properties that have a persistent file stored on disk - self._gen_cachedconfig('lastpulled', 0, configname=False) self._gen_cachedconfig('defaultauthors', True) self._gen_cachedconfig('caseignoreauthors', False) self._gen_cachedconfig('mapauthorscmd', None) @@ -70,7 +68,7 @@ class SVNMeta(object): """Return a cached value for a config option. If the cache is uninitialized then try to read its value from disk. Option can be overridden by the commandline. - name: property name, e.g. 'lastpulled' + name: property name, e.g. 'defaultauthors' filename: name of file in .hg/svn configname: commandline option name default: default value diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -103,7 +103,7 @@ def incoming(orig, ui, repo, origsource= meta = repo.svnmeta(svn.uuid, svn.subdir) ui.status('incoming changes from %s\n' % other.svnurl) - svnrevisions = list(svn.revisions(start=meta.lastpulled)) + svnrevisions = list(svn.revisions(start=meta.revmap.lastpulled)) if opts.get('newest_first'): svnrevisions.reverse() # Returns 0 if there are incoming changes, 1 otherwise. @@ -419,7 +419,7 @@ def pull(repo, source, heads=[], force=F meta.branchmap['default'] = meta.branch ui = repo.ui - start = meta.lastpulled + start = meta.revmap.lastpulled if start <= 0: # we are initializing a new repository @@ -512,7 +512,7 @@ def pull(repo, source, heads=[], force=F util.swap_out_encoding(old_encoding) if lastpulled is not None: - meta.lastpulled = lastpulled + meta.revmap.lastpulled = lastpulled revisions = len(meta.revmap) - oldrevisions if revisions == 0: