# HG changeset patch # User Vitaliy Filippov <vita...@yourcmc.ru> # Date 1327702705 -14400 # Node ID 480e204d11897bafd702834e5de15ddfe2f193f0 # Parent 49fc56d26ecee40a50619bbbb4498d4fd6010394 Respect filemap rule order (rules that come first are overridden by rules that come later)
diff -r 49fc56d26ece -r 480e204d1189 hgsubversion/maps.py --- a/hgsubversion/maps.py Fri Jan 20 19:06:32 2012 +0400 +++ b/hgsubversion/maps.py Sat Jan 28 02:18:25 2012 +0400 @@ -272,32 +272,34 @@ self._write()
def _rpairs(self, name): - yield '.', name e = len(name) while e != -1: yield name[:e], name[e+1:] e = name.rfind('/', 0, e) + yield '.', name
def check(self, m, path): m = getattr(self, m) for pre, _suf in self._rpairs(path): - if pre not in m: - continue - return m[pre] - return None + if pre in m: + return m[pre] + return -1
def __contains__(self, path): - if len(self.include) and len(path): + if not len(path): + return True + if len(self.include): inc = self.check('include', path) + elif not len(self.exclude): + return True else: - inc = path - if len(self.exclude) and len(path): + inc = 0 + if len(self.exclude): exc = self.check('exclude', path) else: - exc = None - if inc is None or exc is not None: - return False - return True + exc = -1 + # respect rule order: newer rules override older + return inc > exc
# Needed so empty filemaps are false def __len__(self): @@ -311,7 +313,8 @@ return bits = m.strip('e'), path self.ui.debug('%sing %s\n' % bits) - mapping[path] = path + # respect rule order + mapping[path] = len(self) if fn != self.path: f = open(self.path, 'a') f.write(m + ' ' + path + '\n') diff -r 49fc56d26ece -r 480e204d1189 tests/test_fetch_mappings.py --- a/tests/test_fetch_mappings.py Fri Jan 20 19:06:32 2012 +0400 +++ b/tests/test_fetch_mappings.py Sat Jan 28 02:18:25 2012 +0400 @@ -131,6 +131,19 @@ # TODO: re-enable test if we ever reinstate this feature self.assertRaises(hgutil.Abort, self.test_file_map_exclude, True)
This is a new version of my filemap patches; the first one is unchanged and the second one doesn't change the behaviour when only 'include' rules are present anymore. Additionally, I added a test for rule order patch.
# HG changeset patch # User Vitaliy Filippov <vita...@yourcmc.ru> # Date 1327071992 -14400 # Node ID 49fc56d26ecee40a50619bbbb4498d4fd6010394 # Parent 6c4d15d8cfbda880bf5e41cd408d49f8529f97d2 Save filemap into .hg/svn/filemap just like other maps
diff -r 6c4d15d8cfbd -r 49fc56d26ece hgsubversion/maps.py --- a/hgsubversion/maps.py Fri Oct 21 16:42:10 2011 -0500 +++ b/hgsubversion/maps.py Fri Jan 20 19:06:32 2012 +0400 @@ -21,7 +21,7 @@ The ui argument is used to print diagnostic messages.
The path argument is the location of the backing store, - typically .hg/authormap. + typically .hg/svn/authors. ''' self.ui = ui self.path = path @@ -252,13 +252,24 @@
class FileMap(object):
- def __init__(self, repo): - self.ui = repo.ui + VERSION = 1 + + def __init__(self, ui, path): + '''Initialise a new FileMap. + + The ui argument is used to print diagnostic messages. + + The path argument is the location of the backing store, + typically .hg/svn/filemap. + ''' + self.ui = ui + self.path = path self.include = {} self.exclude = {} - filemap = repo.ui.config('hgsubversion', 'filemap') - if filemap and os.path.exists(filemap): - self.load(filemap) + if os.path.isfile(self.path): + self._load() + else: + self._write()
> # HG changeset patch > # User Vitaliy Filippov <vita...@yourcmc.ru> > # Date 1327702705 -14400 > # Node ID 480e204d11897bafd702834e5de15ddfe2f193f0 > # Parent 49fc56d26ecee40a50619bbbb4498d4fd6010394 > Respect filemap rule order (rules that come first are overridden by rules that come later)
> def _rpairs(self, name): > - yield '.', name > e = len(name) > while e != -1: > yield name[:e], name[e+1:] > e = name.rfind('/', 0, e) > + yield '.', name
> def check(self, m, path): > m = getattr(self, m) > for pre, _suf in self._rpairs(path): > - if pre not in m: > - continue > - return m[pre] > - return None > + if pre in m: > + return m[pre] > + return -1
> def __contains__(self, path): > - if len(self.include) and len(path): > + if not len(path): > + return True > + if len(self.include): > inc = self.check('include', path) > + elif not len(self.exclude): > + return True > else: > - inc = path > - if len(self.exclude) and len(path): > + inc = 0 > + if len(self.exclude): > exc = self.check('exclude', path) > else: > - exc = None > - if inc is None or exc is not None: > - return False > - return True > + exc = -1 > + # respect rule order: newer rules override older > + return inc > exc
> # Needed so empty filemaps are false > def __len__(self): > @@ -311,7 +313,8 @@ > return > bits = m.strip('e'), path > self.ui.debug('%sing %s\n' % bits) > - mapping[path] = path > + # respect rule order > + mapping[path] = len(self) > if fn != self.path: > f = open(self.path, 'a') > f.write(m + ' ' + path + '\n') > diff -r 49fc56d26ece -r 480e204d1189 tests/test_fetch_mappings.py > --- a/tests/test_fetch_mappings.py Fri Jan 20 19:06:32 2012 +0400 > +++ b/tests/test_fetch_mappings.py Sat Jan 28 02:18:25 2012 +0400 > @@ -131,6 +131,19 @@ > # TODO: re-enable test if we ever reinstate this feature > self.assertRaises(hgutil.Abort, self.test_file_map_exclude, True)
Queued both of these, though for future reference we're trying to make new tests examine particular attributes of commits rather than just asserting the hash is a particular value, as changes to the metadata stored by Mercurial can cause these to change over time without the content being meaningfully different.
> -- > You received this message because you are subscribed to the Google Groups "hgsubversion" group. > To post to this group, send email to hgsubversion@googlegroups.com. > To unsubscribe from this group, send email to hgsubversion+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/hgsubversion?hl=en.