##// END OF EJS Templates
add default values to arguments of walk etc.
Vadim Gelfer -
r2884:fcdcf0c1 default
parent child Browse files
Show More
@@ -1,109 +1,109 b''
1 1 # commands.py - command processing for 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) for i in opts['include']]
75 75 opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
76 76 cwd = ''
77 77 return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
78 78 opts.get('exclude'), head)
79 79
80 def makewalk(repo, pats, opts, node=None, head='', badmatch=None):
80 def makewalk(repo, pats=[], opts={}, node=None, head='', badmatch=None):
81 81 files, matchfn, anypats = matchpats(repo, pats, opts, head)
82 82 exact = dict(zip(files, files))
83 83 def walk():
84 84 for src, fn in repo.walk(node=node, files=files, match=matchfn,
85 85 badmatch=badmatch):
86 86 yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact
87 87 return files, matchfn, walk()
88 88
89 def walk(repo, pats, opts, node=None, head='', badmatch=None):
89 def walk(repo, pats=[], opts={}, node=None, head='', badmatch=None):
90 90 files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch)
91 91 for r in results:
92 92 yield r
93 93
94 def addremove(repo, pats, opts={}, wlock=None, dry_run=None):
94 def addremove(repo, pats=[], opts={}, wlock=None, dry_run=None):
95 95 if dry_run is None:
96 96 dry_run = opts.get('dry_run')
97 97 add, remove = [], []
98 98 for src, abs, rel, exact in walk(repo, pats, opts):
99 99 if src == 'f' and repo.dirstate.state(abs) == '?':
100 100 add.append(abs)
101 101 if repo.ui.verbose or not exact:
102 102 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
103 103 if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel):
104 104 remove.append(abs)
105 105 if repo.ui.verbose or not exact:
106 106 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
107 107 if not dry_run:
108 108 repo.add(add, wlock=wlock)
109 109 repo.remove(remove, wlock=wlock)
General Comments 0
You need to be logged in to leave comments. Login now