Show More
@@ -16,55 +16,9 b'' | |||
|
16 | 16 | # except: |
|
17 | 17 | # pass |
|
18 | 18 | |
|
19 |
import sys |
|
|
19 | import sys | |
|
20 | 20 | from mercurial import hg, mdiff, fancyopts, ui, commands |
|
21 | 21 | |
|
22 | def filterfiles(list, files): | |
|
23 | l = [ x for x in list if x in files ] | |
|
24 | ||
|
25 | for f in files: | |
|
26 | if f[-1] != os.sep: f += os.sep | |
|
27 | l += [ x for x in list if x.startswith(f) ] | |
|
28 | return l | |
|
29 | ||
|
30 | def diff(files = None, node1 = None, node2 = None): | |
|
31 | def date(c): | |
|
32 | return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) | |
|
33 | ||
|
34 | if node2: | |
|
35 | change = repo.changelog.read(node2) | |
|
36 | mmap2 = repo.manifest.read(change[0]) | |
|
37 | (c, a, d) = repo.diffrevs(node1, node2) | |
|
38 | def read(f): return repo.file(f).read(mmap2[f]) | |
|
39 | date2 = date(change) | |
|
40 | else: | |
|
41 | date2 = time.asctime() | |
|
42 | if not node1: | |
|
43 | node1 = repo.dirstate.parents()[0] | |
|
44 | (c, a, d, u) = repo.diffdir(repo.root, node1) | |
|
45 | def read(f): return file(os.path.join(repo.root, f)).read() | |
|
46 | ||
|
47 | change = repo.changelog.read(node1) | |
|
48 | mmap = repo.manifest.read(change[0]) | |
|
49 | date1 = date(change) | |
|
50 | ||
|
51 | if files: | |
|
52 | c, a, d = map(lambda x: filterfiles(x, files), (c, a, d)) | |
|
53 | ||
|
54 | for f in c: | |
|
55 | to = repo.file(f).read(mmap[f]) | |
|
56 | tn = read(f) | |
|
57 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | |
|
58 | for f in a: | |
|
59 | to = "" | |
|
60 | tn = read(f) | |
|
61 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | |
|
62 | for f in d: | |
|
63 | to = repo.file(f).read(mmap[f]) | |
|
64 | tn = "" | |
|
65 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | |
|
66 | ||
|
67 | ||
|
68 | 22 | try: |
|
69 | 23 | sys.exit(commands.dispatch(sys.argv[1:])) |
|
70 | 24 | except commands.UnknownCommand: |
@@ -96,90 +50,7 b' except IOError:' | |||
|
96 | 50 | ui.warn("Unable to open repository\n") |
|
97 | 51 | sys.exit(0) |
|
98 | 52 | |
|
99 | relpath = None | |
|
100 | if os.getcwd() != repo.root: | |
|
101 | relpath = os.getcwd()[len(repo.root) + 1: ] | |
|
102 | ||
|
103 | elif cmd == "rawcommit": | |
|
104 | "raw commit interface" | |
|
105 | rc = {} | |
|
106 | opts = [('p', 'parent', [], 'parent'), | |
|
107 | ('d', 'date', "", 'data'), | |
|
108 | ('u', 'user', "", 'user'), | |
|
109 | ('F', 'files', "", 'file list'), | |
|
110 | ('t', 'text', "", 'commit text'), | |
|
111 | ('l', 'logfile', "", 'commit text file') | |
|
112 | ] | |
|
113 | args = fancyopts.fancyopts(args, opts, rc, | |
|
114 | "hg rawcommit [options] files") | |
|
115 | text = rc['text'] | |
|
116 | if not text and rc['logfile']: | |
|
117 | try: text = open(rc['logfile']).read() | |
|
118 | except IOError: pass | |
|
119 | if not text and not rc['logfile']: | |
|
120 | print "missing commit text" | |
|
121 | sys.exit(0) | |
|
122 | if rc['files']: | |
|
123 | files = open(rc['files']).read().splitlines() | |
|
124 | else: | |
|
125 | files = args | |
|
126 | ||
|
127 | repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) | |
|
128 | ||
|
129 | ||
|
130 | elif cmd == "import" or cmd == "patch": | |
|
131 | try: | |
|
132 | import psyco | |
|
133 | psyco.full() | |
|
134 | except: | |
|
135 | pass | |
|
136 | ||
|
137 | ioptions = {} | |
|
138 | opts = [('p', 'strip', 1, 'path strip'), | |
|
139 | ('b', 'base', "", 'base path'), | |
|
140 | ('q', 'quiet', "", 'silence diff') | |
|
141 | ] | |
|
142 | ||
|
143 | args = fancyopts.fancyopts(args, opts, ioptions, | |
|
144 | 'hg import [options] <patch names>') | |
|
145 | d = ioptions["base"] | |
|
146 | strip = ioptions["strip"] | |
|
147 | quiet = ioptions["quiet"] and "> /dev/null" or "" | |
|
148 | ||
|
149 | for patch in args: | |
|
150 | ui.status("applying %s\n" % patch) | |
|
151 | pf = os.path.join(d, patch) | |
|
152 | ||
|
153 | text = "" | |
|
154 | for l in file(pf): | |
|
155 | if l[:4] == "--- ": break | |
|
156 | text += l | |
|
157 | ||
|
158 | f = os.popen("lsdiff --strip %d %s" % (strip, pf)) | |
|
159 | files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) | |
|
160 | f.close() | |
|
161 | ||
|
162 | if files: | |
|
163 | if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): | |
|
164 | raise "patch failed!" | |
|
165 | repo.commit(files, text) | |
|
166 | ||
|
167 | elif cmd == "export": | |
|
168 | node = repo.lookup(args[0]) | |
|
169 | prev, other = repo.changelog.parents(node) | |
|
170 | change = repo.changelog.read(node) | |
|
171 | print "# HG changeset patch" | |
|
172 | print "# User %s" % change[1] | |
|
173 | print "# Node ID %s" % hg.hex(node) | |
|
174 | print "# Parent %s" % hg.hex(prev) | |
|
175 | ||
|
176 | if other != hg.nullid: | |
|
177 | print "# Parent %s" % hg.hex(other) | |
|
178 | print change[4] | |
|
179 | ||
|
180 | diff(None, prev, node) | |
|
181 | ||
|
182 | elif cmd == "debugchangegroup": | |
|
53 | if cmd == "debugchangegroup": | |
|
183 | 54 | newer = repo.newer(map(repo.lookup, args)) |
|
184 | 55 | for chunk in repo.changegroup(newer): |
|
185 | 56 | sys.stdout.write(chunk) |
@@ -188,25 +59,6 b' elif cmd == "debugaddchangegroup":' | |||
|
188 | 59 | data = sys.stdin.read() |
|
189 | 60 | repo.addchangegroup(data) |
|
190 | 61 | |
|
191 | elif cmd == "history": | |
|
192 | for i in range(repo.changelog.count()): | |
|
193 | n = repo.changelog.node(i) | |
|
194 | changes = repo.changelog.read(n) | |
|
195 | (p1, p2) = repo.changelog.parents(n) | |
|
196 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
|
197 | (i1, i2) = map(repo.changelog.rev, (p1, p2)) | |
|
198 | print "rev: %4d:%s" % (i, h) | |
|
199 | print "parents: %4d:%s" % (i1, h1) | |
|
200 | if i2: print " %4d:%s" % (i2, h2) | |
|
201 | print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), | |
|
202 | hg.hex(changes[0])) | |
|
203 | print "user:", changes[1] | |
|
204 | print "date:", time.asctime( | |
|
205 | time.localtime(float(changes[2].split(' ')[0]))) | |
|
206 | if ui.verbose: print "files:", " ".join(changes[3]) | |
|
207 | print "description:" | |
|
208 | print changes[4] | |
|
209 | ||
|
210 | 62 | elif cmd == "dump": |
|
211 | 63 | if args: |
|
212 | 64 | r = repo.file(args[0]) |
@@ -253,25 +105,6 b' elif cmd == "debugindexdot":' | |||
|
253 | 105 | print "\t%d -> %d" % (r.rev(e[5]), i) |
|
254 | 106 | print "}" |
|
255 | 107 | |
|
256 | elif cmd == "merge": | |
|
257 | if args: | |
|
258 | paths = {} | |
|
259 | try: | |
|
260 | pf = os.path.join(os.environ["HOME"], ".hgpaths") | |
|
261 | for l in file(pf): | |
|
262 | name, path = l.split() | |
|
263 | paths[name] = path | |
|
264 | except: | |
|
265 | pass | |
|
266 | ||
|
267 | if args[0] in paths: args[0] = paths[args[0]] | |
|
268 | ||
|
269 | other = hg.repository(ui, args[0]) | |
|
270 | cg = repo.getchangegroup(other) | |
|
271 | repo.addchangegroup(cg) | |
|
272 | else: | |
|
273 | print "missing source repository" | |
|
274 | ||
|
275 | 108 | elif cmd == "tags": |
|
276 | 109 | repo.lookup(0) # prime the cache |
|
277 | 110 | i = repo.tags.items() |
@@ -183,6 +183,22 b' def diff(ui, repo, *files, **opts):' | |||
|
183 | 183 | |
|
184 | 184 | dodiff(repo, files, *revs) |
|
185 | 185 | |
|
186 | def export(ui, repo, changeset): | |
|
187 | node = repo.lookup(changeset) | |
|
188 | prev, other = repo.changelog.parents(node) | |
|
189 | change = repo.changelog.read(node) | |
|
190 | print "# HG changeset patch" | |
|
191 | print "# User %s" % change[1] | |
|
192 | print "# Node ID %s" % hg.hex(node) | |
|
193 | print "# Parent %s" % hg.hex(prev) | |
|
194 | ||
|
195 | if other != hg.nullid: | |
|
196 | print "# Parent %s" % hg.hex(other) | |
|
197 | print change[4].rstrip() | |
|
198 | ||
|
199 | ||
|
200 | dodiff(repo, None, prev, node) | |
|
201 | ||
|
186 | 202 | def forget(ui, repo, file, *files): |
|
187 | 203 | """don't add the specified files on the next commit""" |
|
188 | 204 | repo.forget(relpath(repo, (file,) + files)) |
@@ -207,6 +223,56 b' def heads(ui, repo):' | |||
|
207 | 223 | print "description:" |
|
208 | 224 | print changes[4] |
|
209 | 225 | |
|
226 | def history(ui, repo): | |
|
227 | """show the changelog history""" | |
|
228 | for i in range(repo.changelog.count()): | |
|
229 | n = repo.changelog.node(i) | |
|
230 | changes = repo.changelog.read(n) | |
|
231 | (p1, p2) = repo.changelog.parents(n) | |
|
232 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
|
233 | (i1, i2) = map(repo.changelog.rev, (p1, p2)) | |
|
234 | print "rev: %4d:%s" % (i, h) | |
|
235 | print "parents: %4d:%s" % (i1, h1) | |
|
236 | if i2: print " %4d:%s" % (i2, h2) | |
|
237 | print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), | |
|
238 | hg.hex(changes[0])) | |
|
239 | print "user:", changes[1] | |
|
240 | print "date:", time.asctime( | |
|
241 | time.localtime(float(changes[2].split(' ')[0]))) | |
|
242 | if ui.verbose: print "files:", " ".join(changes[3]) | |
|
243 | print "description:" | |
|
244 | print changes[4] | |
|
245 | ||
|
246 | def patch(ui, repo, patches, opts): | |
|
247 | """import an ordered set of patches""" | |
|
248 | try: | |
|
249 | import psyco | |
|
250 | psyco.full() | |
|
251 | except: | |
|
252 | pass | |
|
253 | ||
|
254 | d = opts["base"] | |
|
255 | strip = opts["strip"] | |
|
256 | quiet = opts["quiet"] and "> /dev/null" or "" | |
|
257 | ||
|
258 | for patch in patches: | |
|
259 | ui.status("applying %s\n" % patch) | |
|
260 | pf = os.path.join(d, patch) | |
|
261 | ||
|
262 | text = "" | |
|
263 | for l in file(pf): | |
|
264 | if l[:4] == "--- ": break | |
|
265 | text += l | |
|
266 | ||
|
267 | f = os.popen("lsdiff --strip %d %s" % (strip, pf)) | |
|
268 | files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) | |
|
269 | f.close() | |
|
270 | ||
|
271 | if files: | |
|
272 | if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): | |
|
273 | raise "patch failed!" | |
|
274 | repo.commit(files, text) | |
|
275 | ||
|
210 | 276 | def init(ui): |
|
211 | 277 | """create a repository""" |
|
212 | 278 | hg.repository(ui, ".", create=1) |
@@ -245,6 +311,40 b' def parents(ui, repo, node = None):' | |||
|
245 | 311 | if n != hg.nullid: |
|
246 | 312 | ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n))) |
|
247 | 313 | |
|
314 | def pull(ui, repo, source): | |
|
315 | """pull changes from the specified source""" | |
|
316 | paths = {} | |
|
317 | try: | |
|
318 | pf = os.path.expanduser("~/.hgpaths") | |
|
319 | for l in file(pf): | |
|
320 | name, path = l.split() | |
|
321 | paths[name] = path | |
|
322 | except IOError: | |
|
323 | pass | |
|
324 | ||
|
325 | if source in paths: source = paths[source] | |
|
326 | ||
|
327 | other = hg.repository(ui, source) | |
|
328 | cg = repo.getchangegroup(other) | |
|
329 | repo.addchangegroup(cg) | |
|
330 | ||
|
331 | def rawcommit(ui, repo, files, rc): | |
|
332 | "raw commit interface" | |
|
333 | ||
|
334 | text = rc['text'] | |
|
335 | if not text and rc['logfile']: | |
|
336 | try: text = open(rc['logfile']).read() | |
|
337 | except IOError: pass | |
|
338 | if not text and not rc['logfile']: | |
|
339 | print "missing commit text" | |
|
340 | return 1 | |
|
341 | ||
|
342 | files = relpath(repo, files) | |
|
343 | if rc['files']: | |
|
344 | files += open(rc['files']).read().splitlines() | |
|
345 | ||
|
346 | repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) | |
|
347 | ||
|
248 | 348 | def recover(ui, repo): |
|
249 | 349 | repo.recover() |
|
250 | 350 | |
@@ -303,12 +403,28 b' table = {' | |||
|
303 | 403 | "commit|ci": (commit, [], 'hg commit [files]'), |
|
304 | 404 | "diff": (diff, [('r', 'rev', [], 'revision')], |
|
305 | 405 | 'hg diff [-r A] [-r B] [files]'), |
|
406 | "export": (export, [], "hg export <changeset>"), | |
|
306 | 407 | "forget": (forget, [], "hg forget [files]"), |
|
307 | 408 | "heads": (heads, [], 'hg heads'), |
|
409 | "history": (history, [], 'hg history'), | |
|
308 | 410 | "help": (help, [], 'hg help [command]'), |
|
309 | 411 | "init": (init, [], 'hg init'), |
|
310 | 412 | "log": (log, [], 'hg log <file>'), |
|
311 | 413 | "parents": (parents, [], 'hg parents [node]'), |
|
414 | "patch|import": (patch, | |
|
415 | [('p', 'strip', 1, 'path strip'), | |
|
416 | ('b', 'base', "", 'base path'), | |
|
417 | ('q', 'quiet', "", 'silence diff')], | |
|
418 | "hg import [options] patches"), | |
|
419 | "pull|merge": (pull, [], 'hg pull [source]'), | |
|
420 | "rawcommit": (rawcommit, | |
|
421 | [('p', 'parent', [], 'parent'), | |
|
422 | ('d', 'date', "", 'data'), | |
|
423 | ('u', 'user', "", 'user'), | |
|
424 | ('F', 'files', "", 'file list'), | |
|
425 | ('t', 'text', "", 'commit text'), | |
|
426 | ('l', 'logfile', "", 'commit text file')], | |
|
427 | 'hg rawcommit [options] [files]'), | |
|
312 | 428 | "recover": (recover, [], "hg recover"), |
|
313 | 429 | "remove": (remove, [], "hg remove [files]"), |
|
314 | 430 | "resolve": (resolve, [], 'hg resolve [node]'), |
@@ -371,7 +487,7 b' def dispatch(args):' | |||
|
371 | 487 | d = lambda: i[0](u, *args, **cmdoptions) |
|
372 | 488 | |
|
373 | 489 | try: |
|
374 | d() | |
|
490 | return d() | |
|
375 | 491 | except SignalInterrupt: |
|
376 | 492 | u.warn("killed!\n") |
|
377 | 493 | except KeyboardInterrupt: |
General Comments 0
You need to be logged in to leave comments.
Login now