# HG changeset patch # User Durham Goode # Date 1439671590 25200 # Node ID db677b70a298ec488a72cd96e03eee4dd771b020 # Parent 86598f4fe1cf021100550b6400b73d753346c4b4 convert: implements targetfilebelongstosource for filemap source This is an implementation of the new targetfilebelongstosource() function for the filemapper. It simply checks if the given file name is prefixed by any of the rename destinations. It is not a perfect implementation since it doesn't account for the filemap specifying includes or excludes, but that makes the problem much harder, and this implementation should suffice for most cases. diff -r 86598f4fe1cf -r db677b70a298 hgext/convert/filemap.py --- 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)