mercurial/commands.py
changeset 4906 30847b8af7ca
parent 4904 6fd953d5faea
child 4914 9a2a73ea6135
equal deleted inserted replaced
4905:fc61495ea9cf 4906:30847b8af7ca
    31     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
    31     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
    32         if exact:
    32         if exact:
    33             if ui.verbose:
    33             if ui.verbose:
    34                 ui.status(_('adding %s\n') % rel)
    34                 ui.status(_('adding %s\n') % rel)
    35             names.append(abs)
    35             names.append(abs)
    36         elif repo.dirstate.state(abs) == '?':
    36         elif abs not in repo.dirstate:
    37             ui.status(_('adding %s\n') % rel)
    37             ui.status(_('adding %s\n') % rel)
    38             names.append(abs)
    38             names.append(abs)
    39     if not opts.get('dry_run'):
    39     if not opts.get('dry_run'):
    40         repo.add(names)
    40         repo.add(names)
    41 
    41 
   454                         raise util.Abort(_("no match under directory %s!")
   454                         raise util.Abort(_("no match under directory %s!")
   455                                          % rf)
   455                                          % rf)
   456                 elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)):
   456                 elif not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)):
   457                     raise util.Abort(_("can't commit %s: "
   457                     raise util.Abort(_("can't commit %s: "
   458                                        "unsupported file type!") % rf)
   458                                        "unsupported file type!") % rf)
   459                 elif repo.dirstate.state(f) == '?':
   459                 elif f not in repo.dirstate:
   460                     raise util.Abort(_("file %s not tracked!") % rf)
   460                     raise util.Abort(_("file %s not tracked!") % rf)
   461     else:
   461     else:
   462         files = []
   462         files = []
   463     try:
   463     try:
   464         repo.commit(files, message, opts['user'], opts['date'], match,
   464         repo.commit(files, message, opts['user'], opts['date'], match,
   480     # rel: ossep
   480     # rel: ossep
   481     # return: hgsep
   481     # return: hgsep
   482     def okaytocopy(abs, rel, exact):
   482     def okaytocopy(abs, rel, exact):
   483         reasons = {'?': _('is not managed'),
   483         reasons = {'?': _('is not managed'),
   484                    'r': _('has been marked for remove')}
   484                    'r': _('has been marked for remove')}
   485         state = repo.dirstate.state(abs)
   485         state = repo.dirstate[abs]
   486         reason = reasons.get(state)
   486         reason = reasons.get(state)
   487         if reason:
   487         if reason:
   488             if exact:
   488             if exact:
   489                 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
   489                 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
   490         else:
   490         else:
   508             ui.warn(_('%s: not overwriting - %s collides with %s\n') %
   508             ui.warn(_('%s: not overwriting - %s collides with %s\n') %
   509                     (reltarget, repo.pathto(abssrc, cwd),
   509                     (reltarget, repo.pathto(abssrc, cwd),
   510                      repo.pathto(prevsrc, cwd)))
   510                      repo.pathto(prevsrc, cwd)))
   511             return
   511             return
   512         if (not opts['after'] and os.path.exists(target) or
   512         if (not opts['after'] and os.path.exists(target) or
   513             opts['after'] and repo.dirstate.state(abstarget) not in '?ar'):
   513             opts['after'] and repo.dirstate[abstarget] in 'mn'):
   514             if not opts['force']:
   514             if not opts['force']:
   515                 ui.warn(_('%s: not overwriting - file exists\n') %
   515                 ui.warn(_('%s: not overwriting - file exists\n') %
   516                         reltarget)
   516                         reltarget)
   517                 return
   517                 return
   518             if not opts['after'] and not opts.get('dry_run'):
   518             if not opts['after'] and not opts.get('dry_run'):
   523         else:
   523         else:
   524             targetdir = os.path.dirname(target) or '.'
   524             targetdir = os.path.dirname(target) or '.'
   525             if not os.path.isdir(targetdir) and not opts.get('dry_run'):
   525             if not os.path.isdir(targetdir) and not opts.get('dry_run'):
   526                 os.makedirs(targetdir)
   526                 os.makedirs(targetdir)
   527             try:
   527             try:
   528                 restore = repo.dirstate.state(abstarget) == 'r'
   528                 restore = repo.dirstate[abstarget] == 'r'
   529                 if restore and not opts.get('dry_run'):
   529                 if restore and not opts.get('dry_run'):
   530                     repo.undelete([abstarget], wlock)
   530                     repo.undelete([abstarget], wlock)
   531                 try:
   531                 try:
   532                     if not opts.get('dry_run'):
   532                     if not opts.get('dry_run'):
   533                         util.copyfile(src, target)
   533                         util.copyfile(src, target)
   545                     return
   545                     return
   546         if ui.verbose or not exact:
   546         if ui.verbose or not exact:
   547             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
   547             ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
   548         targets[abstarget] = abssrc
   548         targets[abstarget] = abssrc
   549         if abstarget != origsrc:
   549         if abstarget != origsrc:
   550             if repo.dirstate.state(origsrc) == 'a':
   550             if repo.dirstate[origsrc] == 'a':
   551                 if not ui.quiet:
   551                 if not ui.quiet:
   552                     ui.warn(_("%s has not been committed yet, so no copy "
   552                     ui.warn(_("%s has not been committed yet, so no copy "
   553                               "data will be stored for %s.\n")
   553                               "data will be stored for %s.\n")
   554                             % (repo.pathto(origsrc, cwd), reltarget))
   554                             % (repo.pathto(origsrc, cwd), reltarget))
   555                 if abstarget not in repo.dirstate and not opts.get('dry_run'):
   555                 if abstarget not in repo.dirstate and not opts.get('dry_run'):
   716     repo.dirstate.rebuild(rev, files)
   716     repo.dirstate.rebuild(rev, files)
   717 
   717 
   718 def debugcheckstate(ui, repo):
   718 def debugcheckstate(ui, repo):
   719     """validate the correctness of the current dirstate"""
   719     """validate the correctness of the current dirstate"""
   720     parent1, parent2 = repo.dirstate.parents()
   720     parent1, parent2 = repo.dirstate.parents()
   721     dc = repo.dirstate
       
   722     m1 = repo.changectx(parent1).manifest()
   721     m1 = repo.changectx(parent1).manifest()
   723     m2 = repo.changectx(parent2).manifest()
   722     m2 = repo.changectx(parent2).manifest()
   724     errors = 0
   723     errors = 0
   725     for f in dc:
   724     for f in repo.dirstate:
   726         state = repo.dirstate.state(f)
   725         state = repo.dirstate[f]
   727         if state in "nr" and f not in m1:
   726         if state in "nr" and f not in m1:
   728             ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
   727             ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
   729             errors += 1
   728             errors += 1
   730         if state in "a" and f in m1:
   729         if state in "a" and f in m1:
   731             ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
   730             ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
   733         if state in "m" and f not in m1 and f not in m2:
   732         if state in "m" and f not in m1 and f not in m2:
   734             ui.warn(_("%s in state %s, but not in either manifest\n") %
   733             ui.warn(_("%s in state %s, but not in either manifest\n") %
   735                     (f, state))
   734                     (f, state))
   736             errors += 1
   735             errors += 1
   737     for f in m1:
   736     for f in m1:
   738         state = repo.dirstate.state(f)
   737         state = repo.dirstate[f]
   739         if state not in "nrm":
   738         if state not in "nrm":
   740             ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
   739             ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
   741             errors += 1
   740             errors += 1
   742     if errors:
   741     if errors:
   743         error = _(".hg/dirstate inconsistent with current parent's manifest")
   742         error = _(".hg/dirstate inconsistent with current parent's manifest")
   785     finally:
   784     finally:
   786         wlock.release()
   785         wlock.release()
   787 
   786 
   788 def debugstate(ui, repo):
   787 def debugstate(ui, repo):
   789     """show the contents of the current dirstate"""
   788     """show the contents of the current dirstate"""
   790     dc = repo.dirstate
   789     dc = repo.dirstate._map
   791     for file_ in dc:
   790     k = dc.keys()
       
   791     k.sort()
       
   792     for file_ in k:
   792         if dc[file_][3] == -1:
   793         if dc[file_][3] == -1:
   793             # Pad or slice to locale representation
   794             # Pad or slice to locale representation
   794             locale_len = len(time.strftime("%x %X", time.localtime(0)))
   795             locale_len = len(time.strftime("%x %X", time.localtime(0)))
   795             timestr = 'unset'
   796             timestr = 'unset'
   796             timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr))
   797             timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr))
  1756     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
  1757     for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
  1757                                              badmatch=util.always,
  1758                                              badmatch=util.always,
  1758                                              default='relglob'):
  1759                                              default='relglob'):
  1759         if src == 'b':
  1760         if src == 'b':
  1760             continue
  1761             continue
  1761         if not node and repo.dirstate.state(abs) == '?':
  1762         if not node and abs not in repo.dirstate:
  1762             continue
  1763             continue
  1763         if opts['fullpath']:
  1764         if opts['fullpath']:
  1764             ui.write(os.path.join(repo.root, abs), end)
  1765             ui.write(os.path.join(repo.root, abs), end)
  1765         else:
  1766         else:
  1766             ui.write(((pats and rel) or abs), end)
  1767             ui.write(((pats and rel) or abs), end)
  2214         elif abs in added:
  2215         elif abs in added:
  2215             if opts['force']:
  2216             if opts['force']:
  2216                 forget.append(abs)
  2217                 forget.append(abs)
  2217                 continue
  2218                 continue
  2218             reason = _('has been marked for add (use -f to force removal)')
  2219             reason = _('has been marked for add (use -f to force removal)')
  2219         elif repo.dirstate.state(abs) == '?':
  2220         elif abs not in repo.dirstate:
  2220             reason = _('is not managed')
  2221             reason = _('is not managed')
  2221         elif opts['after'] and not exact and abs not in deleted:
  2222         elif opts['after'] and not exact and abs not in deleted:
  2222             continue
  2223             continue
  2223         elif abs in removed:
  2224         elif abs in removed:
  2224             continue
  2225             continue