Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 213:d2172916ef6c
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-----
author | mpm@selenic.com |
---|---|
date | Wed, 01 Jun 2005 11:48:34 -0800 |
parents | 48398a5353e3 |
children | 2d60aa9bde0a |
comparison
equal
deleted
inserted
replaced
212:48398a5353e3 | 213:d2172916ef6c |
---|---|
1 import os, re, traceback, sys | 1 import os, re, traceback, sys |
2 from mercurial import fancyopts, ui, hg | 2 from mercurial import fancyopts, ui, hg |
3 | 3 |
4 class UnknownCommand(Exception): pass | 4 class UnknownCommand(Exception): pass |
5 | |
6 def filterfiles(list, files): | |
7 l = [ x for x in list if x in files ] | |
8 | |
9 for f in files: | |
10 if f[-1] != os.sep: f += os.sep | |
11 l += [ x for x in list if x.startswith(f) ] | |
12 return l | |
13 | |
14 def relfilter(repo, args): | |
15 if os.getcwd() != repo.root: | |
16 p = os.getcwd()[len(repo.root) + 1: ] | |
17 return filterfiles(p, args) | |
18 return args | |
5 | 19 |
6 def relpath(repo, args): | 20 def relpath(repo, args): |
7 if os.getcwd() != repo.root: | 21 if os.getcwd() != repo.root: |
8 p = os.getcwd()[len(repo.root) + 1: ] | 22 p = os.getcwd()[len(repo.root) + 1: ] |
9 return [ os.path.join(p, x) for x in args ] | 23 return [ os.path.join(p, x) for x in args ] |
47 | 61 |
48 def init(ui): | 62 def init(ui): |
49 """create a repository""" | 63 """create a repository""" |
50 hg.repository(ui, ".", create=1) | 64 hg.repository(ui, ".", create=1) |
51 | 65 |
66 def branch(ui, path): | |
67 '''branch from a local repository''' | |
68 # this should eventually support remote repos | |
69 os.system("cp -al %s/.hg .hg" % path) | |
70 | |
52 def checkout(u, repo, changeset=None): | 71 def checkout(u, repo, changeset=None): |
53 '''checkout a given changeset or the current tip''' | 72 '''checkout a given changeset or the current tip''' |
54 node = repo.changelog.tip() | 73 node = repo.changelog.tip() |
55 if changeset: | 74 if changeset: |
56 node = repo.lookup(changeset) | 75 node = repo.lookup(changeset) |
96 pieces.append([ "%*s" % (m, x) for x in l]) | 115 pieces.append([ "%*s" % (m, x) for x in l]) |
97 | 116 |
98 for p,l in zip(zip(*pieces), lines): | 117 for p,l in zip(zip(*pieces), lines): |
99 u.write(" ".join(p) + ": " + l[1]) | 118 u.write(" ".join(p) + ": " + l[1]) |
100 | 119 |
120 def status(ui, repo): | |
121 '''show changed files in the working directory | |
122 | |
123 C = changed | |
124 A = added | |
125 R = removed | |
126 ? = not tracked''' | |
127 (c, a, d) = repo.diffdir(repo.root, repo.current) | |
128 (c, a, d) = map(lambda x: relfilter(repo, x), (c, a, d)) | |
129 | |
130 for f in c: print "C", f | |
131 for f in a: print "?", f | |
132 for f in d: print "R", f | |
133 | |
101 def undo(ui, repo): | 134 def undo(ui, repo): |
102 repo.undo() | 135 repo.undo() |
103 | 136 |
104 table = { | 137 table = { |
105 "init": (init, [], 'hg init'), | 138 "init": (init, [], 'hg init'), |
139 "branch|clone": (branch, [], 'hg branch [path]'), | |
106 "help": (help, [], 'hg help [command]'), | 140 "help": (help, [], 'hg help [command]'), |
107 "checkout|co": (checkout, [], 'hg checkout [changeset]'), | 141 "checkout|co": (checkout, [], 'hg checkout [changeset]'), |
108 "ann|annotate": (annotate, | 142 "ann|annotate": (annotate, |
109 [('r', 'revision', '', 'revision'), | 143 [('r', 'revision', '', 'revision'), |
110 ('u', 'user', None, 'show user'), | 144 ('u', 'user', None, 'show user'), |
111 ('n', 'number', None, 'show revision number'), | 145 ('n', 'number', None, 'show revision number'), |
112 ('c', 'changeset', None, 'show changeset')], | 146 ('c', 'changeset', None, 'show changeset')], |
113 'hg annotate [-u] [-c] [-n] [-r id] [files]'), | 147 'hg annotate [-u] [-c] [-n] [-r id] [files]'), |
148 "status": (status, [], 'hg status'), | |
114 "undo": (undo, [], 'hg undo'), | 149 "undo": (undo, [], 'hg undo'), |
115 } | 150 } |
116 | 151 |
117 norepo = "init branch help" | 152 norepo = "init branch help" |
118 | 153 |