mercurial/commands.py
changeset 2112 2b03c6733efa
parent 2092 1d3c6e63d703
child 2122 9383ba6b069a
equal deleted inserted replaced
2110:25a8d116ab6a 2112:2b03c6733efa
    10 from i18n import gettext as _
    10 from i18n import gettext as _
    11 demandload(globals(), "os re sys signal shutil imp urllib pdb")
    11 demandload(globals(), "os re sys signal shutil imp urllib pdb")
    12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
    12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
    13 demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time")
    13 demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time")
    14 demandload(globals(), "traceback errno socket version struct atexit sets bz2")
    14 demandload(globals(), "traceback errno socket version struct atexit sets bz2")
    15 demandload(globals(), "changegroup")
    15 demandload(globals(), "archival changegroup")
    16 
    16 
    17 class UnknownCommand(Exception):
    17 class UnknownCommand(Exception):
    18     """Exception raised if command is not in the command table."""
    18     """Exception raised if command is not in the command table."""
    19 class AmbiguousCommand(Exception):
    19 class AmbiguousCommand(Exception):
    20     """Exception raised if command shortcut matches more than one command."""
    20     """Exception raised if command shortcut matches more than one command."""
   887                     pieces.append(["%*s" % (m, x) for x in l])
   887                     pieces.append(["%*s" % (m, x) for x in l])
   888 
   888 
   889         if pieces:
   889         if pieces:
   890             for p, l in zip(zip(*pieces), lines):
   890             for p, l in zip(zip(*pieces), lines):
   891                 ui.write("%s: %s" % (" ".join(p), l[1]))
   891                 ui.write("%s: %s" % (" ".join(p), l[1]))
       
   892 
       
   893 def archive(ui, repo, dest, **opts):
       
   894     '''create unversioned archive of a repository revision
       
   895 
       
   896     By default, the revision used is the parent of the working
       
   897     directory; use "-r" to specify a different revision.
       
   898 
       
   899     To specify the type of archive to create, use "-t".  Valid
       
   900     types are:
       
   901 
       
   902     "files" (default): a directory full of files
       
   903     "tar": tar archive, uncompressed
       
   904     "tbz2": tar archive, compressed using bzip2
       
   905     "tgz": tar archive, compressed using gzip
       
   906     "uzip": zip archive, uncompressed
       
   907     "zip": zip archive, compressed using deflate
       
   908 
       
   909     The exact name of the destination archive or directory is given
       
   910     using a format string; see "hg help export" for details.
       
   911 
       
   912     Each member added to an archive file has a directory prefix
       
   913     prepended.  Use "-p" to specify a format string for the prefix.
       
   914     The default is the basename of the archive, with suffixes removed.
       
   915     '''
       
   916 
       
   917     if opts['rev']:
       
   918         node = repo.lookup(opts['rev'])
       
   919     else:
       
   920         node, p2 = repo.dirstate.parents()
       
   921         if p2 != nullid:
       
   922             raise util.Abort(_('uncommitted merge - please provide a '
       
   923                                'specific revision'))
       
   924 
       
   925     dest = make_filename(repo, repo.changelog, dest, node)
       
   926     prefix = make_filename(repo, repo.changelog, opts['prefix'], node)
       
   927     if os.path.realpath(dest) == repo.root:
       
   928         raise util.Abort(_('repository root cannot be destination'))
       
   929     _, matchfn, _ = matchpats(repo, [], opts)
       
   930     archival.archive(repo, dest, node, opts.get('type') or 'files',
       
   931                     not opts['no_decode'], matchfn, prefix)
   892 
   932 
   893 def bundle(ui, repo, fname, dest="default-push", **opts):
   933 def bundle(ui, repo, fname, dest="default-push", **opts):
   894     """create a changegroup file
   934     """create a changegroup file
   895 
   935 
   896     Generate a compressed changegroup file collecting all changesets
   936     Generate a compressed changegroup file collecting all changesets
  2837           ('n', 'number', None, _('list the revision number (default)')),
  2877           ('n', 'number', None, _('list the revision number (default)')),
  2838           ('c', 'changeset', None, _('list the changeset')),
  2878           ('c', 'changeset', None, _('list the changeset')),
  2839           ('I', 'include', [], _('include names matching the given patterns')),
  2879           ('I', 'include', [], _('include names matching the given patterns')),
  2840           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2880           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
  2841          _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
  2881          _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
       
  2882     'archive':
       
  2883         (archive,
       
  2884          [('', 'no-decode', None, _('do not pass files through decoders')),
       
  2885           ('p', 'prefix', '', _('directory prefix for files in archive')),
       
  2886           ('r', 'rev', '', _('revision to distribute')),
       
  2887           ('t', 'type', '', _('type of distribution to create')),
       
  2888           ('I', 'include', [], _('include names matching the given patterns')),
       
  2889           ('X', 'exclude', [], _('exclude names matching the given patterns'))],
       
  2890          _('hg archive [OPTION]... DEST')),
  2842     "bundle":
  2891     "bundle":
  2843         (bundle,
  2892         (bundle,
  2844          [('f', 'force', None,
  2893          [('f', 'force', None,
  2845            _('run even when remote repository is unrelated'))],
  2894            _('run even when remote repository is unrelated'))],
  2846          _('hg bundle FILE DEST')),
  2895          _('hg bundle FILE DEST')),
  3247         del cmdoptions[n]
  3296         del cmdoptions[n]
  3248 
  3297 
  3249     return (cmd, cmd and i[0] or None, args, options, cmdoptions)
  3298     return (cmd, cmd and i[0] or None, args, options, cmdoptions)
  3250 
  3299 
  3251 def dispatch(args):
  3300 def dispatch(args):
  3252     for name in 'SIGTERM', 'SIGHUP', 'SIGBREAK':
  3301     for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
  3253         num = getattr(signal, name, None)
  3302         num = getattr(signal, name, None)
  3254         if num: signal.signal(num, catchterm)
  3303         if num: signal.signal(num, catchterm)
  3255 
  3304 
  3256     try:
  3305     try:
  3257         u = ui.ui()
  3306         u = ui.ui()