mercurial/commands.py
changeset 1456 214f42f23a3b
parent 1455 407bd229f003
child 1469 0847c45ffee6
equal deleted inserted replaced
1455:407bd229f003 1456:214f42f23a3b
   786     elif len(pats) == 1:
   786     elif len(pats) == 1:
   787         raise util.Abort(_('no destination specified'))
   787         raise util.Abort(_('no destination specified'))
   788     pats = list(pats)
   788     pats = list(pats)
   789     dest = pats.pop()
   789     dest = pats.pop()
   790     sources = []
   790     sources = []
   791     dir2dir = not opts['parents'] and len(pats) == 1 and os.path.isdir(pats[0])
   791     dir2dir = len(pats) == 1 and os.path.isdir(pats[0])
   792 
   792 
   793     def okaytocopy(abs, rel, exact):
   793     def okaytocopy(abs, rel, exact):
   794         reasons = {'?': _('is not managed'),
   794         reasons = {'?': _('is not managed'),
   795                    'a': _('has been marked for add')}
   795                    'a': _('has been marked for add')}
   796         reason = reasons.get(repo.dirstate.state(abs))
   796         reason = reasons.get(repo.dirstate.state(abs))
   812         destisfile = not os.path.isdir(reldest)
   812         destisfile = not os.path.isdir(reldest)
   813     else:
   813     else:
   814         destisfile = not dir2dir and (len(sources) == 1
   814         destisfile = not dir2dir and (len(sources) == 1
   815                                       or repo.dirstate.state(absdest) != '?')
   815                                       or repo.dirstate.state(absdest) != '?')
   816 
   816 
   817     if destisfile:
   817     if destisfile and len(sources) > 1:
   818         if opts['parents']:
   818         raise util.Abort(_('with multiple sources, destination must be a '
   819             raise util.Abort(_('with --parents, destination must be a directory'))
   819                            'directory'))
   820         elif len(sources) > 1:
   820 
   821             raise util.Abort(_('with multiple sources, destination must be a '
       
   822                                'directory'))
       
   823     srcpfxlen = 0
   821     srcpfxlen = 0
   824     if dir2dir:
   822     if dir2dir:
   825         srcpfx = util.pathto(cwd, util.canonpath(repo.root, cwd, pats[0]))
   823         srcpfx = util.pathto(cwd, util.canonpath(repo.root, cwd, pats[0]))
   826         if os.path.exists(reldest):
   824         if os.path.exists(reldest):
   827             srcpfx = os.path.split(srcpfx)[0]
   825             srcpfx = os.path.split(srcpfx)[0]
   829             srcpfx += os.sep
   827             srcpfx += os.sep
   830         srcpfxlen = len(srcpfx)
   828         srcpfxlen = len(srcpfx)
   831 
   829 
   832     errs, copied = 0, []
   830     errs, copied = 0, []
   833     for abs, rel, exact in sources:
   831     for abs, rel, exact in sources:
   834         if opts['parents']:
   832         if destisfile:
   835             mydest = os.path.join(dest, rel)
       
   836         elif destisfile:
       
   837             mydest = reldest
   833             mydest = reldest
   838         elif dir2dir:
   834         elif dir2dir:
   839             mydest = os.path.join(dest, rel[srcpfxlen:])
   835             mydest = os.path.join(dest, rel[srcpfxlen:])
   840         else:
   836         else:
   841             mydest = os.path.join(dest, os.path.basename(rel))
   837             mydest = os.path.join(dest, os.path.basename(rel))
   845             ui.warn(_('%s: not overwriting - file already managed\n') % myreldest)
   841             ui.warn(_('%s: not overwriting - file already managed\n') % myreldest)
   846             continue
   842             continue
   847         mydestdir = os.path.dirname(myreldest) or '.'
   843         mydestdir = os.path.dirname(myreldest) or '.'
   848         if not opts['after']:
   844         if not opts['after']:
   849             try:
   845             try:
   850                 if opts['parents'] or dir2dir: os.makedirs(mydestdir)
   846                 if dir2dir: os.makedirs(mydestdir)
   851                 elif not destisfile: os.mkdir(mydestdir)
   847                 elif not destisfile: os.mkdir(mydestdir)
   852             except OSError, inst:
   848             except OSError, inst:
   853                 if inst.errno != errno.EEXIST: raise
   849                 if inst.errno != errno.EEXIST: raise
   854         if ui.verbose or not exact:
   850         if ui.verbose or not exact:
   855             ui.status(_('copying %s to %s\n') % (rel, myreldest))
   851             ui.status(_('copying %s to %s\n') % (rel, myreldest))
  2211          _('hg commit [OPTION]... [FILE]...')),
  2207          _('hg commit [OPTION]... [FILE]...')),
  2212     "copy|cp": (copy,
  2208     "copy|cp": (copy,
  2213              [('I', 'include', [], _('include names matching the given patterns')),
  2209              [('I', 'include', [], _('include names matching the given patterns')),
  2214               ('X', 'exclude', [], _('exclude names matching the given patterns')),
  2210               ('X', 'exclude', [], _('exclude names matching the given patterns')),
  2215               ('A', 'after', None, _('record a copy that has already occurred')),
  2211               ('A', 'after', None, _('record a copy that has already occurred')),
  2216               ('f', 'force', None, _('forcibly copy over an existing managed file')),
  2212               ('f', 'force', None, _('forcibly copy over an existing managed file'))],
  2217               ('p', 'parents', None, _('append source path to dest'))],
       
  2218              _('hg copy [OPTION]... [SOURCE]... DEST')),
  2213              _('hg copy [OPTION]... [SOURCE]... DEST')),
  2219     "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
  2214     "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
  2220     "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
  2215     "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
  2221     "debugconfig": (debugconfig, [], _('debugconfig')),
  2216     "debugconfig": (debugconfig, [], _('debugconfig')),
  2222     "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
  2217     "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
  2334                    _("hg remove [OPTION]... FILE...")),
  2329                    _("hg remove [OPTION]... FILE...")),
  2335     "rename|mv": (rename,
  2330     "rename|mv": (rename,
  2336                   [('I', 'include', [], _('include names matching the given patterns')),
  2331                   [('I', 'include', [], _('include names matching the given patterns')),
  2337                    ('X', 'exclude', [], _('exclude names matching the given patterns')),
  2332                    ('X', 'exclude', [], _('exclude names matching the given patterns')),
  2338                    ('A', 'after', None, _('record a rename that has already occurred')),
  2333                    ('A', 'after', None, _('record a rename that has already occurred')),
  2339                    ('f', 'force', None, _('forcibly copy over an existing managed file')),
  2334                    ('f', 'force', None, _('forcibly copy over an existing managed file'))],
  2340                    ('p', 'parents', None, _('append source path to dest'))],
       
  2341                   _('hg rename [OPTION]... [SOURCE]... DEST')),
  2335                   _('hg rename [OPTION]... [SOURCE]... DEST')),
  2342     "^revert":
  2336     "^revert":
  2343         (revert,
  2337         (revert,
  2344          [("n", "nonrecursive", None, _("do not recurse into subdirectories")),
  2338          [("n", "nonrecursive", None, _("do not recurse into subdirectories")),
  2345           ("r", "rev", "", _("revision to revert to"))],
  2339           ("r", "rev", "", _("revision to revert to"))],