commands: migrate status and branch
authormpm@selenic.com
Wed, 01 Jun 2005 11:48:34 -0800
changeset 213 d2172916ef6c64001cf747040dd625db89b61929
parent 212 48398a5353e393f682c7455d0de7d44ded965d28
child 214 2d60aa9bde0aba8ff1f746473d2db758449404f2
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
commands: migrate status and branch -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 commands: migrate status and branch manifest hash: 7d893a81a81539173fc74d86152062a1a70bed13 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCnhESywK+sNU5EO8RAlBJAKCmv2gHefMOXfX/UUCy1tfV0cOqOQCfbeX8 oaT15B7GBL2lcalGrPXkzY8= =8gVe -----END PGP SIGNATURE-----
hg
mercurial/commands.py
--- a/hg
+++ b/hg
@@ -114,31 +114,21 @@ try:
     cmd = args[0]
     args = args[1:]
 except:
     cmd = "help"
 
 ui = ui.ui(options["verbose"], options["debug"], options["quiet"],
            not options["noninteractive"])
     
-if cmd == "init":
-    repo = hg.repository(ui, ".", create=1)
-    sys.exit(0)
-elif cmd == "branch" or cmd == "clone":
-    os.system("cp -al %s/.hg .hg" % args[0])
+try:
+    repo = hg.repository(ui=ui)
+except IOError:
+    ui.warn("Unable to open repository\n")
     sys.exit(0)
-elif cmd == "help":
-    help()
-    sys.exit(0)
-else:
-    try:
-        repo = hg.repository(ui=ui)
-    except IOError:
-        ui.warn("Unable to open repository\n")
-        sys.exit(0)
 
 relpath = None
 if os.getcwd() != repo.root:
     relpath = os.getcwd()[len(repo.root) + 1: ]
 
 if cmd == "checkout" or cmd == "co":
     node = repo.changelog.tip()
     if args:
@@ -216,25 +206,16 @@ elif cmd == "import" or cmd == "patch":
         files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines()))
         f.close()
 
         if files:
             if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
                 raise "patch failed!"
         repo.commit(repo.current, files, text)
 
-elif cmd == "status":
-    (c, a, d) = repo.diffdir(repo.root, repo.current)
-    if relpath:
-        (c, a, d) = map(lambda x: filterfiles(x, [ relpath ]), (c, a, d))
-
-    for f in c: print "C", f
-    for f in a: print "?", f
-    for f in d: print "R", f
-
 elif cmd == "diff":
     revs = []
 
     if args:
         doptions = {}
         opts = [('r', 'revision', [], 'revision')]
         args = fancyopts.fancyopts(args, opts, doptions,
                                    'hg diff [options] [files]')
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1,13 +1,27 @@
 import os, re, traceback, sys
 from mercurial import fancyopts, ui, hg
 
 class UnknownCommand(Exception): pass
 
+def filterfiles(list, files):
+    l = [ x for x in list if x in files ]
+
+    for f in files:
+        if f[-1] != os.sep: f += os.sep
+        l += [ x for x in list if x.startswith(f) ]
+    return l
+
+def relfilter(repo, args):
+    if os.getcwd() != repo.root:
+        p = os.getcwd()[len(repo.root) + 1: ]
+        return filterfiles(p, args)
+    return args
+
 def relpath(repo, args):
     if os.getcwd() != repo.root:
         p = os.getcwd()[len(repo.root) + 1: ]
         return [ os.path.join(p, x) for x in args ]
     return args
     
 def help(ui, cmd=None):
     '''show help'''
@@ -44,16 +58,21 @@ def help(ui, cmd=None):
  tags                  show current changeset tags
  undo                  undo the last transaction
 """)
 
 def init(ui):
     """create a repository"""
     hg.repository(ui, ".", create=1)
 
+def branch(ui, path):
+    '''branch from a local repository'''
+    # this should eventually support remote repos
+    os.system("cp -al %s/.hg .hg" % path)
+
 def checkout(u, repo, changeset=None):
     '''checkout a given changeset or the current tip'''
     node = repo.changelog.tip()
     if changeset:
         node = repo.lookup(changeset)
     repo.checkout(node)
 
 def annotate(u, repo, *args, **ops):
@@ -93,29 +112,45 @@ def annotate(u, repo, *args, **ops):
             if ops[o]:
                 l = [ f(n) for n,t in lines ]
                 m = max(map(len, l))
                 pieces.append([ "%*s" % (m, x) for x in l])
 
         for p,l in zip(zip(*pieces), lines):
             u.write(" ".join(p) + ": " + l[1])
 
+def status(ui, repo):
+    '''show changed files in the working directory
+
+C = changed
+A = added
+R = removed
+? = not tracked'''
+    (c, a, d) = repo.diffdir(repo.root, repo.current)
+    (c, a, d) = map(lambda x: relfilter(repo, x), (c, a, d))
+
+    for f in c: print "C", f
+    for f in a: print "?", f
+    for f in d: print "R", f
+
 def undo(ui, repo):
     repo.undo()
 
 table = {
     "init": (init, [], 'hg init'),
+    "branch|clone": (branch, [], 'hg branch [path]'),
     "help": (help, [], 'hg help [command]'),
     "checkout|co": (checkout, [], 'hg checkout [changeset]'),
     "ann|annotate": (annotate,
                      [('r', 'revision', '', 'revision'),
                       ('u', 'user', None, 'show user'),
                       ('n', 'number', None, 'show revision number'),
                       ('c', 'changeset', None, 'show changeset')],
                      'hg annotate [-u] [-c] [-n] [-r id] [files]'),
+    "status": (status, [], 'hg status'),
     "undo": (undo, [], 'hg undo'),
     }
 
 norepo = "init branch help"
 
 def find(cmd):
     i = None
     for e in table.keys():