purge.py
changeset 2369 9da3dd62c827
parent 2364 f368a1c302d5
child 2370 de893ad6bd17
equal deleted inserted replaced
2368:eb1ec13e3b0d 2369:9da3dd62c827
    21 
    21 
    22 from mercurial import hg, util
    22 from mercurial import hg, util
    23 import os
    23 import os
    24 
    24 
    25 class Purge(object):
    25 class Purge(object):
    26     '''removes files not tracked by mercurial
       
    27 
       
    28     Delete files not known to mercurial, this is useful to test local and
       
    29     uncommitted changes in the otherwise clean source tree.
       
    30 
       
    31     This means that purge will delete:
       
    32      - Unknown files: files marked with "?" by "hg status"
       
    33      - Ignored files: files usually ignored by Mercurial because they match a
       
    34        pattern in a ".hgignore" file
       
    35      - Empty directories: infact Mercurial ignores directories unless they
       
    36        contain files under source control managment
       
    37     But it will leave untouched:
       
    38      - Unmodified tracked files
       
    39      - Modified tracked files
       
    40      - New files added to the repository (with "hg add")
       
    41 
       
    42     If names are given, only files matching the names are considered, else
       
    43     all files in the repository directory are considered.
       
    44 
       
    45     Be careful with purge, you could irreversibly delete some files you
       
    46     forgot to add to the repository. If you only want to print the list of
       
    47     files that this program would delete use the -vn options.
       
    48     '''
       
    49 
       
    50     def __init__(self, act=True, abort_on_err=False):
    26     def __init__(self, act=True, abort_on_err=False):
    51         self._repo = None
    27         self._repo = None
    52         self._ui = None
    28         self._ui = None
    53         self._hg_root = None
    29         self._hg_root = None
    54         self._act = act
    30         self._act = act
   133                 ret = os.path.join(ret, part)
   109                 ret = os.path.join(ret, part)
   134             else:
   110             else:
   135                 ret = part
   111                 ret = part
   136         return ret
   112         return ret
   137 
   113 
   138     def from_command(ui, repo, *paths, **opts):
       
   139         act = True
       
   140         if opts['nothing']:
       
   141             act = False
       
   142 
   114 
   143         abort_on_err = True
   115 def purge(ui, repo, *paths, **opts):
   144         if not opts['abort_on_err']:
   116     '''removes files not tracked by mercurial
   145             abort_on_err = False
       
   146 
   117 
   147         p = Purge(act, abort_on_err)
   118     Delete files not known to mercurial, this is useful to test local and
   148         p.purge(ui, repo, paths)
   119     uncommitted changes in the otherwise clean source tree.
   149 
   120 
   150     # The docstring of from_command() is used by hg to print the help
   121     This means that purge will delete:
   151     # of the command.
   122      - Unknown files: files marked with "?" by "hg status"
   152     from_command.__doc__ = __doc__
   123      - Ignored files: files usually ignored by Mercurial because they match a
   153     from_command = staticmethod(from_command)
   124        pattern in a ".hgignore" file
       
   125      - Empty directories: infact Mercurial ignores directories unless they
       
   126        contain files under source control managment
       
   127     But it will leave untouched:
       
   128      - Unmodified tracked files
       
   129      - Modified tracked files
       
   130      - New files added to the repository (with "hg add")
       
   131 
       
   132     If names are given, only files matching the names are considered, else
       
   133     all files in the repository directory are considered.
       
   134 
       
   135     Be careful with purge, you could irreversibly delete some files you
       
   136     forgot to add to the repository. If you only want to print the list of
       
   137     files that this program would delete use the -vn options.
       
   138     '''
       
   139     act = True
       
   140     if opts['nothing']:
       
   141         act = False
       
   142 
       
   143     abort_on_err = True
       
   144     if not opts['abort_on_err']:
       
   145         abort_on_err = False
       
   146 
       
   147     p = Purge(act, abort_on_err)
       
   148     p.purge(ui, repo, paths)
   154 
   149 
   155 
   150 
   156 cmdtable = {
   151 cmdtable = {
   157     'purge':    (Purge.from_command,
   152     'purge':    (purge,
   158                  [('a', 'abort-on-err', None, 'abort if an error occurs'),
   153                  [('a', 'abort-on-err', None, 'abort if an error occurs'),
   159                   ('n', 'nothing',      None, 'do nothing on files, useful with --verbose'),
   154                   ('n', 'nothing',      None, 'do nothing on files, useful with --verbose'),
   160                  ],
   155                  ],
   161                  'hg purge [OPTIONS] [NAME]')
   156                  'hg purge [OPTIONS] [NAME]')
   162 }
   157 }