##// END OF EJS Templates
convert: rewrite calls to Git to use the new shelling mechanism (SEC)...
Mateusz Kwapich -
r28660:cdda7b96 stable
parent child Browse files
Show More
@@ -115,13 +115,13 b' class convert_git(converter_source, comm'
115 115 if similarity < 0 or similarity > 100:
116 116 raise error.Abort(_('similarity must be between 0 and 100'))
117 117 if similarity > 0:
118 self.simopt = '-C%d%%' % similarity
118 self.simopt = ['-C%d%%' % similarity]
119 119 findcopiesharder = ui.configbool('convert', 'git.findcopiesharder',
120 120 False)
121 121 if findcopiesharder:
122 self.simopt += ' --find-copies-harder'
122 self.simopt.append('--find-copies-harder')
123 123 else:
124 self.simopt = ''
124 self.simopt = []
125 125
126 126 checktool('git', 'git')
127 127
@@ -136,14 +136,14 b' class convert_git(converter_source, comm'
136 136
137 137 def getheads(self):
138 138 if not self.revs:
139 heads, ret = self.gitread('git rev-parse --branches --remotes')
140 heads = heads.splitlines()
141 if ret:
139 output, status = self.gitrun('rev-parse', '--branches', '--remotes')
140 heads = output.splitlines()
141 if status:
142 142 raise error.Abort(_('cannot retrieve git heads'))
143 143 else:
144 144 heads = []
145 145 for rev in self.revs:
146 rawhead, ret = self.gitread("git rev-parse --verify %s" % rev)
146 rawhead, ret = self.gitrun('rev-parse', '--verify', rev)
147 147 heads.append(rawhead[:-1])
148 148 if ret:
149 149 raise error.Abort(_('cannot retrieve git head "%s"') % rev)
@@ -203,7 +203,7 b' class convert_git(converter_source, comm'
203 203 self.submodules.append(submodule(s['path'], '', s['url']))
204 204
205 205 def retrievegitmodules(self, version):
206 modules, ret = self.gitread("git show %s:%s" % (version, '.gitmodules'))
206 modules, ret = self.gitrun('show', '%s:%s' % (version, '.gitmodules'))
207 207 if ret:
208 208 # This can happen if a file is in the repo that has permissions
209 209 # 160000, but there is no .gitmodules file.
@@ -219,7 +219,7 b' class convert_git(converter_source, comm'
219 219 return
220 220
221 221 for m in self.submodules:
222 node, ret = self.gitread("git rev-parse %s:%s" % (version, m.path))
222 node, ret = self.gitrun('rev-parse', '%s:%s' % (version, m.path))
223 223 if ret:
224 224 continue
225 225 m.node = node.strip()
@@ -228,15 +228,17 b' class convert_git(converter_source, comm'
228 228 if full:
229 229 raise error.Abort(_("convert from git does not support --full"))
230 230 self.modecache = {}
231 fh = self.gitopen("git diff-tree -z --root -m -r %s %s" % (
232 self.simopt, version))
231 cmd = ['diff-tree','-z', '--root', '-m', '-r'] + self.simopt + [version]
232 output, status = self.gitrun(*cmd)
233 if status:
234 raise error.Abort(_('cannot read changes in %s') % version)
233 235 changes = []
234 236 copies = {}
235 237 seen = set()
236 238 entry = None
237 239 subexists = [False]
238 240 subdeleted = [False]
239 difftree = fh.read().split('\x00')
241 difftree = output.split('\x00')
240 242 lcount = len(difftree)
241 243 i = 0
242 244
@@ -298,8 +300,6 b' class convert_git(converter_source, comm'
298 300 if f != '.gitmodules' and fdest != '.gitmodules':
299 301 copies[fdest] = f
300 302 entry = None
301 if fh.close():
302 raise error.Abort(_('cannot read changes in %s') % version)
303 303
304 304 if subexists[0]:
305 305 if subdeleted[0]:
@@ -345,17 +345,23 b' class convert_git(converter_source, comm'
345 345 return c
346 346
347 347 def numcommits(self):
348 return len([None for _ in self.gitopen('git rev-list --all')])
348 output, ret = self.gitrunlines('rev-list', '--all')
349 if ret:
350 raise error.Abort(_('cannot retrieve number of commits in %s') \
351 % self.path)
352 return len(output)
349 353
350 354 def gettags(self):
351 355 tags = {}
352 356 alltags = {}
353 fh = self.gitopen('git ls-remote --tags "%s"' % self.path,
354 err=subprocess.STDOUT)
357 output, status = self.gitrunlines('ls-remote', '--tags', self.path)
358
359 if status:
360 raise error.Abort(_('cannot read tags from %s') % self.path)
355 361 prefix = 'refs/tags/'
356 362
357 363 # Build complete list of tags, both annotated and bare ones
358 for line in fh:
364 for line in output:
359 365 line = line.strip()
360 366 if line.startswith("error:") or line.startswith("fatal:"):
361 367 raise error.Abort(_('cannot read tags from %s') % self.path)
@@ -363,8 +369,6 b' class convert_git(converter_source, comm'
363 369 if not tag.startswith(prefix):
364 370 continue
365 371 alltags[tag[len(prefix):]] = node
366 if fh.close():
367 raise error.Abort(_('cannot read tags from %s') % self.path)
368 372
369 373 # Filter out tag objects for annotated tag refs
370 374 for tag in alltags:
@@ -381,18 +385,20 b' class convert_git(converter_source, comm'
381 385 def getchangedfiles(self, version, i):
382 386 changes = []
383 387 if i is None:
384 fh = self.gitopen("git diff-tree --root -m -r %s" % version)
385 for l in fh:
388 output, status = self.gitrunlines('diff-tree', '--root', '-m',
389 '-r', version)
390 if status:
391 raise error.Abort(_('cannot read changes in %s') % version)
392 for l in output:
386 393 if "\t" not in l:
387 394 continue
388 395 m, f = l[:-1].split("\t")
389 396 changes.append(f)
390 397 else:
391 fh = self.gitopen('git diff-tree --name-only --root -r %s '
392 '"%s^%s" --' % (version, version, i + 1))
393 changes = [f.rstrip('\n') for f in fh]
394 if fh.close():
395 raise error.Abort(_('cannot read changes in %s') % version)
398 output, status = self.gitrunlines('diff-tree', '--name-only',
399 '--root', '-r', version,
400 '%s^%s' % (version, i + 1), '--')
401 changes = [f.rstrip('\n') for f in output]
396 402
397 403 return changes
398 404
@@ -412,8 +418,8 b' class convert_git(converter_source, comm'
412 418 ])
413 419
414 420 try:
415 fh = self.gitopen('git show-ref', err=subprocess.PIPE)
416 for line in fh:
421 output, status = self.gitrunlines('show-ref')
422 for line in output:
417 423 line = line.strip()
418 424 rev, name = line.split(None, 1)
419 425 # Process each type of branch
@@ -714,7 +714,7 b' damage git repository by renaming a comm'
714 714 $ COMMIT_OBJ=1c/0ce3c5886f83a1d78a7b517cdff5cf9ca17bdd
715 715 $ mv git-repo4/.git/objects/$COMMIT_OBJ git-repo4/.git/objects/$COMMIT_OBJ.tmp
716 716 $ hg convert git-repo4 git-repo4-broken-hg 2>&1 | grep 'abort:'
717 abort: cannot read tags from git-repo4/.git
717 abort: cannot retrieve number of commits in git-repo4/.git
718 718 $ mv git-repo4/.git/objects/$COMMIT_OBJ.tmp git-repo4/.git/objects/$COMMIT_OBJ
719 719 damage git repository by renaming a blob object
720 720
General Comments 0
You need to be logged in to leave comments. Login now