--- a/hgext/convert/filemap.py Sat Aug 15 13:44:55 2015 -0700
+++ b/hgext/convert/filemap.py Sat Aug 15 13:46:30 2015 -0700
@@ -42,6 +42,7 @@
self.include = {}
self.exclude = {}
self.rename = {}
+ self.targetprefixes = None
if path:
if self.parse(path):
raise util.Abort(_('errors in filemap'))
@@ -100,6 +101,30 @@
pass
return '', name, ''
+ def istargetfile(self, filename):
+ """Return true if the given target filename is covered as a destination
+ of the filemap. This is useful for identifying what parts of the target
+ repo belong to the source repo and what parts don't."""
+ if self.targetprefixes is None:
+ self.targetprefixes = set()
+ for before, after in self.rename.iteritems():
+ self.targetprefixes.add(after)
+
+ # If "." is a target, then all target files are considered from the
+ # source.
+ if not self.targetprefixes or '.' in self.targetprefixes:
+ return True
+
+ filename = normalize(filename)
+ for pre, suf in rpairs(filename):
+ # This check is imperfect since it doesn't account for the
+ # include/exclude list, but it should work in filemaps that don't
+ # apply include/exclude to the same source directories they are
+ # renaming.
+ if pre in self.targetprefixes:
+ return True
+ return False
+
def __call__(self, name):
if self.include:
inc = self.lookup(name, self.include)[0]
@@ -410,6 +435,9 @@
return files, ncopies, ncleanp2
+ def targetfilebelongstosource(self, targetfilename):
+ return self.filemapper.istargetfile(targetfilename)
+
def getfile(self, name, rev):
realname, realrev = rev
return self.base.getfile(realname, realrev)