Mercurial > hg
diff hgext/convert/darcs.py @ 9527:b3c13e721593
convert/darcs: handle directory renaming
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 04 Oct 2009 23:06:14 +0200 |
parents | 457a30ed8ffb |
children | 53a95a744812 |
line wrap: on
line diff
--- a/hgext/convert/darcs.py Sun Oct 04 22:23:11 2009 +0200 +++ b/hgext/convert/darcs.py Sun Oct 04 23:06:14 2009 +0200 @@ -85,6 +85,17 @@ self.checkexit(fp.close()) return etree.getroot() + def manifest(self): + man = [] + output, status = self.run('show', 'files', no_directories=True, + repodir=self.tmppath) + self.checkexit(status) + for line in output.split('\n'): + path = line[2:] + if path: + man.append(path) + return man + def getheads(self): return self.parents[None] @@ -107,19 +118,35 @@ output, status = self.run('revert', all=True, repodir=self.tmppath) self.checkexit(status, output) - def getchanges(self, rev): - self.pull(rev) + def getchanges(self, rev): copies = {} changes = [] + man = None for elt in self.changes[rev].find('summary').getchildren(): if elt.tag in ('add_directory', 'remove_directory'): continue if elt.tag == 'move': - changes.append((elt.get('from'), rev)) - changes.append((elt.get('to'), rev)) - copies[elt.get('to')] = elt.get('from') + if man is None: + man = self.manifest() + source, dest = elt.get('from'), elt.get('to') + if source in man: + # File move + changes.append((source, rev)) + changes.append((dest, rev)) + copies[dest] = source + else: + # Directory move, deduce file moves from manifest + source = source + '/' + for f in man: + if not f.startswith(source): + continue + fdest = dest + '/' + f[len(source):] + changes.append((f, rev)) + changes.append((fdest, rev)) + copies[fdest] = f else: changes.append((elt.text.strip(), rev)) + self.pull(rev) self.lastrev = rev return sorted(changes), copies