mercurial/commands.py
changeset 6740 b148e9099133
parent 6739 c9fbd6ec3489
child 6743 86e8187b721a
equal deleted inserted replaced
6739:c9fbd6ec3489 6740:b148e9099133
   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.workingctx().parents()]:
   362             if label not in [p.branch() for p in repo.changectx(None).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:
  1452         if num or branch or tags:
  1452         if num or branch or tags:
  1453             raise util.Abort(
  1453             raise util.Abort(
  1454                 "can't query remote revision number, branch, or tags")
  1454                 "can't query remote revision number, branch, or tags")
  1455         output = [hexfunc(srepo.lookup(rev))]
  1455         output = [hexfunc(srepo.lookup(rev))]
  1456     elif not rev:
  1456     elif not rev:
  1457         ctx = repo.workingctx()
  1457         ctx = repo.changectx(None)
  1458         parents = ctx.parents()
  1458         parents = ctx.parents()
  1459         changed = False
  1459         changed = False
  1460         if default or id or num:
  1460         if default or id or num:
  1461             changed = ctx.files() + ctx.deleted()
  1461             changed = ctx.files() + ctx.deleted()
  1462         if default or id:
  1462         if default or id:
  1561                 else:
  1561                 else:
  1562                     # launch the editor
  1562                     # launch the editor
  1563                     message = None
  1563                     message = None
  1564                 ui.debug(_('message:\n%s\n') % message)
  1564                 ui.debug(_('message:\n%s\n') % message)
  1565 
  1565 
  1566                 wp = repo.workingctx().parents()
  1566                 wp = repo.changectx(None).parents()
  1567                 if opts.get('exact'):
  1567                 if opts.get('exact'):
  1568                     if not nodeid or not p1:
  1568                     if not nodeid or not p1:
  1569                         raise util.Abort(_('not a mercurial patch'))
  1569                         raise util.Abort(_('not a mercurial patch'))
  1570                     p1 = repo.lookup(p1)
  1570                     p1 = repo.lookup(p1)
  1571                     p2 = repo.lookup(p2 or hex(nullid))
  1571                     p2 = repo.lookup(p2 or hex(nullid))
  1900         raise util.Abort(_("please specify just one revision"))
  1900         raise util.Abort(_("please specify just one revision"))
  1901     if not node:
  1901     if not node:
  1902         node = rev
  1902         node = rev
  1903 
  1903 
  1904     if not node:
  1904     if not node:
  1905         branch = repo.workingctx().branch()
  1905         branch = repo.changectx(None).branch()
  1906         bheads = repo.branchheads()
  1906         bheads = repo.branchheads()
  1907         if len(bheads) > 2:
  1907         if len(bheads) > 2:
  1908             raise util.Abort(_("branch '%s' has %d heads - "
  1908             raise util.Abort(_("branch '%s' has %d heads - "
  1909                                "please merge with an explicit rev") %
  1909                                "please merge with an explicit rev") %
  1910                              (branch, len(bheads)))
  1910                              (branch, len(bheads)))
  1914             if len(repo.heads()) > 1:
  1914             if len(repo.heads()) > 1:
  1915                 raise util.Abort(_("branch '%s' has one head - "
  1915                 raise util.Abort(_("branch '%s' has one head - "
  1916                                    "please merge with an explicit rev") %
  1916                                    "please merge with an explicit rev") %
  1917                                  branch)
  1917                                  branch)
  1918             msg = _('there is nothing to merge')
  1918             msg = _('there is nothing to merge')
  1919             if parent != repo.lookup(repo.workingctx().branch()):
  1919             if parent != repo.lookup(repo.changectx(None).branch()):
  1920                 msg = _('%s - use "hg update" instead') % msg
  1920                 msg = _('%s - use "hg update" instead') % msg
  1921             raise util.Abort(msg)
  1921             raise util.Abort(msg)
  1922 
  1922 
  1923         if parent not in bheads:
  1923         if parent not in bheads:
  1924             raise util.Abort(_('working dir not at a head rev - '
  1924             raise util.Abort(_('working dir not at a head rev - '
  1973     """
  1973     """
  1974     rev = opts.get('rev')
  1974     rev = opts.get('rev')
  1975     if rev:
  1975     if rev:
  1976         ctx = repo.changectx(rev)
  1976         ctx = repo.changectx(rev)
  1977     else:
  1977     else:
  1978         ctx = repo.workingctx()
  1978         ctx = repo.changectx(None)
  1979 
  1979 
  1980     if file_:
  1980     if file_:
  1981         m = cmdutil.match(repo, (file_,), opts)
  1981         m = cmdutil.match(repo, (file_,), opts)
  1982         if m.anypats() or len(m.files()) != 1:
  1982         if m.anypats() or len(m.files()) != 1:
  1983             raise util.Abort(_('can only specify an explicit file name'))
  1983             raise util.Abort(_('can only specify an explicit file name'))
  2295             elif opts.get("mark"):
  2295             elif opts.get("mark"):
  2296                 ms.mark(f, "r")
  2296                 ms.mark(f, "r")
  2297             elif opts.get("unmark"):
  2297             elif opts.get("unmark"):
  2298                 ms.mark(f, "u")
  2298                 ms.mark(f, "u")
  2299             else:
  2299             else:
  2300                 wctx = repo.workingctx()
  2300                 wctx = repo.changectx(None)
  2301                 mctx = wctx.parents()[-1]
  2301                 mctx = wctx.parents()[-1]
  2302                 ms.resolve(f, wctx, mctx)
  2302                 ms.resolve(f, wctx, mctx)
  2303 
  2303 
  2304 def revert(ui, repo, *pats, **opts):
  2304 def revert(ui, repo, *pats, **opts):
  2305     """restore individual files or dirs to an earlier state
  2305     """restore individual files or dirs to an earlier state
  2668     changestates = zip(states, 'MAR!?IC', stat)
  2668     changestates = zip(states, 'MAR!?IC', stat)
  2669 
  2669 
  2670     if (opts['all'] or opts['copies']) and not opts['no_status']:
  2670     if (opts['all'] or opts['copies']) and not opts['no_status']:
  2671         ctxn = repo.changectx(nullid)
  2671         ctxn = repo.changectx(nullid)
  2672         ctx1 = repo.changectx(node1)
  2672         ctx1 = repo.changectx(node1)
       
  2673         ctx2 = repo.changectx(node2)
  2673         added = stat[1]
  2674         added = stat[1]
  2674         if node2 is None:
  2675         if node2 is None:
  2675             added = stat[0] + stat[1] # merged?
  2676             added = stat[0] + stat[1] # merged?
  2676             ctx2 = repo.workingctx()
  2677 
  2677         else:
       
  2678             ctx2 = repo.changectx(node2)
       
  2679         for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].items():
  2678         for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].items():
  2680             if k in added:
  2679             if k in added:
  2681                 copy[k] = v
  2680                 copy[k] = v
  2682             elif v in added:
  2681             elif v in added:
  2683                 copy[v] = k
  2682                 copy[v] = k