Mercurial > hg-stable
comparison mercurial/commands.py @ 15474:95174c381525
forget: support forgetting explicit paths in subrepos
Change the behavior of the forget command such that explicit paths in
subrepos are handled by forgetting the file in the subrepo. This eliminates the
previous behavior where if you called "hg forget" for an explicit path in a
subrepo, it would state that the file is already untracked.
author | David M. Carr <david@carrclan.us> |
---|---|
date | Wed, 09 Nov 2011 19:46:51 -0500 |
parents | f520c9616db5 |
children | 875bb46e35ea |
comparison
equal
deleted
inserted
replaced
15473:d90b0b30464b | 15474:95174c381525 |
---|---|
11 import os, re, difflib, time, tempfile, errno | 11 import os, re, difflib, time, tempfile, errno |
12 import hg, scmutil, util, revlog, extensions, copies, error, bookmarks | 12 import hg, scmutil, util, revlog, extensions, copies, error, bookmarks |
13 import patch, help, url, encoding, templatekw, discovery | 13 import patch, help, url, encoding, templatekw, discovery |
14 import archival, changegroup, cmdutil, hbisect | 14 import archival, changegroup, cmdutil, hbisect |
15 import sshserver, hgweb, hgweb.server, commandserver | 15 import sshserver, hgweb, hgweb.server, commandserver |
16 import match as matchmod | |
16 import merge as mergemod | 17 import merge as mergemod |
17 import minirst, revset, fileset | 18 import minirst, revset, fileset |
18 import dagparser, context, simplemerge | 19 import dagparser, context, simplemerge |
19 import random, setdiscovery, treediscovery, dagutil | 20 import random, setdiscovery, treediscovery, dagutil |
20 | 21 |
2430 """ | 2431 """ |
2431 | 2432 |
2432 if not pats: | 2433 if not pats: |
2433 raise util.Abort(_('no files specified')) | 2434 raise util.Abort(_('no files specified')) |
2434 | 2435 |
2435 m = scmutil.match(repo[None], pats, opts) | 2436 wctx = repo[None] |
2437 m = scmutil.match(wctx, pats, opts) | |
2436 s = repo.status(match=m, clean=True) | 2438 s = repo.status(match=m, clean=True) |
2437 forget = sorted(s[0] + s[1] + s[3] + s[6]) | 2439 forget = sorted(s[0] + s[1] + s[3] + s[6]) |
2440 subforget = {} | |
2438 errs = 0 | 2441 errs = 0 |
2442 | |
2443 for subpath in wctx.substate: | |
2444 sub = wctx.sub(subpath) | |
2445 try: | |
2446 submatch = matchmod.narrowmatcher(subpath, m) | |
2447 for fsub in sub.walk(submatch): | |
2448 if submatch.exact(fsub): | |
2449 subforget[os.path.join(subpath, fsub)] = (fsub, sub) | |
2450 except error.LookupError: | |
2451 ui.status(_("skipping missing subrepository: %s\n") % subpath) | |
2439 | 2452 |
2440 for f in m.files(): | 2453 for f in m.files(): |
2441 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): | 2454 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
2442 if os.path.exists(m.rel(f)): | 2455 if f not in subforget: |
2443 ui.warn(_('not removing %s: file is already untracked\n') | 2456 if os.path.exists(m.rel(f)): |
2444 % m.rel(f)) | 2457 ui.warn(_('not removing %s: file is already untracked\n') |
2445 errs = 1 | 2458 % m.rel(f)) |
2459 errs = 1 | |
2446 | 2460 |
2447 for f in forget: | 2461 for f in forget: |
2448 if ui.verbose or not m.exact(f): | 2462 if ui.verbose or not m.exact(f): |
2449 ui.status(_('removing %s\n') % m.rel(f)) | 2463 ui.status(_('removing %s\n') % m.rel(f)) |
2450 | 2464 |
2451 repo[None].forget(forget) | 2465 if ui.verbose: |
2466 for f in sorted(subforget.keys()): | |
2467 ui.status(_('removing %s\n') % m.rel(f)) | |
2468 | |
2469 wctx.forget(forget) | |
2470 | |
2471 for f in sorted(subforget.keys()): | |
2472 fsub, sub = subforget[f] | |
2473 sub.forget([fsub]) | |
2474 | |
2452 return errs | 2475 return errs |
2453 | 2476 |
2454 @command( | 2477 @command( |
2455 'graft', | 2478 'graft', |
2456 [('c', 'continue', False, _('resume interrupted graft')), | 2479 [('c', 'continue', False, _('resume interrupted graft')), |