Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 44394:2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
I want to add a `hg cp/mv -r <rev>` option to mark files as
copied/moved in an existing commit (amending that commit). The code
needs to not depend on the dirstate for that.
Differential Revision: https://phab.mercurial-scm.org/D8031
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 20 Dec 2019 14:03:12 -0800 |
parents | a0ec05d93c8e |
children | 27a78ea30b48 |
comparison
equal
deleted
inserted
replaced
44393:a69c08cdb2a8 | 44394:2bd3b95fdce0 |
---|---|
1417 cwd = repo.getcwd() | 1417 cwd = repo.getcwd() |
1418 targets = {} | 1418 targets = {} |
1419 after = opts.get(b"after") | 1419 after = opts.get(b"after") |
1420 dryrun = opts.get(b"dry_run") | 1420 dryrun = opts.get(b"dry_run") |
1421 wctx = repo[None] | 1421 wctx = repo[None] |
1422 pctx = wctx.p1() | |
1422 | 1423 |
1423 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) | 1424 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
1424 | 1425 |
1425 def walkpat(pat): | 1426 def walkpat(pat): |
1426 srcs = [] | 1427 srcs = [] |
1427 if after: | |
1428 badstates = b'?' | |
1429 else: | |
1430 badstates = b'?r' | |
1431 m = scmutil.match(wctx, [pat], opts, globbed=True) | 1428 m = scmutil.match(wctx, [pat], opts, globbed=True) |
1432 for abs in wctx.walk(m): | 1429 for abs in wctx.walk(m): |
1433 state = repo.dirstate[abs] | |
1434 rel = uipathfn(abs) | 1430 rel = uipathfn(abs) |
1435 exact = m.exact(abs) | 1431 exact = m.exact(abs) |
1436 if state in badstates: | 1432 if abs not in wctx: |
1437 if exact and state == b'?': | 1433 if abs in pctx: |
1438 ui.warn(_(b'%s: not copying - file is not managed\n') % rel) | 1434 if not after: |
1439 if exact and state == b'r': | 1435 if exact: |
1440 ui.warn( | 1436 ui.warn( |
1441 _( | 1437 _( |
1442 b'%s: not copying - file has been marked for' | 1438 b'%s: not copying - file has been marked ' |
1443 b' remove\n' | 1439 b'for remove\n' |
1440 ) | |
1441 % rel | |
1442 ) | |
1443 continue | |
1444 else: | |
1445 if exact: | |
1446 ui.warn( | |
1447 _(b'%s: not copying - file is not managed\n') % rel | |
1444 ) | 1448 ) |
1445 % rel | 1449 continue |
1446 ) | 1450 |
1447 continue | |
1448 # abs: hgsep | 1451 # abs: hgsep |
1449 # rel: ossep | 1452 # rel: ossep |
1450 srcs.append((abs, rel, exact)) | 1453 srcs.append((abs, rel, exact)) |
1451 return srcs | 1454 return srcs |
1452 | 1455 |