##// END OF EJS Templates
forget: fix subrepo recursion for explicit path handling...
David M. Carr -
r15912:2bd54ffa default
parent child Browse files
Show More
@@ -1201,6 +1201,48 b' def add(ui, repo, match, dryrun, listsub'
1201 1201 bad.extend(f for f in rejected if f in match.files())
1202 1202 return bad
1203 1203
1204 def forget(ui, repo, match, prefix, explicitonly):
1205 join = lambda f: os.path.join(prefix, f)
1206 bad = []
1207 oldbad = match.bad
1208 match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
1209 wctx = repo[None]
1210 forgot = []
1211 s = repo.status(match=match, clean=True)
1212 forget = sorted(s[0] + s[1] + s[3] + s[6])
1213 if explicitonly:
1214 forget = [f for f in forget if match.exact(f)]
1215
1216 for subpath in wctx.substate:
1217 sub = wctx.sub(subpath)
1218 try:
1219 submatch = matchmod.narrowmatcher(subpath, match)
1220 subbad, subforgot = sub.forget(ui, submatch, prefix)
1221 bad.extend([subpath + '/' + f for f in subbad])
1222 forgot.extend([subpath + '/' + f for f in subforgot])
1223 except error.LookupError:
1224 ui.status(_("skipping missing subrepository: %s\n")
1225 % join(subpath))
1226
1227 for f in match.files():
1228 if match.exact(f) or not explicitonly:
1229 if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))):
1230 if f not in forgot:
1231 if os.path.exists(match.rel(join(f))):
1232 ui.warn(_('not removing %s: '
1233 'file is already untracked\n')
1234 % match.rel(join(f)))
1235 bad.append(f)
1236
1237 for f in forget:
1238 if ui.verbose or not match.exact(f):
1239 ui.status(_('removing %s\n') % match.rel(join(f)))
1240
1241 rejected = wctx.forget(forget, prefix)
1242 bad.extend(f for f in rejected if f in match.files())
1243 forgot.extend(forget)
1244 return bad, forgot
1245
1204 1246 def duplicatecopies(repo, rev, p1):
1205 1247 "Reproduce copies found in the source revision in the dirstate for grafts"
1206 1248 for dst, src in copies.pathcopies(repo[p1], repo[rev]).iteritems():
@@ -13,7 +13,6 b' import hg, scmutil, util, revlog, extens'
13 13 import patch, help, url, encoding, templatekw, discovery
14 14 import archival, changegroup, cmdutil, hbisect
15 15 import sshserver, hgweb, hgweb.server, commandserver
16 import match as matchmod
17 16 import merge as mergemod
18 17 import minirst, revset, fileset
19 18 import dagparser, context, simplemerge
@@ -2449,46 +2448,9 b' def forget(ui, repo, *pats, **opts):'
2449 2448 if not pats:
2450 2449 raise util.Abort(_('no files specified'))
2451 2450
2452 wctx = repo[None]
2453 m = scmutil.match(wctx, pats, opts)
2454 s = repo.status(match=m, clean=True)
2455 forget = sorted(s[0] + s[1] + s[3] + s[6])
2456 subforget = {}
2457 errs = 0
2458
2459 for subpath in wctx.substate:
2460 sub = wctx.sub(subpath)
2461 try:
2462 submatch = matchmod.narrowmatcher(subpath, m)
2463 for fsub in sub.walk(submatch):
2464 if submatch.exact(fsub):
2465 subforget[subpath + '/' + fsub] = (fsub, sub)
2466 except error.LookupError:
2467 ui.status(_("skipping missing subrepository: %s\n") % subpath)
2468
2469 for f in m.files():
2470 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
2471 if f not in subforget:
2472 if os.path.exists(m.rel(f)):
2473 ui.warn(_('not removing %s: file is already untracked\n')
2474 % m.rel(f))
2475 errs = 1
2476
2477 for f in forget:
2478 if ui.verbose or not m.exact(f):
2479 ui.status(_('removing %s\n') % m.rel(f))
2480
2481 if ui.verbose:
2482 for f in sorted(subforget.keys()):
2483 ui.status(_('removing %s\n') % m.rel(f))
2484
2485 wctx.forget(forget)
2486
2487 for f in sorted(subforget.keys()):
2488 fsub, sub = subforget[f]
2489 sub.forget([fsub])
2490
2491 return errs
2451 m = scmutil.match(repo[None], pats, opts)
2452 rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0]
2453 return rejected and 1 or 0
2492 2454
2493 2455 @command(
2494 2456 'graft',
@@ -900,16 +900,20 b' class workingctx(changectx):'
900 900 finally:
901 901 wlock.release()
902 902
903 def forget(self, files):
903 def forget(self, files, prefix=""):
904 join = lambda f: os.path.join(prefix, f)
904 905 wlock = self._repo.wlock()
905 906 try:
907 rejected = []
906 908 for f in files:
907 909 if self._repo.dirstate[f] != 'a':
908 910 self._repo.dirstate.remove(f)
909 911 elif f not in self._repo.dirstate:
910 self._repo.ui.warn(_("%s not tracked!\n") % f)
912 self._repo.ui.warn(_("%s not tracked!\n") % join(f))
913 rejected.append(f)
911 914 else:
912 915 self._repo.dirstate.drop(f)
916 return rejected
913 917 finally:
914 918 wlock.release()
915 919
@@ -360,8 +360,8 b' class abstractsubrepo(object):'
360 360 '''
361 361 pass
362 362
363 def forget(self, files):
364 pass
363 def forget(self, ui, match, prefix):
364 return []
365 365
366 366 class hgsubrepo(abstractsubrepo):
367 367 def __init__(self, ctx, path, state):
@@ -561,9 +561,9 b' class hgsubrepo(abstractsubrepo):'
561 561 ctx = self._repo[None]
562 562 return ctx.walk(match)
563 563
564 def forget(self, files):
565 ctx = self._repo[None]
566 ctx.forget(files)
564 def forget(self, ui, match, prefix):
565 return cmdutil.forget(ui, self._repo, match,
566 os.path.join(prefix, self._path), True)
567 567
568 568 class svnsubrepo(abstractsubrepo):
569 569 def __init__(self, ctx, path, state):
@@ -197,12 +197,6 b' Test explicit path commands within subre'
197 197 A foo/bar/z2.txt
198 198 This is expected to forget the file, but is currently broken
199 199 $ hg forget foo/bar/z2.txt
200 not removing foo/bar/z2.txt: file is already untracked
201 [1]
202 $ hg status -S
203 A foo/bar/z2.txt
204 When fixed, remove the next two commands
205 $ hg forget -R foo/bar foo/bar/z2.txt
206 200 $ hg status -S
207 201 ? foo/bar/z2.txt
208 202 $ rm foo/bar/z2.txt
General Comments 0
You need to be logged in to leave comments. Login now