Mercurial > hg
comparison hgext/hgk.py @ 3979:e0d13267f7a4
hgk: use contexts
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Tue, 26 Dec 2006 03:27:24 +0100 |
parents | ee5663cb4406 |
children | 180670f14045 |
comparison
equal
deleted
inserted
replaced
3978:ee5663cb4406 | 3979:e0d13267f7a4 |
---|---|
10 | 10 |
11 def difftree(ui, repo, node1=None, node2=None, *files, **opts): | 11 def difftree(ui, repo, node1=None, node2=None, *files, **opts): |
12 """diff trees from two commits""" | 12 """diff trees from two commits""" |
13 def __difftree(repo, node1, node2, files=[]): | 13 def __difftree(repo, node1, node2, files=[]): |
14 assert node2 is not None | 14 assert node2 is not None |
15 change = repo.changelog.read(node2) | 15 mmap2 = repo.changectx(node2).manifest() |
16 mmap2 = repo.manifest.read(change[0]) | |
17 status = repo.status(node1, node2, files=files)[:5] | 16 status = repo.status(node1, node2, files=files)[:5] |
18 modified, added, removed, deleted, unknown = status | 17 modified, added, removed, deleted, unknown = status |
19 | 18 |
20 change = repo.changelog.read(node1) | 19 mmap = repo.changectx(node1).manifest() |
21 mmap = repo.manifest.read(change[0]) | |
22 empty = hg.short(hg.nullid) | 20 empty = hg.short(hg.nullid) |
23 | 21 |
24 for f in modified: | 22 for f in modified: |
25 # TODO get file permissions | 23 # TODO get file permissions |
26 print ":100664 100664 %s %s M\t%s\t%s" % (hg.short(mmap[f]), | 24 print ":100664 100664 %s %s M\t%s\t%s" % (hg.short(mmap[f]), |
62 else: | 60 else: |
63 __difftree(repo, node1, node2, files=files) | 61 __difftree(repo, node1, node2, files=files) |
64 if not opts['stdin']: | 62 if not opts['stdin']: |
65 break | 63 break |
66 | 64 |
67 def catcommit(repo, n, prefix, changes=None): | 65 def catcommit(repo, n, prefix, ctx=None): |
68 nlprefix = '\n' + prefix; | 66 nlprefix = '\n' + prefix; |
69 (p1, p2) = repo.changelog.parents(n) | 67 if ctx is None: |
70 (h, h1, h2) = map(hg.short, (n, p1, p2)) | 68 ctx = repo.changectx(n) |
71 (i1, i2) = map(repo.changelog.rev, (p1, p2)) | 69 (p1, p2) = ctx.parents() |
72 if not changes: | 70 print "tree %s" % (hg.short(ctx.changeset()[0])) # use ctx.node() instead ?? |
73 changes = repo.changelog.read(n) | 71 if p1: print "parent %s" % (hg.short(p1.node())) |
74 print "tree %s" % (hg.short(changes[0])) | 72 if p2: print "parent %s" % (hg.short(p2.node())) |
75 if i1 != hg.nullrev: print "parent %s" % (h1) | 73 date = ctx.date() |
76 if i2 != hg.nullrev: print "parent %s" % (h2) | 74 description = ctx.description() |
77 date_ar = changes[2] | 75 lines = description.splitlines() |
78 date = int(float(date_ar[0])) | |
79 lines = changes[4].splitlines() | |
80 if lines and lines[-1].startswith('committer:'): | 76 if lines and lines[-1].startswith('committer:'): |
81 committer = lines[-1].split(': ')[1].rstrip() | 77 committer = lines[-1].split(': ')[1].rstrip() |
82 else: | 78 else: |
83 committer = changes[1] | 79 committer = ctx.user() |
84 | 80 |
85 print "author %s %s %s" % (changes[1], date, date_ar[1]) | 81 print "author %s %s %s" % (ctx.user(), int(date[0]), date[1]) |
86 print "committer %s %s %s" % (committer, date, date_ar[1]) | 82 print "committer %s %s %s" % (committer, int(date[0]), date[1]) |
87 print "revision %d" % repo.changelog.rev(n) | 83 print "revision %d" % ctx.rev() |
88 print "" | 84 print "" |
89 if prefix != "": | 85 if prefix != "": |
90 print "%s%s" % (prefix, changes[4].replace('\n', nlprefix).strip()) | 86 print "%s%s" % (prefix, description.replace('\n', nlprefix).strip()) |
91 else: | 87 else: |
92 print changes[4] | 88 print description |
93 if prefix: | 89 if prefix: |
94 sys.stdout.write('\0') | 90 sys.stdout.write('\0') |
95 | 91 |
96 def base(ui, repo, node1, node2): | 92 def base(ui, repo, node1, node2): |
97 """Output common ancestor information""" | 93 """Output common ancestor information""" |
138 # telling you which commits are reachable from the supplied ones via | 134 # telling you which commits are reachable from the supplied ones via |
139 # a bitmask based on arg position. | 135 # a bitmask based on arg position. |
140 # you can specify a commit to stop at by starting the sha1 with ^ | 136 # you can specify a commit to stop at by starting the sha1 with ^ |
141 def revtree(args, repo, full="tree", maxnr=0, parents=False): | 137 def revtree(args, repo, full="tree", maxnr=0, parents=False): |
142 def chlogwalk(): | 138 def chlogwalk(): |
143 ch = repo.changelog | 139 count = repo.changelog.count() |
144 count = ch.count() | |
145 i = count | 140 i = count |
146 l = [0] * 100 | 141 l = [0] * 100 |
147 chunk = 100 | 142 chunk = 100 |
148 while True: | 143 while True: |
149 if chunk > i: | 144 if chunk > i: |
155 for x in xrange(0, chunk): | 150 for x in xrange(0, chunk): |
156 if i + x >= count: | 151 if i + x >= count: |
157 l[chunk - x:] = [0] * (chunk - x) | 152 l[chunk - x:] = [0] * (chunk - x) |
158 break | 153 break |
159 if full != None: | 154 if full != None: |
160 l[x] = ch.read(ch.node(i + x)) | 155 l[x] = repo.changectx(i + x) |
161 else: | 156 else: |
162 l[x] = 1 | 157 l[x] = 1 |
163 for x in xrange(chunk-1, -1, -1): | 158 for x in xrange(chunk-1, -1, -1): |
164 if l[x] != 0: | 159 if l[x] != 0: |
165 yield (i + x, full != None and l[x] or None) | 160 yield (i + x, full != None and l[x] or None) |
209 if p in stop_sha1: | 204 if p in stop_sha1: |
210 continue | 205 continue |
211 | 206 |
212 # walk the repository looking for commits that are in our | 207 # walk the repository looking for commits that are in our |
213 # reachability graph | 208 # reachability graph |
214 for i, changes in chlogwalk(): | 209 for i, ctx in chlogwalk(): |
215 n = repo.changelog.node(i) | 210 n = repo.changelog.node(i) |
216 mask = is_reachable(want_sha1, reachable, n) | 211 mask = is_reachable(want_sha1, reachable, n) |
217 if mask: | 212 if mask: |
218 parentstr = "" | 213 parentstr = "" |
219 if parents: | 214 if parents: |
224 parentstr += " " + hg.short(pp[1]) | 219 parentstr += " " + hg.short(pp[1]) |
225 if not full: | 220 if not full: |
226 print hg.short(n) + parentstr | 221 print hg.short(n) + parentstr |
227 elif full == "commit": | 222 elif full == "commit": |
228 print hg.short(n) + parentstr | 223 print hg.short(n) + parentstr |
229 catcommit(repo, n, ' ', changes) | 224 catcommit(repo, n, ' ', ctx) |
230 else: | 225 else: |
231 (p1, p2) = repo.changelog.parents(n) | 226 (p1, p2) = repo.changelog.parents(n) |
232 (h, h1, h2) = map(hg.short, (n, p1, p2)) | 227 (h, h1, h2) = map(hg.short, (n, p1, p2)) |
233 (i1, i2) = map(repo.changelog.rev, (p1, p2)) | 228 (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
234 | 229 |
235 date = changes[2][0] | 230 date = ctx.date()[0] |
236 print "%s %s:%s" % (date, h, mask), | 231 print "%s %s:%s" % (date, h, mask), |
237 mask = is_reachable(want_sha1, reachable, p1) | 232 mask = is_reachable(want_sha1, reachable, p1) |
238 if i1 != hg.nullrev and mask > 0: | 233 if i1 != hg.nullrev and mask > 0: |
239 print "%s:%s " % (h1, mask), | 234 print "%s:%s " % (h1, mask), |
240 mask = is_reachable(want_sha1, reachable, p2) | 235 mask = is_reachable(want_sha1, reachable, p2) |