comparison mercurial/commands.py @ 6584:29c77e5dfb3c

walk: remove rel and exact returns
author Matt Mackall <mpm@selenic.com>
date Mon, 12 May 2008 11:37:08 -0500
parents 3951e04ea989
children d3d1d39da2fa
comparison
equal deleted inserted replaced
6583:3951e04ea989 6584:29c77e5dfb3c
31 rejected = None 31 rejected = None
32 exacts = {} 32 exacts = {}
33 names = [] 33 names = []
34 m = cmdutil.match(repo, pats, opts) 34 m = cmdutil.match(repo, pats, opts)
35 m.bad = lambda x,y: True 35 m.bad = lambda x,y: True
36 for src, abs, rel, exact in cmdutil.walk(repo, m): 36 for src, abs in cmdutil.walk(repo, m):
37 if exact: 37 if m.exact(abs):
38 if ui.verbose: 38 if ui.verbose:
39 ui.status(_('adding %s\n') % rel) 39 ui.status(_('adding %s\n') % m.rel(abs))
40 names.append(abs) 40 names.append(abs)
41 exacts[abs] = 1 41 exacts[abs] = 1
42 elif abs not in repo.dirstate: 42 elif abs not in repo.dirstate:
43 ui.status(_('adding %s\n') % rel) 43 ui.status(_('adding %s\n') % m.rel(abs))
44 names.append(abs) 44 names.append(abs)
45 if not opts.get('dry_run'): 45 if not opts.get('dry_run'):
46 rejected = repo.add(names) 46 rejected = repo.add(names)
47 rejected = [p for p in rejected if p in exacts] 47 rejected = [p for p in rejected if p in exacts]
48 return rejected and 1 or 0 48 return rejected and 1 or 0
108 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) 108 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
109 109
110 ctx = repo.changectx(opts['rev']) 110 ctx = repo.changectx(opts['rev'])
111 111
112 m = cmdutil.match(repo, pats, opts) 112 m = cmdutil.match(repo, pats, opts)
113 for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()): 113 for src, abs in cmdutil.walk(repo, m, ctx.node()):
114 fctx = ctx.filectx(abs) 114 fctx = ctx.filectx(abs)
115 if not opts['text'] and util.binary(fctx.data()): 115 if not opts['text'] and util.binary(fctx.data()):
116 ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) 116 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
117 continue 117 continue
118 118
119 lines = fctx.annotate(follow=opts.get('follow'), 119 lines = fctx.annotate(follow=opts.get('follow'),
120 linenumber=linenumber) 120 linenumber=linenumber)
121 pieces = [] 121 pieces = []
487 %p root-relative path name of file being printed 487 %p root-relative path name of file being printed
488 """ 488 """
489 ctx = repo.changectx(opts['rev']) 489 ctx = repo.changectx(opts['rev'])
490 err = 1 490 err = 1
491 m = cmdutil.match(repo, (file1,) + pats, opts) 491 m = cmdutil.match(repo, (file1,) + pats, opts)
492 for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()): 492 for src, abs in cmdutil.walk(repo, m, ctx.node()):
493 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) 493 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
494 data = ctx.filectx(abs).data() 494 data = ctx.filectx(abs).data()
495 if opts.get('decode'): 495 if opts.get('decode'):
496 data = repo.wwritedata(abs, data) 496 data = repo.wwritedata(abs, data)
497 fp.write(data) 497 fp.write(data)
913 def debugrename(ui, repo, file1, *pats, **opts): 913 def debugrename(ui, repo, file1, *pats, **opts):
914 """dump rename information""" 914 """dump rename information"""
915 915
916 ctx = repo.changectx(opts.get('rev', 'tip')) 916 ctx = repo.changectx(opts.get('rev', 'tip'))
917 m = cmdutil.match(repo, (file1,) + pats, opts) 917 m = cmdutil.match(repo, (file1,) + pats, opts)
918 for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()): 918 for src, abs in cmdutil.walk(repo, m, ctx.node()):
919 fctx = ctx.filectx(abs) 919 fctx = ctx.filectx(abs)
920 o = fctx.filelog().renamed(fctx.filenode()) 920 o = fctx.filelog().renamed(fctx.filenode())
921 rel = m.rel(abs)
921 if o: 922 if o:
922 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) 923 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
923 else: 924 else:
924 ui.write(_("%s not renamed\n") % rel) 925 ui.write(_("%s not renamed\n") % rel)
925 926
928 m = cmdutil.match(repo, pats, opts) 929 m = cmdutil.match(repo, pats, opts)
929 items = list(cmdutil.walk(repo, m)) 930 items = list(cmdutil.walk(repo, m))
930 if not items: 931 if not items:
931 return 932 return
932 fmt = '%%s %%-%ds %%-%ds %%s' % ( 933 fmt = '%%s %%-%ds %%-%ds %%s' % (
933 max([len(abs) for (src, abs, rel, exact) in items]), 934 max([len(abs) for (src, abs) in items]),
934 max([len(rel) for (src, abs, rel, exact) in items])) 935 max([len(m.rel(abs)) for (src, abs) in items]))
935 for src, abs, rel, exact in items: 936 for src, abs in items:
936 line = fmt % (src, abs, rel, exact and 'exact' or '') 937 line = fmt % (src, abs, m.rel(abs), m.exact(abs) and 'exact' or '')
937 ui.write("%s\n" % line.rstrip()) 938 ui.write("%s\n" % line.rstrip())
938 939
939 def diff(ui, repo, *pats, **opts): 940 def diff(ui, repo, *pats, **opts):
940 """diff repository (or selected files) 941 """diff repository (or selected files)
941 942
1696 node = None 1697 node = None
1697 1698
1698 ret = 1 1699 ret = 1
1699 m = cmdutil.match(repo, pats, opts, default='relglob') 1700 m = cmdutil.match(repo, pats, opts, default='relglob')
1700 m.bad = lambda x,y: False 1701 m.bad = lambda x,y: False
1701 for src, abs, rel, exact in cmdutil.walk(repo, m, node): 1702 for src, abs in cmdutil.walk(repo, m, node):
1702 if not node and abs not in repo.dirstate: 1703 if not node and abs not in repo.dirstate:
1703 continue 1704 continue
1704 if opts['fullpath']: 1705 if opts['fullpath']:
1705 ui.write(os.path.join(repo.root, abs), end) 1706 ui.write(os.path.join(repo.root, abs), end)
1706 else: 1707 else:
1707 ui.write(((pats and rel) or abs), end) 1708 ui.write(((pats and m.rel(abs)) or abs), end)
1708 ret = 0 1709 ret = 0
1709 1710
1710 return ret 1711 return ret
1711 1712
1712 def log(ui, repo, *pats, **opts): 1713 def log(ui, repo, *pats, **opts):
2182 m = cmdutil.match(repo, pats, opts) 2183 m = cmdutil.match(repo, pats, opts)
2183 mardu = map(dict.fromkeys, repo.status(files=m.files(), match=m))[:5] 2184 mardu = map(dict.fromkeys, repo.status(files=m.files(), match=m))[:5]
2184 modified, added, removed, deleted, unknown = mardu 2185 modified, added, removed, deleted, unknown = mardu
2185 2186
2186 remove, forget = [], [] 2187 remove, forget = [], []
2187 for src, abs, rel, exact in cmdutil.walk(repo, m): 2188 for src, abs in cmdutil.walk(repo, m):
2188 2189
2189 reason = None 2190 reason = None
2190 if abs in removed or abs in unknown: 2191 if abs in removed or abs in unknown:
2191 continue 2192 continue
2192 2193
2215 # rest of the second column 2216 # rest of the second column
2216 elif not reason: 2217 elif not reason:
2217 remove.append(abs) 2218 remove.append(abs)
2218 2219
2219 if reason: 2220 if reason:
2220 ui.warn(_('not removing %s: file %s\n') % (rel, reason)) 2221 ui.warn(_('not removing %s: file %s\n') % (m.rel(abs), reason))
2221 elif ui.verbose or not exact: 2222 elif ui.verbose or not m.exact(abs):
2222 ui.status(_('removing %s\n') % rel) 2223 ui.status(_('removing %s\n') % m.rel(abs))
2223 2224
2224 repo.forget(forget) 2225 repo.forget(forget)
2225 repo.remove(remove, unlink=not after) 2226 repo.remove(remove, unlink=not after)
2226 2227
2227 def rename(ui, repo, *pats, **opts): 2228 def rename(ui, repo, *pats, **opts):
2339 # walk dirstate. 2340 # walk dirstate.
2340 files = [] 2341 files = []
2341 2342
2342 m = cmdutil.match(repo, pats, opts) 2343 m = cmdutil.match(repo, pats, opts)
2343 m.bad = lambda x,y: False 2344 m.bad = lambda x,y: False
2344 for src, abs, rel, exact in cmdutil.walk(repo, m): 2345 for src, abs in cmdutil.walk(repo, m):
2345 names[abs] = (rel, exact) 2346 names[abs] = m.rel(abs), m.exact(abs)
2346 2347
2347 # walk target manifest. 2348 # walk target manifest.
2348 2349
2349 def badfn(path, msg): 2350 def badfn(path, msg):
2350 if path in names: 2351 if path in names:
2356 repo.ui.warn("%s: %s\n" % (m.rel(path), msg)) 2357 repo.ui.warn("%s: %s\n" % (m.rel(path), msg))
2357 return False 2358 return False
2358 2359
2359 m = cmdutil.match(repo, pats, opts) 2360 m = cmdutil.match(repo, pats, opts)
2360 m.bad = badfn 2361 m.bad = badfn
2361 for src, abs, rel, exact in cmdutil.walk(repo, m, node=node): 2362 for src, abs in cmdutil.walk(repo, m, node=node):
2362 if abs in names: 2363 if abs not in names:
2363 continue 2364 names[abs] = m.rel(abs), m.exact(abs)
2364 names[abs] = (rel, exact)
2365 2365
2366 changes = repo.status(files=files, match=names.has_key)[:4] 2366 changes = repo.status(files=files, match=names.has_key)[:4]
2367 modified, added, removed, deleted = map(dict.fromkeys, changes) 2367 modified, added, removed, deleted = map(dict.fromkeys, changes)
2368 2368
2369 # if f is a rename, also revert the source 2369 # if f is a rename, also revert the source