Show More
@@ -119,21 +119,11 b' except:' | |||||
119 | ui = ui.ui(options["verbose"], options["debug"], options["quiet"], |
|
119 | ui = ui.ui(options["verbose"], options["debug"], options["quiet"], | |
120 | not options["noninteractive"]) |
|
120 | not options["noninteractive"]) | |
121 |
|
121 | |||
122 | if cmd == "init": |
|
122 | try: | |
123 |
repo = hg.repository(ui |
|
123 | repo = hg.repository(ui=ui) | |
124 | sys.exit(0) |
|
124 | except IOError: | |
125 | elif cmd == "branch" or cmd == "clone": |
|
125 | ui.warn("Unable to open repository\n") | |
126 | os.system("cp -al %s/.hg .hg" % args[0]) |
|
|||
127 | sys.exit(0) |
|
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 | relpath = None |
|
128 | relpath = None | |
139 | if os.getcwd() != repo.root: |
|
129 | if os.getcwd() != repo.root: | |
@@ -221,15 +211,6 b' elif cmd == "import" or cmd == "patch":' | |||||
221 | raise "patch failed!" |
|
211 | raise "patch failed!" | |
222 | repo.commit(repo.current, files, text) |
|
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 | elif cmd == "diff": |
|
214 | elif cmd == "diff": | |
234 | revs = [] |
|
215 | revs = [] | |
235 |
|
216 |
@@ -3,6 +3,20 b' from mercurial import fancyopts, ui, hg' | |||||
3 |
|
3 | |||
4 | class UnknownCommand(Exception): pass |
|
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 | 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: ] | |
@@ -49,6 +63,11 b' 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() | |
@@ -98,11 +117,26 b' def annotate(u, repo, *args, **ops):' | |||||
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, | |
@@ -111,6 +145,7 b' table = {' | |||||
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 |
General Comments 0
You need to be logged in to leave comments.
Login now