comparison 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
comparison
equal deleted inserted replaced
19119:61f1223ab358 19120:58e782f076e7
119 self.authorfile = self.dest.authorfile() 119 self.authorfile = self.dest.authorfile()
120 120
121 self.splicemap = self.parsesplicemap(opts.get('splicemap')) 121 self.splicemap = self.parsesplicemap(opts.get('splicemap'))
122 self.branchmap = mapfile(ui, opts.get('branchmap')) 122 self.branchmap = mapfile(ui, opts.get('branchmap'))
123 123
124
125 def parsesplicemap(self, path): 124 def parsesplicemap(self, path):
126 """Parse a splicemap, return a child/parents dictionary.""" 125 """ check and validate the splicemap format and
126 return a child/parents dictionary.
127 Format checking has two parts.
128 1. generic format which is same across all source types
129 2. specific format checking which may be different for
130 different source type. This logic is implemented in
131 checkrevformat function in source files like
132 hg.py, subversion.py etc.
133 """
134
127 if not path: 135 if not path:
128 return {} 136 return {}
129 m = {} 137 m = {}
130 try: 138 try:
131 fp = open(path, 'r') 139 fp = open(path, 'r')
134 if not line: 142 if not line:
135 # Ignore blank lines 143 # Ignore blank lines
136 continue 144 continue
137 try: 145 try:
138 child, parents = line.split(' ', 1) 146 child, parents = line.split(' ', 1)
147 self.source.checkrevformat(child)
139 parents = parents.replace(',', ' ').split() 148 parents = parents.replace(',', ' ').split()
149 # check if number of parents are upto 2 max
150 if (len(parents) > 2):
151 raise util.Abort(_('syntax error in %s(%d): child '\
152 'parent1[,parent2] expected') \
153 % (path, i + 1))
154 for parent in parents:
155 self.source.checkrevformat(parent)
140 except ValueError: 156 except ValueError:
141 raise util.Abort(_('syntax error in %s(%d): child parent1' 157 raise util.Abort(_('syntax error in %s(%d): child '\
142 '[,parent2] expected') % (path, i + 1)) 158 'parent1[,parent2] expected') \
159 % (path, i + 1))
143 pp = [] 160 pp = []
144 for p in parents: 161 for p in parents:
145 if p not in pp: 162 if p not in pp:
146 pp.append(p) 163 pp.append(p)
147 m[child] = pp 164 m[child] = pp
148 except IOError, e: 165 # if file does not exist or error reading, exit
149 if e.errno != errno.ENOENT: 166 except IOError:
150 raise 167 raise util.Abort(_('splicemap file not found or error reading %s:')
168 % path)
151 return m 169 return m
152 170
153 171
154 def walktree(self, heads): 172 def walktree(self, heads):
155 '''Return a mapping that identifies the uncommitted parents of every 173 '''Return a mapping that identifies the uncommitted parents of every