Mercurial > hg
diff hgext/convert/convcmd.py @ 19120:58e782f076e7
splicemap: improve error handling when source is hg (issue2084)
1. Introduced 2 levels of error handling for splicemap files
a. Check the splicemap file for rules which are same across different
types of source repos. This is done through enhancing parsesplicemap
function
b. Check revision string formats. Each repo may have their own format.
This is done usign checkrevformat function
c. Implemented the above two for hg
author | Ben Goswami <bengoswami@fb.com> |
---|---|
date | Thu, 25 Apr 2013 11:50:26 -0700 |
parents | 61f1223ab358 |
children | 8c2fdf7d5645 |
line wrap: on
line diff
--- a/hgext/convert/convcmd.py Wed Apr 24 18:26:37 2013 -0700 +++ b/hgext/convert/convcmd.py Thu Apr 25 11:50:26 2013 -0700 @@ -121,9 +121,17 @@ self.splicemap = self.parsesplicemap(opts.get('splicemap')) self.branchmap = mapfile(ui, opts.get('branchmap')) + def parsesplicemap(self, path): + """ check and validate the splicemap format and + return a child/parents dictionary. + Format checking has two parts. + 1. generic format which is same across all source types + 2. specific format checking which may be different for + different source type. This logic is implemented in + checkrevformat function in source files like + hg.py, subversion.py etc. + """ - def parsesplicemap(self, path): - """Parse a splicemap, return a child/parents dictionary.""" if not path: return {} m = {} @@ -136,18 +144,28 @@ continue try: child, parents = line.split(' ', 1) + self.source.checkrevformat(child) parents = parents.replace(',', ' ').split() + # check if number of parents are upto 2 max + if (len(parents) > 2): + raise util.Abort(_('syntax error in %s(%d): child '\ + 'parent1[,parent2] expected') \ + % (path, i + 1)) + for parent in parents: + self.source.checkrevformat(parent) except ValueError: - raise util.Abort(_('syntax error in %s(%d): child parent1' - '[,parent2] expected') % (path, i + 1)) + raise util.Abort(_('syntax error in %s(%d): child '\ + 'parent1[,parent2] expected') \ + % (path, i + 1)) pp = [] for p in parents: if p not in pp: pp.append(p) m[child] = pp - except IOError, e: - if e.errno != errno.ENOENT: - raise + # if file does not exist or error reading, exit + except IOError: + raise util.Abort(_('splicemap file not found or error reading %s:') + % path) return m