mercurial/commands.py
changeset 1218 cde6818e082a
parent 1215 8b4435aae40a
child 1220 8baa29e36b14
equal deleted inserted replaced
1217:f1895785c79e 1218:cde6818e082a
     5 # This software may be used and distributed according to the terms
     5 # This software may be used and distributed according to the terms
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 from demandload import demandload
     8 from demandload import demandload
     9 from node import *
     9 from node import *
    10 demandload(globals(), "os re sys signal shutil imp")
    10 demandload(globals(), "os re sys signal shutil imp urllib")
    11 demandload(globals(), "fancyopts ui hg util lock revlog")
    11 demandload(globals(), "fancyopts ui hg util lock revlog")
    12 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
    12 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
    13 demandload(globals(), "errno socket version struct atexit sets")
    13 demandload(globals(), "errno socket version struct atexit sets bz2")
    14 
    14 
    15 class UnknownCommand(Exception):
    15 class UnknownCommand(Exception):
    16     """Exception raised if command is not in the command table."""
    16     """Exception raised if command is not in the command table."""
    17 
    17 
    18 def filterfiles(filters, files):
    18 def filterfiles(filters, files):
   547 
   547 
   548         if pieces:
   548         if pieces:
   549             for p, l in zip(zip(*pieces), lines):
   549             for p, l in zip(zip(*pieces), lines):
   550                 ui.write("%s: %s" % (" ".join(p), l[1]))
   550                 ui.write("%s: %s" % (" ".join(p), l[1]))
   551 
   551 
       
   552 def bundle(ui, repo, fname, dest="default-push", **opts):
       
   553     """create a changegroup file"""
       
   554     f = open(fname, "wb")
       
   555     dest = ui.expandpath(dest)
       
   556     other = hg.repository(ui, dest)
       
   557     o = repo.findoutgoing(other)
       
   558     cg = repo.changegroup(o)
       
   559 
       
   560     try:
       
   561         f.write("HG10")
       
   562         z = bz2.BZ2Compressor(9)
       
   563         while 1:
       
   564             chunk = cg.read(4096)
       
   565             if not chunk:
       
   566                 break
       
   567             f.write(z.compress(chunk))
       
   568         f.write(z.flush())
       
   569     except:
       
   570         os.unlink(fname)
       
   571 
   552 def cat(ui, repo, file1, rev=None, **opts):
   572 def cat(ui, repo, file1, rev=None, **opts):
   553     """output the latest or given revision of a file"""
   573     """output the latest or given revision of a file"""
   554     r = repo.file(relpath(repo, [file1])[0])
   574     r = repo.file(relpath(repo, [file1])[0])
   555     if rev:
   575     if rev:
   556         try:
   576         try:
  1532 def tip(ui, repo):
  1552 def tip(ui, repo):
  1533     """show the tip revision"""
  1553     """show the tip revision"""
  1534     n = repo.changelog.tip()
  1554     n = repo.changelog.tip()
  1535     show_changeset(ui, repo, changenode=n)
  1555     show_changeset(ui, repo, changenode=n)
  1536 
  1556 
       
  1557 def unbundle(ui, repo, fname):
       
  1558     f = urllib.urlopen(fname)
       
  1559 
       
  1560     if f.read(4) != "HG10":
       
  1561         ui.warn("abort: not a Mercurial bundle file!\n")
       
  1562         return -1
       
  1563 
       
  1564     class bzread:
       
  1565         def __init__(self, f):
       
  1566             self.zd = bz2.BZ2Decompressor()
       
  1567             self.f = f
       
  1568             self.buf = ""
       
  1569         def read(self, l):
       
  1570             while l > len(self.buf):
       
  1571                 r = self.f.read(4096)
       
  1572                 if r:
       
  1573                     self.buf += self.zd.decompress(r)
       
  1574                 else:
       
  1575                     break
       
  1576             d, self.buf = self.buf[:l], self.buf[l:]
       
  1577             return d
       
  1578 
       
  1579     repo.addchangegroup(bzread(f))
       
  1580 
  1537 def undo(ui, repo):
  1581 def undo(ui, repo):
  1538     """undo the last commit or pull
  1582     """undo the last commit or pull
  1539 
  1583 
  1540     Roll back the last pull or commit transaction on the
  1584     Roll back the last pull or commit transaction on the
  1541     repository, restoring the project to its earlier state.
  1585     repository, restoring the project to its earlier state.
  1608           ('n', 'number', None, 'show revision number'),
  1652           ('n', 'number', None, 'show revision number'),
  1609           ('c', 'changeset', None, 'show changeset'),
  1653           ('c', 'changeset', None, 'show changeset'),
  1610           ('I', 'include', [], 'include path in search'),
  1654           ('I', 'include', [], 'include path in search'),
  1611           ('X', 'exclude', [], 'exclude path from search')],
  1655           ('X', 'exclude', [], 'exclude path from search')],
  1612          'hg annotate [OPTION]... FILE...'),
  1656          'hg annotate [OPTION]... FILE...'),
       
  1657     "bundle":
       
  1658         (bundle,
       
  1659          [],
       
  1660          'hg bundle FILE DEST'),
  1613     "cat":
  1661     "cat":
  1614         (cat,
  1662         (cat,
  1615          [('o', 'output', "", 'output to file')],
  1663          [('o', 'output', "", 'output to file')],
  1616          'hg cat [-o OUTFILE] FILE [REV]'),
  1664          'hg cat [-o OUTFILE] FILE [REV]'),
  1617     "^clone":
  1665     "^clone":
  1774           ('d', 'date', "", 'date code'),
  1822           ('d', 'date', "", 'date code'),
  1775           ('u', 'user', "", 'user')],
  1823           ('u', 'user', "", 'user')],
  1776          'hg tag [OPTION]... NAME [REV]'),
  1824          'hg tag [OPTION]... NAME [REV]'),
  1777     "tags": (tags, [], 'hg tags'),
  1825     "tags": (tags, [], 'hg tags'),
  1778     "tip": (tip, [], 'hg tip'),
  1826     "tip": (tip, [], 'hg tip'),
       
  1827     "unbundle":
       
  1828         (unbundle,
       
  1829          [],
       
  1830          'hg unbundle FILE'),
  1779     "undo": (undo, [], 'hg undo'),
  1831     "undo": (undo, [], 'hg undo'),
  1780     "^update|up|checkout|co":
  1832     "^update|up|checkout|co":
  1781         (update,
  1833         (update,
  1782          [('b', 'branch', "", 'checkout the head of a specific branch'),
  1834          [('b', 'branch', "", 'checkout the head of a specific branch'),
  1783           ('m', 'merge', None, 'allow merging of conflicts'),
  1835           ('m', 'merge', None, 'allow merging of conflicts'),