75 lines = self.opener(self.status_path).read().splitlines() |
75 lines = self.opener(self.status_path).read().splitlines() |
76 self.applied = [statusentry(l) for l in lines] |
76 self.applied = [statusentry(l) for l in lines] |
77 |
77 |
78 def diffopts(self): |
78 def diffopts(self): |
79 if self._diffopts is None: |
79 if self._diffopts is None: |
80 self._diffopts = self.ui.diffopts() |
80 self._diffopts = patch.diffopts(self.ui) |
81 return self._diffopts |
81 return self._diffopts |
82 |
82 |
83 def join(self, *p): |
83 def join(self, *p): |
84 return os.path.join(self.path, *p) |
84 return os.path.join(self.path, *p) |
85 |
85 |
398 |
398 |
399 def patch(self, repo, patchfile): |
399 def patch(self, repo, patchfile): |
400 '''Apply patchfile to the working directory. |
400 '''Apply patchfile to the working directory. |
401 patchfile: file name of patch''' |
401 patchfile: file name of patch''' |
402 try: |
402 try: |
403 (files, fuzz) = patch.patch(patchfile, self.ui, strip=1, |
403 pp = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
404 cwd=repo.root) |
404 f = os.popen("%s -d %s -p1 --no-backup-if-mismatch < %s" % |
405 except Exception, inst: |
405 (pp, util.shellquote(repo.root), util.shellquote(patchfile))) |
406 self.ui.note(str(inst) + '\n') |
406 except: |
407 if not self.ui.verbose: |
407 self.ui.warn("patch failed, unable to continue (try -v)\n") |
408 self.ui.warn("patch failed, unable to continue (try -v)\n") |
408 return (None, [], False) |
409 return (False, [], False) |
409 files = [] |
410 |
410 fuzz = False |
411 return (True, files.keys(), fuzz) |
411 for l in f: |
|
412 l = l.rstrip('\r\n'); |
|
413 if self.ui.verbose: |
|
414 self.ui.warn(l + "\n") |
|
415 if l[:14] == 'patching file ': |
|
416 pf = os.path.normpath(util.parse_patch_output(l)) |
|
417 if pf not in files: |
|
418 files.append(pf) |
|
419 printed_file = False |
|
420 file_str = l |
|
421 elif l.find('with fuzz') >= 0: |
|
422 if not printed_file: |
|
423 self.ui.warn(file_str + '\n') |
|
424 printed_file = True |
|
425 self.ui.warn(l + '\n') |
|
426 fuzz = True |
|
427 elif l.find('saving rejects to file') >= 0: |
|
428 self.ui.warn(l + '\n') |
|
429 elif l.find('FAILED') >= 0: |
|
430 if not printed_file: |
|
431 self.ui.warn(file_str + '\n') |
|
432 printed_file = True |
|
433 self.ui.warn(l + '\n') |
|
434 |
|
435 return (not f.close(), files, fuzz) |
412 |
436 |
413 def apply(self, repo, series, list=False, update_status=True, |
437 def apply(self, repo, series, list=False, update_status=True, |
414 strict=False, patchdir=None, merge=None, wlock=None): |
438 strict=False, patchdir=None, merge=None, wlock=None): |
415 # TODO unify with commands.py |
439 # TODO unify with commands.py |
416 if not patchdir: |
440 if not patchdir: |
480 err = 1 |
504 err = 1 |
481 break |
505 break |
482 tr.close() |
506 tr.close() |
483 return (err, n) |
507 return (err, n) |
484 |
508 |
485 def delete(self, repo, patches, keep=False): |
509 def delete(self, repo, patch, force=False): |
486 realpatches = [] |
510 patch = self.lookup(patch, strict=True) |
487 for patch in patches: |
511 info = self.isapplied(patch) |
488 patch = self.lookup(patch, strict=True) |
512 if info: |
489 info = self.isapplied(patch) |
513 raise util.Abort(_("cannot delete applied patch %s") % patch) |
490 if info: |
514 if patch not in self.series: |
491 raise util.Abort(_("cannot delete applied patch %s") % patch) |
515 raise util.Abort(_("patch %s not in series file") % patch) |
492 if patch not in self.series: |
516 if force: |
493 raise util.Abort(_("patch %s not in series file") % patch) |
|
494 realpatches.append(patch) |
|
495 |
|
496 if not keep: |
|
497 r = self.qrepo() |
517 r = self.qrepo() |
498 if r: |
518 if r: |
499 r.remove(realpatches, True) |
519 r.remove([patch], True) |
500 else: |
520 else: |
501 os.unlink(self.join(patch)) |
521 os.unlink(self.join(patch)) |
502 |
522 i = self.find_series(patch) |
503 indices = [self.find_series(p) for p in realpatches] |
523 del self.full_series[i] |
504 indices.sort() |
|
505 for i in indices[-1::-1]: |
|
506 del self.full_series[i] |
|
507 self.parse_series() |
524 self.parse_series() |
508 self.series_dirty = 1 |
525 self.series_dirty = 1 |
509 |
526 |
510 def check_toppatch(self, repo): |
527 def check_toppatch(self, repo): |
511 if len(self.applied) > 0: |
528 if len(self.applied) > 0: |
1281 self.series_dirty = 1 |
1298 self.series_dirty = 1 |
1282 qrepo = self.qrepo() |
1299 qrepo = self.qrepo() |
1283 if qrepo: |
1300 if qrepo: |
1284 qrepo.add(added) |
1301 qrepo.add(added) |
1285 |
1302 |
1286 def delete(ui, repo, patch, *patches, **opts): |
1303 def delete(ui, repo, patch, **opts): |
1287 """remove patches from queue |
1304 """remove a patch from the series file |
1288 |
1305 |
1289 The patches must not be applied. |
1306 The patch must not be applied. |
1290 With -k, the patch files are preserved in the patch directory.""" |
1307 With -f, deletes the patch file as well as the series entry.""" |
1291 q = repo.mq |
1308 q = repo.mq |
1292 q.delete(repo, (patch,) + patches, keep=opts.get('keep')) |
1309 q.delete(repo, patch, force=opts.get('force')) |
1293 q.save_dirty() |
1310 q.save_dirty() |
1294 return 0 |
1311 return 0 |
1295 |
1312 |
1296 def applied(ui, repo, patch=None, **opts): |
1313 def applied(ui, repo, patch=None, **opts): |
1297 """print the patches already applied""" |
1314 """print the patches already applied""" |
1445 |
1462 |
1446 Patches must not yet be applied. Each patch will be successively |
1463 Patches must not yet be applied. Each patch will be successively |
1447 applied to the current patch in the order given. If all the |
1464 applied to the current patch in the order given. If all the |
1448 patches apply successfully, the current patch will be refreshed |
1465 patches apply successfully, the current patch will be refreshed |
1449 with the new cumulative patch, and the folded patches will |
1466 with the new cumulative patch, and the folded patches will |
1450 be deleted. With -k/--keep, the folded patch files will not |
1467 be deleted. With -f/--force, the folded patch files will |
1451 be removed afterwards. |
1468 be removed afterwards. |
1452 |
1469 |
1453 The header for each folded patch will be concatenated with |
1470 The header for each folded patch will be concatenated with |
1454 the current patch header, separated by a line of '* * *'.""" |
1471 the current patch header, separated by a line of '* * *'.""" |
1455 |
1472 |
1495 message = ui.edit(message, user or ui.username()) |
1512 message = ui.edit(message, user or ui.username()) |
1496 |
1513 |
1497 q.refresh(repo, msg=message) |
1514 q.refresh(repo, msg=message) |
1498 |
1515 |
1499 for patch in patches: |
1516 for patch in patches: |
1500 q.delete(repo, patch, keep=opts['keep']) |
1517 q.delete(repo, patch, force=opts['force']) |
1501 |
1518 |
1502 q.save_dirty() |
1519 q.save_dirty() |
1503 |
1520 |
1504 def guard(ui, repo, *args, **opts): |
1521 def guard(ui, repo, *args, **opts): |
1505 '''set or print guards for a patch |
1522 '''set or print guards for a patch |
1884 "qcommit|qci": |
1901 "qcommit|qci": |
1885 (commit, |
1902 (commit, |
1886 commands.table["^commit|ci"][1], |
1903 commands.table["^commit|ci"][1], |
1887 'hg qcommit [OPTION]... [FILE]...'), |
1904 'hg qcommit [OPTION]... [FILE]...'), |
1888 "^qdiff": (diff, [], 'hg qdiff [FILE]...'), |
1905 "^qdiff": (diff, [], 'hg qdiff [FILE]...'), |
1889 "qdelete|qremove|qrm": |
1906 "qdelete": |
1890 (delete, |
1907 (delete, |
1891 [('k', 'keep', None, _('keep patch file'))], |
1908 [('f', 'force', None, _('delete patch file'))], |
1892 'hg qdelete [-k] PATCH'), |
1909 'hg qdelete [-f] PATCH'), |
1893 'qfold': |
1910 'qfold': |
1894 (fold, |
1911 (fold, |
1895 [('e', 'edit', None, _('edit patch header')), |
1912 [('e', 'edit', None, _('edit patch header')), |
1896 ('k', 'keep', None, _('keep folded patch files')), |
1913 ('f', 'force', None, _('delete folded patch files')), |
1897 ('m', 'message', '', _('set patch header to <text>')), |
1914 ('m', 'message', '', _('set patch header to <text>')), |
1898 ('l', 'logfile', '', _('set patch header to contents of <file>'))], |
1915 ('l', 'logfile', '', _('set patch header to contents of <file>'))], |
1899 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'), |
1916 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'), |
1900 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')), |
1917 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')), |
1901 ('n', 'none', None, _('drop all guards'))], |
1918 ('n', 'none', None, _('drop all guards'))], |