comparison mercurial/commands.py @ 814:0902ffece4b4

Merge with BOS
author mpm@selenic.com
date Sat, 30 Jul 2005 09:00:14 -0800
parents 8f5637f0a0c0 80fd2958235a
children 5a55e3011772
comparison
equal deleted inserted replaced
808:8f5637f0a0c0 814:0902ffece4b4
45 45
46 def walk(repo, pats, opts, head = ''): 46 def walk(repo, pats, opts, head = ''):
47 cwd = repo.getcwd() 47 cwd = repo.getcwd()
48 c = 0 48 c = 0
49 if cwd: c = len(cwd) + 1 49 if cwd: c = len(cwd) + 1
50 for src, fn in repo.walk(match = matchpats(cwd, pats, opts, head)): 50 files, matchfn = matchpats(cwd, pats, opts, head)
51 for src, fn in repo.walk(files = files, match = matchfn):
51 yield src, fn, fn[c:] 52 yield src, fn, fn[c:]
52 53
53 revrangesep = ':' 54 revrangesep = ':'
54 55
55 def revrange(ui, repo, revs, revlog=None): 56 def revrange(ui, repo, revs, revlog=None):
337 repo.add(names) 338 repo.add(names)
338 339
339 def addremove(ui, repo, *pats, **opts): 340 def addremove(ui, repo, *pats, **opts):
340 """add all new files, delete all missing files""" 341 """add all new files, delete all missing files"""
341 q = dict(zip(pats, pats)) 342 q = dict(zip(pats, pats))
342 cwd = repo.getcwd() 343 add, remove = [], []
343 n = (cwd and len(cwd) + 1) or 0 344 for src, abs, rel in walk(repo, pats, opts):
344 c, a, d, u = repo.changes(match = matchpats(cwd, pats, opts)) 345 if src == 'f':
345 for f in u: 346 if repo.dirstate.state(abs) == '?':
346 if f not in q: 347 add.append(abs)
347 ui.status('adding %s\n' % f[n:]) 348 if rel not in q: ui.status('adding ', rel, '\n')
348 repo.add(u) 349 elif repo.dirstate.state(abs) != 'r' and not os.path.exists(rel):
349 for f in d: 350 remove.append(abs)
350 if f not in q: 351 if rel not in q: ui.status('removing ', rel, '\n')
351 ui.status('removing %s\n' % f[n:]) 352 repo.add(add)
352 repo.remove(d) 353 repo.remove(remove)
353 354
354 def annotate(ui, repo, *pats, **opts): 355 def annotate(ui, repo, *pats, **opts):
355 """show changeset information per file line""" 356 """show changeset information per file line"""
356 def getnode(rev): 357 def getnode(rev):
357 return hg.short(repo.changelog.node(rev)) 358 return hg.short(repo.changelog.node(rev))
465 if not opts['noupdate']: 466 if not opts['noupdate']:
466 update(ui, repo) 467 update(ui, repo)
467 468
468 d.close() 469 d.close()
469 470
470 def commit(ui, repo, *files, **opts): 471 def commit(ui, repo, *pats, **opts):
471 """commit the specified files or all outstanding changes""" 472 """commit the specified files or all outstanding changes"""
472 if opts['text']: 473 if opts['text']:
473 ui.warn("Warning: -t and --text is deprecated," 474 ui.warn("Warning: -t and --text is deprecated,"
474 " please use -m or --message instead.\n") 475 " please use -m or --message instead.\n")
475 message = opts['message'] or opts['text'] 476 message = opts['message'] or opts['text']
479 message = open(logfile).read() 480 message = open(logfile).read()
480 except IOError, why: 481 except IOError, why:
481 ui.warn("Can't read commit message %s: %s\n" % (logfile, why)) 482 ui.warn("Can't read commit message %s: %s\n" % (logfile, why))
482 483
483 if opts['addremove']: 484 if opts['addremove']:
484 addremove(ui, repo, *files) 485 addremove(ui, repo, *pats, **opts)
485 repo.commit(relpath(repo, files), message, opts['user'], opts['date']) 486 cwd = repo.getcwd()
487 if not pats and cwd:
488 opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
489 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
490 fns, match = matchpats((pats and repo.getcwd()) or '', pats, opts)
491 if pats:
492 c, a, d, u = repo.changes(files = fns, match = match)
493 files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r']
494 else:
495 files = []
496 repo.commit(files, message, opts['user'], opts['date'], match)
486 497
487 def copy(ui, repo, source, dest): 498 def copy(ui, repo, source, dest):
488 """mark a file as copied or renamed for the next commit""" 499 """mark a file as copied or renamed for the next commit"""
489 return repo.copy(*relpath(repo, (source, dest))) 500 return repo.copy(*relpath(repo, (source, dest)))
490 501
602 ui.note(len(revs) > 1 and "Exporting patches:\n" or "Exporting patch:\n") 613 ui.note(len(revs) > 1 and "Exporting patches:\n" or "Exporting patch:\n")
603 for cset in revs: 614 for cset in revs:
604 seqno += 1 615 seqno += 1
605 doexport(ui, repo, cset, seqno, total, revwidth, opts) 616 doexport(ui, repo, cset, seqno, total, revwidth, opts)
606 617
607 def forget(ui, repo, file1, *files): 618 def forget(ui, repo, *pats, **opts):
608 """don't add the specified files on the next commit""" 619 """don't add the specified files on the next commit"""
609 repo.forget(relpath(repo, (file1,) + files)) 620 q = dict(zip(pats, pats))
621 forget = []
622 for src, abs, rel in walk(repo, pats, opts):
623 if repo.dirstate.state(abs) == 'a':
624 forget.append(abs)
625 if rel not in q: ui.status('forgetting ', rel, '\n')
626 repo.forget(forget)
610 627
611 def heads(ui, repo): 628 def heads(ui, repo):
612 """show current repository heads""" 629 """show current repository heads"""
613 for n in repo.changelog.heads(): 630 for n in repo.changelog.heads():
614 show_changeset(ui, repo, changenode=n) 631 show_changeset(ui, repo, changenode=n)
1002 M = modified 1019 M = modified
1003 A = added 1020 A = added
1004 R = removed 1021 R = removed
1005 ? = not tracked''' 1022 ? = not tracked'''
1006 1023
1007 (c, a, d, u) = repo.changes(match = matchpats(repo.getcwd(), pats, opts)) 1024 files, matchfn = matchpats(repo.getcwd(), pats, opts)
1025 (c, a, d, u) = repo.changes(files = files, match = matchfn)
1008 (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) 1026 (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u))
1009 1027
1010 for f in c: 1028 for f in c:
1011 ui.write("M ", f, "\n") 1029 ui.write("M ", f, "\n")
1012 for f in a: 1030 for f in a:
1133 [('U', 'noupdate', None, 'skip update after cloning')], 1151 [('U', 'noupdate', None, 'skip update after cloning')],
1134 'hg clone [-U] SOURCE [DEST]'), 1152 'hg clone [-U] SOURCE [DEST]'),
1135 "^commit|ci": 1153 "^commit|ci":
1136 (commit, 1154 (commit,
1137 [('A', 'addremove', None, 'run add/remove during commit'), 1155 [('A', 'addremove', None, 'run add/remove during commit'),
1156 ('I', 'include', [], 'include path in search'),
1157 ('X', 'exclude', [], 'exclude path from search'),
1138 ('m', 'message', "", 'commit message'), 1158 ('m', 'message', "", 'commit message'),
1139 ('t', 'text', "", 'commit message (deprecated: use -m)'), 1159 ('t', 'text', "", 'commit message (deprecated: use -m)'),
1140 ('l', 'logfile', "", 'commit message file'), 1160 ('l', 'logfile', "", 'commit message file'),
1141 ('d', 'date', "", 'date code'), 1161 ('d', 'date', "", 'date code'),
1142 ('u', 'user', "", 'user')], 1162 ('u', 'user', "", 'user')],
1154 'hg diff [-r REV1 [-r REV2]] [FILE]...'), 1174 'hg diff [-r REV1 [-r REV2]] [FILE]...'),
1155 "^export": 1175 "^export":
1156 (export, 1176 (export,
1157 [('o', 'output', "", 'output to file')], 1177 [('o', 'output', "", 'output to file')],
1158 "hg export [-o OUTFILE] REV..."), 1178 "hg export [-o OUTFILE] REV..."),
1159 "forget": (forget, [], "hg forget FILE..."), 1179 "forget": (forget,
1180 [('I', 'include', [], 'include path in search'),
1181 ('X', 'exclude', [], 'exclude path from search')],
1182 "hg forget FILE..."),
1160 "heads": (heads, [], 'hg heads'), 1183 "heads": (heads, [], 'hg heads'),
1161 "help": (help_, [], 'hg help [COMMAND]'), 1184 "help": (help_, [], 'hg help [COMMAND]'),
1162 "identify|id": (identify, [], 'hg identify'), 1185 "identify|id": (identify, [], 'hg identify'),
1163 "import|patch": 1186 "import|patch":
1164 (import_, 1187 (import_,