comparison mercurial/cmdutil.py @ 44364:8be0c63535b5

copy: add option to unmark file as copied To unmark a file as copied, the user currently has to do this: hg forget <dest> hg add <dest> The new command simplifies that to: hg copy --forget <dest> That's not a very big improvement, but I'm planning to also teach `hg copy [--forget]` a `--at-rev` argument for marking/unmarking copies after commit (usually with `--at-rev .`). Differential Revision: https://phab.mercurial-scm.org/D8029
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 20 Dec 2019 15:50:13 -0800
parents 27a78ea30b48
children 7c4b98a4e536
comparison
equal deleted inserted replaced
44363:f7459da77f23 44364:8be0c63535b5
1408 """ 1408 """
1409 return openstorage(repo, cmd, file_, opts, returnrevlog=True) 1409 return openstorage(repo, cmd, file_, opts, returnrevlog=True)
1410 1410
1411 1411
1412 def copy(ui, repo, pats, opts, rename=False): 1412 def copy(ui, repo, pats, opts, rename=False):
1413 check_incompatible_arguments(opts, b'forget', [b'dry_run'])
1414
1413 # called with the repo lock held 1415 # called with the repo lock held
1414 # 1416 #
1415 # hgsep => pathname that uses "/" to separate directories 1417 # hgsep => pathname that uses "/" to separate directories
1416 # ossep => pathname that uses os.sep to separate directories 1418 # ossep => pathname that uses os.sep to separate directories
1417 cwd = repo.getcwd() 1419 cwd = repo.getcwd()
1418 targets = {} 1420 targets = {}
1421 forget = opts.get(b"forget")
1419 after = opts.get(b"after") 1422 after = opts.get(b"after")
1420 dryrun = opts.get(b"dry_run") 1423 dryrun = opts.get(b"dry_run")
1421 ctx = repo[None] 1424 ctx = repo[None]
1422 pctx = ctx.p1() 1425 pctx = ctx.p1()
1423 1426
1424 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) 1427 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
1428
1429 if forget:
1430 match = scmutil.match(wctx, pats, opts)
1431
1432 current_copies = wctx.p1copies()
1433 current_copies.update(wctx.p2copies())
1434
1435 for f in wctx.walk(match):
1436 if f in current_copies:
1437 wctx[f].markcopied(None)
1438 elif match.exact(f):
1439 ui.warn(
1440 _(
1441 b'%s: not unmarking as copy - file is not marked as copied\n'
1442 )
1443 % uipathfn(f)
1444 )
1445 return
1425 1446
1426 def walkpat(pat): 1447 def walkpat(pat):
1427 srcs = [] 1448 srcs = []
1428 m = scmutil.match(ctx, [pat], opts, globbed=True) 1449 m = scmutil.match(ctx, [pat], opts, globbed=True)
1429 for abs in ctx.walk(m): 1450 for abs in ctx.walk(m):