mercurial/commands.py
changeset 6579 0159b7a36184
parent 6578 f242d3684f83
child 6582 5acbdd3941c4
equal deleted inserted replaced
6578:f242d3684f83 6579:0159b7a36184
    29     """
    29     """
    30 
    30 
    31     rejected = None
    31     rejected = None
    32     exacts = {}
    32     exacts = {}
    33     names = []
    33     names = []
    34     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
    34     m = cmdutil.match(repo, pats, opts)
    35                                              badmatch=lambda x,y: True):
    35     m.bad = lambda x,y: True
       
    36     for src, abs, rel, exact in cmdutil.walk(repo, m):
    36         if exact:
    37         if exact:
    37             if ui.verbose:
    38             if ui.verbose:
    38                 ui.status(_('adding %s\n') % rel)
    39                 ui.status(_('adding %s\n') % rel)
    39             names.append(abs)
    40             names.append(abs)
    40             exacts[abs] = 1
    41             exacts[abs] = 1
   106         lastfunc = funcmap[-1]
   107         lastfunc = funcmap[-1]
   107         funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
   108         funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
   108 
   109 
   109     ctx = repo.changectx(opts['rev'])
   110     ctx = repo.changectx(opts['rev'])
   110 
   111 
   111     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
   112     m = cmdutil.match(repo, pats, opts)
   112                                              node=ctx.node()):
   113     for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()):
   113         fctx = ctx.filectx(abs)
   114         fctx = ctx.filectx(abs)
   114         if not opts['text'] and util.binary(fctx.data()):
   115         if not opts['text'] and util.binary(fctx.data()):
   115             ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
   116             ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
   116             continue
   117             continue
   117 
   118 
   158         raise util.Abort(_('repository has no revisions'))
   159         raise util.Abort(_('repository has no revisions'))
   159     node = ctx.node()
   160     node = ctx.node()
   160     dest = cmdutil.make_filename(repo, dest, node)
   161     dest = cmdutil.make_filename(repo, dest, node)
   161     if os.path.realpath(dest) == repo.root:
   162     if os.path.realpath(dest) == repo.root:
   162         raise util.Abort(_('repository root cannot be destination'))
   163         raise util.Abort(_('repository root cannot be destination'))
   163     dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts)
   164     matchfn = cmdutil.match(repo, [], opts)
   164     kind = opts.get('type') or 'files'
   165     kind = opts.get('type') or 'files'
   165     prefix = opts['prefix']
   166     prefix = opts['prefix']
   166     if dest == '-':
   167     if dest == '-':
   167         if kind == 'files':
   168         if kind == 'files':
   168             raise util.Abort(_('cannot archive plain files to stdout'))
   169             raise util.Abort(_('cannot archive plain files to stdout'))
   485     %d   dirname of file being printed, or '.' if in repo root
   486     %d   dirname of file being printed, or '.' if in repo root
   486     %p   root-relative path name of file being printed
   487     %p   root-relative path name of file being printed
   487     """
   488     """
   488     ctx = repo.changectx(opts['rev'])
   489     ctx = repo.changectx(opts['rev'])
   489     err = 1
   490     err = 1
   490     for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
   491     m = cmdutil.match(repo, (file1,) + pats, opts)
   491                                              ctx.node()):
   492     for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()):
   492         fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
   493         fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
   493         data = ctx.filectx(abs).data()
   494         data = ctx.filectx(abs).data()
   494         if opts.get('decode'):
   495         if opts.get('decode'):
   495             data = repo.wwritedata(abs, data)
   496             data = repo.wwritedata(abs, data)
   496         fp.write(data)
   497         fp.write(data)
   911 
   912 
   912 def debugrename(ui, repo, file1, *pats, **opts):
   913 def debugrename(ui, repo, file1, *pats, **opts):
   913     """dump rename information"""
   914     """dump rename information"""
   914 
   915 
   915     ctx = repo.changectx(opts.get('rev', 'tip'))
   916     ctx = repo.changectx(opts.get('rev', 'tip'))
   916     for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
   917     m = cmdutil.match(repo, (file1,) + pats, opts)
   917                                              ctx.node()):
   918     for src, abs, rel, exact in cmdutil.walk(repo, m, ctx.node()):
   918         fctx = ctx.filectx(abs)
   919         fctx = ctx.filectx(abs)
   919         m = fctx.filelog().renamed(fctx.filenode())
   920         o = fctx.filelog().renamed(fctx.filenode())
   920         if m:
   921         if o:
   921             ui.write(_("%s renamed from %s:%s\n") % (rel, m[0], hex(m[1])))
   922             ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
   922         else:
   923         else:
   923             ui.write(_("%s not renamed\n") % rel)
   924             ui.write(_("%s not renamed\n") % rel)
   924 
   925 
   925 def debugwalk(ui, repo, *pats, **opts):
   926 def debugwalk(ui, repo, *pats, **opts):
   926     """show how files match on given patterns"""
   927     """show how files match on given patterns"""
   927     items = list(cmdutil.walk(repo, pats, opts))
   928     m = cmdutil.match(repo, pats, opts)
       
   929     items = list(cmdutil.walk(repo, m))
   928     if not items:
   930     if not items:
   929         return
   931         return
   930     fmt = '%%s  %%-%ds  %%-%ds  %%s' % (
   932     fmt = '%%s  %%-%ds  %%-%ds  %%s' % (
   931         max([len(abs) for (src, abs, rel, exact) in items]),
   933         max([len(abs) for (src, abs, rel, exact) in items]),
   932         max([len(rel) for (src, abs, rel, exact) in items]))
   934         max([len(rel) for (src, abs, rel, exact) in items]))
  1693         node = repo.lookup(rev)
  1695         node = repo.lookup(rev)
  1694     else:
  1696     else:
  1695         node = None
  1697         node = None
  1696 
  1698 
  1697     ret = 1
  1699     ret = 1
  1698     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
  1700     m = cmdutil.match(repo, pats, opts, default='relglob')
  1699                                              badmatch=lambda x,y: True,
  1701     m.bad = lambda x,y: True
  1700                                              default='relglob'):
  1702     for src, abs, rel, exact in cmdutil.walk(repo, m, node):
  1701         if src == 'b':
  1703         if src == 'b':
  1702             continue
  1704             continue
  1703         if not node and abs not in repo.dirstate:
  1705         if not node and abs not in repo.dirstate:
  1704             continue
  1706             continue
  1705         if opts['fullpath']:
  1707         if opts['fullpath']:
  2183     files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
  2185     files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
  2184     mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5]
  2186     mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5]
  2185     modified, added, removed, deleted, unknown = mardu
  2187     modified, added, removed, deleted, unknown = mardu
  2186 
  2188 
  2187     remove, forget = [], []
  2189     remove, forget = [], []
  2188     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
  2190     m = cmdutil.match(repo, pats, opts)
       
  2191     for src, abs, rel, exact in cmdutil.walk(repo, m):
  2189 
  2192 
  2190         reason = None
  2193         reason = None
  2191         if abs in removed or abs in unknown:
  2194         if abs in removed or abs in unknown:
  2192             continue
  2195             continue
  2193 
  2196 
  2337 
  2340 
  2338     wlock = repo.wlock()
  2341     wlock = repo.wlock()
  2339     try:
  2342     try:
  2340         # walk dirstate.
  2343         # walk dirstate.
  2341         files = []
  2344         files = []
  2342         for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
  2345 
  2343                                                  badmatch=mf.has_key):
  2346         m = cmdutil.match(repo, pats, opts)
       
  2347         def bad(f, msg):
       
  2348             if f not in mf:
       
  2349                 repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
       
  2350             return False
       
  2351         m.bad = bad
       
  2352         for src, abs, rel, exact in cmdutil.walk(repo, m):
  2344             names[abs] = (rel, exact)
  2353             names[abs] = (rel, exact)
  2345             if src != 'b':
       
  2346                 files.append(abs)
       
  2347 
  2354 
  2348         # walk target manifest.
  2355         # walk target manifest.
  2349 
  2356 
  2350         def badmatch(path):
  2357         def badfn(path, msg):
  2351             if path in names:
  2358             if path in names:
  2352                 return True
  2359                 return True
  2353             path_ = path + '/'
  2360             path_ = path + '/'
  2354             for f in names:
  2361             for f in names:
  2355                 if f.startswith(path_):
  2362                 if f.startswith(path_):
  2356                     return True
  2363                     return True
  2357             return False
  2364             return False
  2358 
  2365 
  2359         for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
  2366         m = cmdutil.match(repo, pats, opts)
  2360                                                  badmatch=badmatch):
  2367         m.bad = badfn
       
  2368         for src, abs, rel, exact in cmdutil.walk(repo, m, node=node):
  2361             if abs in names or src == 'b':
  2369             if abs in names or src == 'b':
  2362                 continue
  2370                 continue
  2363             names[abs] = (rel, exact)
  2371             names[abs] = (rel, exact)
  2364 
  2372 
  2365         changes = repo.status(files=files, match=names.has_key)[:4]
  2373         changes = repo.status(files=files, match=names.has_key)[:4]