Show More
@@ -119,21 +119,11 b' except:' | |||
|
119 | 119 | ui = ui.ui(options["verbose"], options["debug"], options["quiet"], |
|
120 | 120 | not options["noninteractive"]) |
|
121 | 121 | |
|
122 | if cmd == "init": | |
|
123 |
repo = hg.repository(ui |
|
|
124 | sys.exit(0) | |
|
125 | elif cmd == "branch" or cmd == "clone": | |
|
126 | os.system("cp -al %s/.hg .hg" % args[0]) | |
|
122 | try: | |
|
123 | repo = hg.repository(ui=ui) | |
|
124 | except IOError: | |
|
125 | ui.warn("Unable to open repository\n") | |
|
127 | 126 | sys.exit(0) |
|
128 | elif cmd == "help": | |
|
129 | help() | |
|
130 | sys.exit(0) | |
|
131 | else: | |
|
132 | try: | |
|
133 | repo = hg.repository(ui=ui) | |
|
134 | except IOError: | |
|
135 | ui.warn("Unable to open repository\n") | |
|
136 | sys.exit(0) | |
|
137 | 127 | |
|
138 | 128 | relpath = None |
|
139 | 129 | if os.getcwd() != repo.root: |
@@ -221,15 +211,6 b' elif cmd == "import" or cmd == "patch":' | |||
|
221 | 211 | raise "patch failed!" |
|
222 | 212 | repo.commit(repo.current, files, text) |
|
223 | 213 | |
|
224 | elif cmd == "status": | |
|
225 | (c, a, d) = repo.diffdir(repo.root, repo.current) | |
|
226 | if relpath: | |
|
227 | (c, a, d) = map(lambda x: filterfiles(x, [ relpath ]), (c, a, d)) | |
|
228 | ||
|
229 | for f in c: print "C", f | |
|
230 | for f in a: print "?", f | |
|
231 | for f in d: print "R", f | |
|
232 | ||
|
233 | 214 | elif cmd == "diff": |
|
234 | 215 | revs = [] |
|
235 | 216 |
@@ -3,6 +3,20 b' from mercurial import fancyopts, ui, hg' | |||
|
3 | 3 | |
|
4 | 4 | class UnknownCommand(Exception): pass |
|
5 | 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 | |
|
19 | ||
|
6 | 20 | def relpath(repo, args): |
|
7 | 21 | if os.getcwd() != repo.root: |
|
8 | 22 | p = os.getcwd()[len(repo.root) + 1: ] |
@@ -49,6 +63,11 b' def init(ui):' | |||
|
49 | 63 | """create a repository""" |
|
50 | 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 | 71 | def checkout(u, repo, changeset=None): |
|
53 | 72 | '''checkout a given changeset or the current tip''' |
|
54 | 73 | node = repo.changelog.tip() |
@@ -98,11 +117,26 b' def annotate(u, repo, *args, **ops):' | |||
|
98 | 117 | for p,l in zip(zip(*pieces), lines): |
|
99 | 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 | 134 | def undo(ui, repo): |
|
102 | 135 | repo.undo() |
|
103 | 136 | |
|
104 | 137 | table = { |
|
105 | 138 | "init": (init, [], 'hg init'), |
|
139 | "branch|clone": (branch, [], 'hg branch [path]'), | |
|
106 | 140 | "help": (help, [], 'hg help [command]'), |
|
107 | 141 | "checkout|co": (checkout, [], 'hg checkout [changeset]'), |
|
108 | 142 | "ann|annotate": (annotate, |
@@ -111,6 +145,7 b' table = {' | |||
|
111 | 145 | ('n', 'number', None, 'show revision number'), |
|
112 | 146 | ('c', 'changeset', None, 'show changeset')], |
|
113 | 147 | 'hg annotate [-u] [-c] [-n] [-r id] [files]'), |
|
148 | "status": (status, [], 'hg status'), | |
|
114 | 149 | "undo": (undo, [], 'hg undo'), |
|
115 | 150 | } |
|
116 | 151 |
General Comments 0
You need to be logged in to leave comments.
Login now