##// END OF EJS Templates
fix comment.
Vadim Gelfer -
r2957:6e062d9b default
parent child Browse files
Show More
@@ -1,111 +1,111 b''
1 # commands.py - command processing for mercurial
1 # cmdutil.py - help for command processing in mercurial
2 2 #
3 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from demandload import demandload
9 9 from node import *
10 10 from i18n import gettext as _
11 11 demandload(globals(), 'util')
12 12 demandload(globals(), 'os sys')
13 13
14 14 def make_filename(repo, pat, node,
15 15 total=None, seqno=None, revwidth=None, pathname=None):
16 16 node_expander = {
17 17 'H': lambda: hex(node),
18 18 'R': lambda: str(repo.changelog.rev(node)),
19 19 'h': lambda: short(node),
20 20 }
21 21 expander = {
22 22 '%': lambda: '%',
23 23 'b': lambda: os.path.basename(repo.root),
24 24 }
25 25
26 26 try:
27 27 if node:
28 28 expander.update(node_expander)
29 29 if node and revwidth is not None:
30 30 expander['r'] = (lambda:
31 31 str(repo.changelog.rev(node)).zfill(revwidth))
32 32 if total is not None:
33 33 expander['N'] = lambda: str(total)
34 34 if seqno is not None:
35 35 expander['n'] = lambda: str(seqno)
36 36 if total is not None and seqno is not None:
37 37 expander['n'] = lambda:str(seqno).zfill(len(str(total)))
38 38 if pathname is not None:
39 39 expander['s'] = lambda: os.path.basename(pathname)
40 40 expander['d'] = lambda: os.path.dirname(pathname) or '.'
41 41 expander['p'] = lambda: pathname
42 42
43 43 newname = []
44 44 patlen = len(pat)
45 45 i = 0
46 46 while i < patlen:
47 47 c = pat[i]
48 48 if c == '%':
49 49 i += 1
50 50 c = pat[i]
51 51 c = expander[c]()
52 52 newname.append(c)
53 53 i += 1
54 54 return ''.join(newname)
55 55 except KeyError, inst:
56 56 raise util.Abort(_("invalid format spec '%%%s' in output file name"),
57 57 inst.args[0])
58 58
59 59 def make_file(repo, pat, node=None,
60 60 total=None, seqno=None, revwidth=None, mode='wb', pathname=None):
61 61 if not pat or pat == '-':
62 62 return 'w' in mode and sys.stdout or sys.stdin
63 63 if hasattr(pat, 'write') and 'w' in mode:
64 64 return pat
65 65 if hasattr(pat, 'read') and 'r' in mode:
66 66 return pat
67 67 return open(make_filename(repo, pat, node, total, seqno, revwidth,
68 68 pathname),
69 69 mode)
70 70
71 71 def matchpats(repo, pats=[], opts={}, head=''):
72 72 cwd = repo.getcwd()
73 73 if not pats and cwd:
74 74 opts['include'] = [os.path.join(cwd, i)
75 75 for i in opts.get('include', [])]
76 76 opts['exclude'] = [os.path.join(cwd, x)
77 77 for x in opts.get('exclude', [])]
78 78 cwd = ''
79 79 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
80 80 opts.get('exclude'), head)
81 81
82 82 def makewalk(repo, pats=[], opts={}, node=None, head='', badmatch=None):
83 83 files, matchfn, anypats = matchpats(repo, pats, opts, head)
84 84 exact = dict(zip(files, files))
85 85 def walk():
86 86 for src, fn in repo.walk(node=node, files=files, match=matchfn,
87 87 badmatch=badmatch):
88 88 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact
89 89 return files, matchfn, walk()
90 90
91 91 def walk(repo, pats=[], opts={}, node=None, head='', badmatch=None):
92 92 files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch)
93 93 for r in results:
94 94 yield r
95 95
96 96 def addremove(repo, pats=[], opts={}, wlock=None, dry_run=None):
97 97 if dry_run is None:
98 98 dry_run = opts.get('dry_run')
99 99 add, remove = [], []
100 100 for src, abs, rel, exact in walk(repo, pats, opts):
101 101 if src == 'f' and repo.dirstate.state(abs) == '?':
102 102 add.append(abs)
103 103 if repo.ui.verbose or not exact:
104 104 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
105 105 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel):
106 106 remove.append(abs)
107 107 if repo.ui.verbose or not exact:
108 108 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
109 109 if not dry_run:
110 110 repo.add(add, wlock=wlock)
111 111 repo.remove(remove, wlock=wlock)
General Comments 0
You need to be logged in to leave comments. Login now