##// END OF EJS Templates
graft: add initial implementation
Matt Mackall -
r15238:2d710c12 default
parent child Browse files
Show More
@@ -2447,6 +2447,75 b' def forget(ui, repo, *pats, **opts):'
2447 2447 repo[None].forget(forget)
2448 2448 return errs
2449 2449
2450 @command('graft',
2451 [],
2452 _('[OPTION]... REVISION...'))
2453 def graft(ui, repo, rev, *revs, **opts):
2454 '''copy changes from other branches onto the current branch
2455
2456 This command uses Mercurial's merge logic to copy individual
2457 changes from other branches without merging branches in the
2458 history graph. This is sometimes known as 'backporting' or
2459 'cherry-picking'.
2460
2461 Changesets that are ancestors of the current revision, that have
2462 already been grafted, or that are merges will be skipped.
2463
2464 Returns 0 on successful completion.
2465 '''
2466
2467 cmdutil.bailifchanged(repo)
2468
2469 revs = [rev] + list(revs)
2470 revs = scmutil.revrange(repo, revs)
2471
2472 # check for merges
2473 for ctx in repo.set('%ld and merge()', revs):
2474 ui.warn(_('skipping ungraftable merge revision %s\n') % ctx.rev())
2475 revs.remove(ctx.rev())
2476 if not revs:
2477 return -1
2478
2479 # check for ancestors of dest branch
2480 for ctx in repo.set('::. and %ld', revs):
2481 ui.warn(_('skipping ancestor revision %s\n') % ctx.rev())
2482 revs.remove(ctx.rev())
2483 if not revs:
2484 return -1
2485
2486 # check ancestors for earlier grafts
2487 ui.debug('scanning for existing transplants')
2488 for ctx in repo.set("::. - ::%ld", revs):
2489 n = ctx.extra().get('source')
2490 if n and n in repo:
2491 r = repo[n].rev()
2492 ui.warn(_('skipping already grafted revision %s\n') % r)
2493 revs.remove(r)
2494 if not revs:
2495 return -1
2496
2497 for ctx in repo.set("%ld", revs):
2498 current = repo['.']
2499 ui.debug('grafting revision %s', ctx.rev())
2500 # perform the graft merge with p1(rev) as 'ancestor'
2501 stats = mergemod.update(repo, ctx.node(), True, True, False,
2502 ctx.p1().node())
2503 # drop the second merge parent
2504 repo.dirstate.setparents(current.node(), nullid)
2505 repo.dirstate.write()
2506 # fix up dirstate for copies and renames
2507 cmdutil.duplicatecopies(repo, ctx.rev(), current.node(), nullid)
2508 # report any conflicts
2509 if stats and stats[3] > 0:
2510 raise util.Abort(_("unresolved conflicts, can't continue"),
2511 hint=_('use hg resolve and hg graft --continue'))
2512 # commit
2513 extra = {'source': ctx.hex()}
2514 repo.commit(text=ctx.description(), user=ctx.user(),
2515 date=ctx.date(), extra=extra)
2516
2517 return 0
2518
2450 2519 @command('grep',
2451 2520 [('0', 'print0', None, _('end fields with NUL')),
2452 2521 ('', 'all', None, _('print all revisions that match')),
@@ -17,6 +17,7 b' Show all commands except debug commands'
17 17 diff
18 18 export
19 19 forget
20 graft
20 21 grep
21 22 heads
22 23 help
@@ -242,6 +243,7 b' Show all commands + options'
242 243 debugsub: rev
243 244 debugwalk: include, exclude
244 245 debugwireargs: three, four, five, ssh, remotecmd, insecure
246 graft:
245 247 grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
246 248 heads: rev, topo, active, closed, style, template
247 249 help: extension, command
@@ -296,6 +296,7 b' Testing -h/--help:'
296 296 diff diff repository (or selected files)
297 297 export dump the header and diffs for one or more changesets
298 298 forget forget the specified files on the next commit
299 graft copy changes from other branches onto the current branch
299 300 grep search for a pattern in specified files and revisions
300 301 heads show current repository heads or show branch heads
301 302 help show help for a given topic or a help overview
@@ -377,6 +378,7 b' Testing -h/--help:'
377 378 diff diff repository (or selected files)
378 379 export dump the header and diffs for one or more changesets
379 380 forget forget the specified files on the next commit
381 graft copy changes from other branches onto the current branch
380 382 grep search for a pattern in specified files and revisions
381 383 heads show current repository heads or show branch heads
382 384 help show help for a given topic or a help overview
@@ -66,6 +66,7 b' Short help:'
66 66 diff diff repository (or selected files)
67 67 export dump the header and diffs for one or more changesets
68 68 forget forget the specified files on the next commit
69 graft copy changes from other branches onto the current branch
69 70 grep search for a pattern in specified files and revisions
70 71 heads show current repository heads or show branch heads
71 72 help show help for a given topic or a help overview
@@ -141,6 +142,7 b' Short help:'
141 142 diff diff repository (or selected files)
142 143 export dump the header and diffs for one or more changesets
143 144 forget forget the specified files on the next commit
145 graft copy changes from other branches onto the current branch
144 146 grep search for a pattern in specified files and revisions
145 147 heads show current repository heads or show branch heads
146 148 help show help for a given topic or a help overview
@@ -626,6 +628,7 b' Test that default list of commands omits'
626 628 diff diff repository (or selected files)
627 629 export dump the header and diffs for one or more changesets
628 630 forget forget the specified files on the next commit
631 graft copy changes from other branches onto the current branch
629 632 grep search for a pattern in specified files and revisions
630 633 heads show current repository heads or show branch heads
631 634 help show help for a given topic or a help overview
General Comments 0
You need to be logged in to leave comments. Login now