mercurial/commands.py
changeset 6747 f6c00b17387c
parent 6746 1dca460e7d1e
child 6748 c6cc35a3d1de
equal deleted inserted replaced
6746:1dca460e7d1e 6747:f6c00b17387c
   105     funcmap = [func for op, func in opmap if opts.get(op)]
   105     funcmap = [func for op, func in opmap if opts.get(op)]
   106     if linenumber:
   106     if linenumber:
   107         lastfunc = funcmap[-1]
   107         lastfunc = funcmap[-1]
   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[opts['rev']]
   111 
   111 
   112     m = cmdutil.match(repo, pats, opts)
   112     m = cmdutil.match(repo, pats, opts)
   113     for abs in repo.walk(m, ctx.node()):
   113     for abs in repo.walk(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()):
   152     Each member added to an archive file has a directory prefix
   152     Each member added to an archive file has a directory prefix
   153     prepended. Use "-p" to specify a format string for the prefix.
   153     prepended. Use "-p" to specify a format string for the prefix.
   154     The default is the basename of the archive, with suffixes removed.
   154     The default is the basename of the archive, with suffixes removed.
   155     '''
   155     '''
   156 
   156 
   157     ctx = repo.changectx(opts['rev'])
   157     ctx = repo[opts['rev']]
   158     if not ctx:
   158     if not ctx:
   159         raise util.Abort(_('repository has no revisions'))
   159         raise util.Abort(_('repository has no revisions'))
   160     node = ctx.node()
   160     node = ctx.node()
   161     dest = cmdutil.make_filename(repo, dest, node)
   161     dest = cmdutil.make_filename(repo, dest, node)
   162     if os.path.realpath(dest) == repo.root:
   162     if os.path.realpath(dest) == repo.root:
   357     Use the command 'hg update' to switch to an existing branch.
   357     Use the command 'hg update' to switch to an existing branch.
   358     """
   358     """
   359 
   359 
   360     if label:
   360     if label:
   361         if not opts.get('force') and label in repo.branchtags():
   361         if not opts.get('force') and label in repo.branchtags():
   362             if label not in [p.branch() for p in repo.changectx(None).parents()]:
   362             if label not in [p.branch() for p in repo.parents()]:
   363                 raise util.Abort(_('a branch of the same name already exists'
   363                 raise util.Abort(_('a branch of the same name already exists'
   364                                    ' (use --force to override)'))
   364                                    ' (use --force to override)'))
   365         repo.dirstate.setbranch(util.fromlocal(label))
   365         repo.dirstate.setbranch(util.fromlocal(label))
   366         ui.status(_('marked working directory as branch %s\n') % label)
   366         ui.status(_('marked working directory as branch %s\n') % label)
   367     else:
   367     else:
   376     A branch is considered active if it contains repository heads.
   376     A branch is considered active if it contains repository heads.
   377 
   377 
   378     Use the command 'hg update' to switch to an existing branch.
   378     Use the command 'hg update' to switch to an existing branch.
   379     """
   379     """
   380     hexfunc = ui.debugflag and hex or short
   380     hexfunc = ui.debugflag and hex or short
   381     activebranches = [util.tolocal(repo.changectx(n).branch())
   381     activebranches = [util.tolocal(repo[n].branch())
   382                             for n in repo.heads()]
   382                             for n in repo.heads()]
   383     branches = [(tag in activebranches, repo.changelog.rev(node), tag)
   383     branches = [(tag in activebranches, repo.changelog.rev(node), tag)
   384                             for tag, node in repo.branchtags().items()]
   384                             for tag, node in repo.branchtags().items()]
   385     branches.sort()
   385     branches.sort()
   386     branches.reverse()
   386     branches.reverse()
   481 
   481 
   482     %s   basename of file being printed
   482     %s   basename of file being printed
   483     %d   dirname of file being printed, or '.' if in repo root
   483     %d   dirname of file being printed, or '.' if in repo root
   484     %p   root-relative path name of file being printed
   484     %p   root-relative path name of file being printed
   485     """
   485     """
   486     ctx = repo.changectx(opts['rev'])
   486     ctx = repo[opts['rev']]
   487     err = 1
   487     err = 1
   488     m = cmdutil.match(repo, (file1,) + pats, opts)
   488     m = cmdutil.match(repo, (file1,) + pats, opts)
   489     for abs in repo.walk(m, ctx.node()):
   489     for abs in repo.walk(m, ctx.node()):
   490         fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
   490         fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
   491         data = ctx.filectx(abs).data()
   491         data = ctx.filectx(abs).data()
   645     ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
   645     ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
   646     ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
   646     ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
   647                                 and 'yes' or 'no'))
   647                                 and 'yes' or 'no'))
   648     os.unlink('.debugfsinfo')
   648     os.unlink('.debugfsinfo')
   649 
   649 
   650 def debugrebuildstate(ui, repo, rev=""):
   650 def debugrebuildstate(ui, repo, rev="tip"):
   651     """rebuild the dirstate as it would look like for the given revision"""
   651     """rebuild the dirstate as it would look like for the given revision"""
   652     if rev == "":
   652     ctx = repo[rev]
   653         rev = repo.changelog.tip()
       
   654     ctx = repo.changectx(rev)
       
   655     files = ctx.manifest()
       
   656     wlock = repo.wlock()
   653     wlock = repo.wlock()
   657     try:
   654     try:
   658         repo.dirstate.rebuild(rev, files)
   655         repo.dirstate.rebuild(ctx.node(), ctx.manifest())
   659     finally:
   656     finally:
   660         del wlock
   657         del wlock
   661 
   658 
   662 def debugcheckstate(ui, repo):
   659 def debugcheckstate(ui, repo):
   663     """validate the correctness of the current dirstate"""
   660     """validate the correctness of the current dirstate"""
   664     parent1, parent2 = repo.dirstate.parents()
   661     parent1, parent2 = repo.dirstate.parents()
   665     m1 = repo.changectx(parent1).manifest()
   662     m1 = repo[parent1].manifest()
   666     m2 = repo.changectx(parent2).manifest()
   663     m2 = repo[parent2].manifest()
   667     errors = 0
   664     errors = 0
   668     for f in repo.dirstate:
   665     for f in repo.dirstate:
   669         state = repo.dirstate[f]
   666         state = repo.dirstate[f]
   670         if state in "nr" and f not in m1:
   667         if state in "nr" and f not in m1:
   671             ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
   668             ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
   911     return problems
   908     return problems
   912 
   909 
   913 def debugrename(ui, repo, file1, *pats, **opts):
   910 def debugrename(ui, repo, file1, *pats, **opts):
   914     """dump rename information"""
   911     """dump rename information"""
   915 
   912 
   916     ctx = repo.changectx(opts.get('rev', 'tip'))
   913     ctx = repo[opts.get('rev', 'tip')]
   917     m = cmdutil.match(repo, (file1,) + pats, opts)
   914     m = cmdutil.match(repo, (file1,) + pats, opts)
   918     for abs in repo.walk(m, ctx.node()):
   915     for abs in repo.walk(m, ctx.node()):
   919         fctx = ctx.filectx(abs)
   916         fctx = ctx.filectx(abs)
   920         o = fctx.filelog().renamed(fctx.filenode())
   917         o = fctx.filelog().renamed(fctx.filenode())
   921         rel = m.rel(abs)
   918         rel = m.rel(abs)
  1120             found = True
  1117             found = True
  1121         return found
  1118         return found
  1122 
  1119 
  1123     fstate = {}
  1120     fstate = {}
  1124     skip = {}
  1121     skip = {}
  1125     get = util.cachefunc(lambda r: repo.changectx(r).changeset())
  1122     get = util.cachefunc(lambda r: repo[r].changeset())
  1126     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
  1123     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
  1127     found = False
  1124     found = False
  1128     follow = opts.get('follow')
  1125     follow = opts.get('follow')
  1129     for st, rev, fns in changeiter:
  1126     for st, rev, fns in changeiter:
  1130         if st == 'window':
  1127         if st == 'window':
  1131             matches.clear()
  1128             matches.clear()
  1132         elif st == 'add':
  1129         elif st == 'add':
  1133             ctx = repo.changectx(rev)
  1130             ctx = repo[rev]
  1134             matches[rev] = {}
  1131             matches[rev] = {}
  1135             for fn in fns:
  1132             for fn in fns:
  1136                 if fn in skip:
  1133                 if fn in skip:
  1137                     continue
  1134                     continue
  1138                 try:
  1135                 try:
  1200         heads = repo.heads(start)
  1197         heads = repo.heads(start)
  1201     else:
  1198     else:
  1202         heads = []
  1199         heads = []
  1203         visitedset = util.set()
  1200         visitedset = util.set()
  1204         for branchrev in branchrevs:
  1201         for branchrev in branchrevs:
  1205             branch = repo.changectx(branchrev).branch()
  1202             branch = repo[branchrev].branch()
  1206             if branch in visitedset:
  1203             if branch in visitedset:
  1207                 continue
  1204                 continue
  1208             visitedset.add(branch)
  1205             visitedset.add(branch)
  1209             bheads = repo.branchheads(branch, start)
  1206             bheads = repo.branchheads(branch, start)
  1210             if not bheads:
  1207             if not bheads:
  1452         if num or branch or tags:
  1449         if num or branch or tags:
  1453             raise util.Abort(
  1450             raise util.Abort(
  1454                 "can't query remote revision number, branch, or tags")
  1451                 "can't query remote revision number, branch, or tags")
  1455         output = [hexfunc(srepo.lookup(rev))]
  1452         output = [hexfunc(srepo.lookup(rev))]
  1456     elif not rev:
  1453     elif not rev:
  1457         ctx = repo.changectx(None)
  1454         ctx = repo[None]
  1458         parents = ctx.parents()
  1455         parents = ctx.parents()
  1459         changed = False
  1456         changed = False
  1460         if default or id or num:
  1457         if default or id or num:
  1461             changed = ctx.files() + ctx.deleted()
  1458             changed = ctx.files() + ctx.deleted()
  1462         if default or id:
  1459         if default or id:
  1464                                 (changed) and "+" or "")]
  1461                                 (changed) and "+" or "")]
  1465         if num:
  1462         if num:
  1466             output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
  1463             output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
  1467                                     (changed) and "+" or ""))
  1464                                     (changed) and "+" or ""))
  1468     else:
  1465     else:
  1469         ctx = repo.changectx(rev)
  1466         ctx = repo[rev]
  1470         if default or id:
  1467         if default or id:
  1471             output = [hexfunc(ctx.node())]
  1468             output = [hexfunc(ctx.node())]
  1472         if num:
  1469         if num:
  1473             output.append(str(ctx.rev()))
  1470             output.append(str(ctx.rev()))
  1474 
  1471 
  1561                 else:
  1558                 else:
  1562                     # launch the editor
  1559                     # launch the editor
  1563                     message = None
  1560                     message = None
  1564                 ui.debug(_('message:\n%s\n') % message)
  1561                 ui.debug(_('message:\n%s\n') % message)
  1565 
  1562 
  1566                 wp = repo.changectx(None).parents()
  1563                 wp = repo.parents()
  1567                 if opts.get('exact'):
  1564                 if opts.get('exact'):
  1568                     if not nodeid or not p1:
  1565                     if not nodeid or not p1:
  1569                         raise util.Abort(_('not a mercurial patch'))
  1566                         raise util.Abort(_('not a mercurial patch'))
  1570                     p1 = repo.lookup(p1)
  1567                     p1 = repo.lookup(p1)
  1571                     p2 = repo.lookup(p2 or hex(nullid))
  1568                     p2 = repo.lookup(p2 or hex(nullid))
  1754     first parent only. Also, the files: list will only reflect files
  1751     first parent only. Also, the files: list will only reflect files
  1755     that are different from BOTH parents.
  1752     that are different from BOTH parents.
  1756 
  1753 
  1757     """
  1754     """
  1758 
  1755 
  1759     get = util.cachefunc(lambda r: repo.changectx(r).changeset())
  1756     get = util.cachefunc(lambda r: repo[r].changeset())
  1760     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
  1757     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
  1761 
  1758 
  1762     limit = cmdutil.loglimit(opts)
  1759     limit = cmdutil.loglimit(opts)
  1763     count = 0
  1760     count = 0
  1764 
  1761 
  1791 
  1788 
  1792         # If linkrev != rev (i.e. rev not found in rcache) fallback to
  1789         # If linkrev != rev (i.e. rev not found in rcache) fallback to
  1793         # filectx logic.
  1790         # filectx logic.
  1794 
  1791 
  1795         try:
  1792         try:
  1796             return repo.changectx(rev).filectx(fn).renamed()
  1793             return repo[rev][fn].renamed()
  1797         except revlog.LookupError:
  1794         except revlog.LookupError:
  1798             pass
  1795             pass
  1799         return None
  1796         return None
  1800 
  1797 
  1801     df = False
  1798     df = False
  1867         raise util.Abort(_("please specify just one revision"))
  1864         raise util.Abort(_("please specify just one revision"))
  1868 
  1865 
  1869     if not node:
  1866     if not node:
  1870         node = rev
  1867         node = rev
  1871 
  1868 
  1872     m = repo.changectx(node).manifest()
  1869     m = repo[node].manifest()
  1873     files = m.keys()
  1870     files = m.keys()
  1874     files.sort()
  1871     files.sort()
  1875 
  1872 
  1876     for f in files:
  1873     for f in files:
  1877         if ui.debugflag:
  1874         if ui.debugflag:
  1914             if len(repo.heads()) > 1:
  1911             if len(repo.heads()) > 1:
  1915                 raise util.Abort(_("branch '%s' has one head - "
  1912                 raise util.Abort(_("branch '%s' has one head - "
  1916                                    "please merge with an explicit rev") %
  1913                                    "please merge with an explicit rev") %
  1917                                  branch)
  1914                                  branch)
  1918             msg = _('there is nothing to merge')
  1915             msg = _('there is nothing to merge')
  1919             if parent != repo.lookup(repo.changectx(None).branch()):
  1916             if parent != repo.lookup(repo[None].branch()):
  1920                 msg = _('%s - use "hg update" instead') % msg
  1917                 msg = _('%s - use "hg update" instead') % msg
  1921             raise util.Abort(msg)
  1918             raise util.Abort(msg)
  1922 
  1919 
  1923         if parent not in bheads:
  1920         if parent not in bheads:
  1924             raise util.Abort(_('working dir not at a head rev - '
  1921             raise util.Abort(_('working dir not at a head rev - '
  1971     which the file was last changed (before the working directory
  1968     which the file was last changed (before the working directory
  1972     revision or the argument to --rev if given) is printed.
  1969     revision or the argument to --rev if given) is printed.
  1973     """
  1970     """
  1974     rev = opts.get('rev')
  1971     rev = opts.get('rev')
  1975     if rev:
  1972     if rev:
  1976         ctx = repo.changectx(rev)
  1973         ctx = repo[rev]
  1977     else:
  1974     else:
  1978         ctx = repo.changectx(None)
  1975         ctx = repo[None]
  1979 
  1976 
  1980     if file_:
  1977     if file_:
  1981         m = cmdutil.match(repo, (file_,), opts)
  1978         m = cmdutil.match(repo, (file_,), opts)
  1982         if m.anypats() or len(m.files()) != 1:
  1979         if m.anypats() or len(m.files()) != 1:
  1983             raise util.Abort(_('can only specify an explicit file name'))
  1980             raise util.Abort(_('can only specify an explicit file name'))
  2295             elif opts.get("mark"):
  2292             elif opts.get("mark"):
  2296                 ms.mark(f, "r")
  2293                 ms.mark(f, "r")
  2297             elif opts.get("unmark"):
  2294             elif opts.get("unmark"):
  2298                 ms.mark(f, "u")
  2295                 ms.mark(f, "u")
  2299             else:
  2296             else:
  2300                 wctx = repo.changectx(None)
  2297                 wctx = repo[None]
  2301                 mctx = wctx.parents()[-1]
  2298                 mctx = wctx.parents()[-1]
  2302                 ms.resolve(f, wctx, mctx)
  2299                 ms.resolve(f, wctx, mctx)
  2303 
  2300 
  2304 def revert(ui, repo, *pats, **opts):
  2301 def revert(ui, repo, *pats, **opts):
  2305     """restore individual files or dirs to an earlier state
  2302     """restore individual files or dirs to an earlier state
  2346 
  2343 
  2347     parent, p2 = repo.dirstate.parents()
  2344     parent, p2 = repo.dirstate.parents()
  2348     if not opts['rev'] and p2 != nullid:
  2345     if not opts['rev'] and p2 != nullid:
  2349         raise util.Abort(_('uncommitted merge - please provide a '
  2346         raise util.Abort(_('uncommitted merge - please provide a '
  2350                            'specific revision'))
  2347                            'specific revision'))
  2351     ctx = repo.changectx(opts['rev'])
  2348     ctx = repo[opts['rev']]
  2352     node = ctx.node()
  2349     node = ctx.node()
  2353     mf = ctx.manifest()
  2350     mf = ctx.manifest()
  2354     if node == parent:
  2351     if node == parent:
  2355         pmf = mf
  2352         pmf = mf
  2356     else:
  2353     else:
  2464                     if exact: ui.warn(_('no changes needed to %s\n') % rel)
  2461                     if exact: ui.warn(_('no changes needed to %s\n') % rel)
  2465                     continue
  2462                     continue
  2466                 if pmf is None:
  2463                 if pmf is None:
  2467                     # only need parent manifest in this unlikely case,
  2464                     # only need parent manifest in this unlikely case,
  2468                     # so do not read by default
  2465                     # so do not read by default
  2469                     pmf = repo.changectx(parent).manifest()
  2466                     pmf = repo[parent].manifest()
  2470                 if abs in pmf:
  2467                 if abs in pmf:
  2471                     if mfentry:
  2468                     if mfentry:
  2472                         # if version of file is same in parent and target
  2469                         # if version of file is same in parent and target
  2473                         # manifests, do nothing
  2470                         # manifests, do nothing
  2474                         if (pmf[abs] != mfentry or
  2471                         if (pmf[abs] != mfentry or
  2666     stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
  2663     stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
  2667                        'ignored' in show, 'clean' in show, 'unknown' in show)
  2664                        'ignored' in show, 'clean' in show, 'unknown' in show)
  2668     changestates = zip(states, 'MAR!?IC', stat)
  2665     changestates = zip(states, 'MAR!?IC', stat)
  2669 
  2666 
  2670     if (opts['all'] or opts['copies']) and not opts['no_status']:
  2667     if (opts['all'] or opts['copies']) and not opts['no_status']:
  2671         ctxn = repo.changectx(nullid)
  2668         ctxn = repo[nullid]
  2672         ctx1 = repo.changectx(node1)
  2669         ctx1 = repo[node1]
  2673         ctx2 = repo.changectx(node2)
  2670         ctx2 = repo[node2]
  2674         added = stat[1]
  2671         added = stat[1]
  2675         if node2 is None:
  2672         if node2 is None:
  2676             added = stat[0] + stat[1] # merged?
  2673             added = stat[0] + stat[1] # merged?
  2677 
  2674 
  2678         for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].items():
  2675         for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].items():
  2742                 raise util.Abort(_('tag \'%s\' already exists '
  2739                 raise util.Abort(_('tag \'%s\' already exists '
  2743                                    '(use -f to force)') % n)
  2740                                    '(use -f to force)') % n)
  2744     if not rev_ and repo.dirstate.parents()[1] != nullid:
  2741     if not rev_ and repo.dirstate.parents()[1] != nullid:
  2745         raise util.Abort(_('uncommitted merge - please provide a '
  2742         raise util.Abort(_('uncommitted merge - please provide a '
  2746                            'specific revision'))
  2743                            'specific revision'))
  2747     r = repo.changectx(rev_).node()
  2744     r = repo[rev_].node()
  2748 
  2745 
  2749     if not message:
  2746     if not message:
  2750         message = (_('Added tag %s for changeset %s') %
  2747         message = (_('Added tag %s for changeset %s') %
  2751                    (', '.join(names), short(r)))
  2748                    (', '.join(names), short(r)))
  2752 
  2749