Mercurial > hg
comparison hgext/hgk.py @ 6217:fe8dbbe9520d
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
author | Joel Rosdahl <joel@rosdahl.net> |
---|---|
date | Thu, 06 Mar 2008 22:51:16 +0100 |
parents | e75aab656f46 |
children | cd4db3999ef9 |
comparison
equal
deleted
inserted
replaced
6216:a88259018f79 | 6217:fe8dbbe9520d |
---|---|
44 # | 44 # |
45 # Revisions context menu will now display additional entries to fire | 45 # Revisions context menu will now display additional entries to fire |
46 # vdiff on hovered and selected revisions. | 46 # vdiff on hovered and selected revisions. |
47 | 47 |
48 import os | 48 import os |
49 from mercurial import hg, commands, util, patch, revlog | 49 from mercurial import commands, util, patch, revlog |
50 from mercurial.node import nullid, nullrev, short | |
50 | 51 |
51 def difftree(ui, repo, node1=None, node2=None, *files, **opts): | 52 def difftree(ui, repo, node1=None, node2=None, *files, **opts): |
52 """diff trees from two commits""" | 53 """diff trees from two commits""" |
53 def __difftree(repo, node1, node2, files=[]): | 54 def __difftree(repo, node1, node2, files=[]): |
54 assert node2 is not None | 55 assert node2 is not None |
55 mmap = repo.changectx(node1).manifest() | 56 mmap = repo.changectx(node1).manifest() |
56 mmap2 = repo.changectx(node2).manifest() | 57 mmap2 = repo.changectx(node2).manifest() |
57 status = repo.status(node1, node2, files=files)[:5] | 58 status = repo.status(node1, node2, files=files)[:5] |
58 modified, added, removed, deleted, unknown = status | 59 modified, added, removed, deleted, unknown = status |
59 | 60 |
60 empty = hg.short(hg.nullid) | 61 empty = short(nullid) |
61 | 62 |
62 for f in modified: | 63 for f in modified: |
63 # TODO get file permissions | 64 # TODO get file permissions |
64 ui.write(":100664 100664 %s %s M\t%s\t%s\n" % | 65 ui.write(":100664 100664 %s %s M\t%s\t%s\n" % |
65 (hg.short(mmap[f]), hg.short(mmap2[f]), f, f)) | 66 (short(mmap[f]), short(mmap2[f]), f, f)) |
66 for f in added: | 67 for f in added: |
67 ui.write(":000000 100664 %s %s N\t%s\t%s\n" % | 68 ui.write(":000000 100664 %s %s N\t%s\t%s\n" % |
68 (empty, hg.short(mmap2[f]), f, f)) | 69 (empty, short(mmap2[f]), f, f)) |
69 for f in removed: | 70 for f in removed: |
70 ui.write(":100664 000000 %s %s D\t%s\t%s\n" % | 71 ui.write(":100664 000000 %s %s D\t%s\t%s\n" % |
71 (hg.short(mmap[f]), empty, f, f)) | 72 (short(mmap[f]), empty, f, f)) |
72 ## | 73 ## |
73 | 74 |
74 while True: | 75 while True: |
75 if opts['stdin']: | 76 if opts['stdin']: |
76 try: | 77 try: |
102 def catcommit(ui, repo, n, prefix, ctx=None): | 103 def catcommit(ui, repo, n, prefix, ctx=None): |
103 nlprefix = '\n' + prefix; | 104 nlprefix = '\n' + prefix; |
104 if ctx is None: | 105 if ctx is None: |
105 ctx = repo.changectx(n) | 106 ctx = repo.changectx(n) |
106 (p1, p2) = ctx.parents() | 107 (p1, p2) = ctx.parents() |
107 ui.write("tree %s\n" % hg.short(ctx.changeset()[0])) # use ctx.node() instead ?? | 108 ui.write("tree %s\n" % short(ctx.changeset()[0])) # use ctx.node() instead ?? |
108 if p1: ui.write("parent %s\n" % hg.short(p1.node())) | 109 if p1: ui.write("parent %s\n" % short(p1.node())) |
109 if p2: ui.write("parent %s\n" % hg.short(p2.node())) | 110 if p2: ui.write("parent %s\n" % short(p2.node())) |
110 date = ctx.date() | 111 date = ctx.date() |
111 description = ctx.description().replace("\0", "") | 112 description = ctx.description().replace("\0", "") |
112 lines = description.splitlines() | 113 lines = description.splitlines() |
113 if lines and lines[-1].startswith('committer:'): | 114 if lines and lines[-1].startswith('committer:'): |
114 committer = lines[-1].split(': ')[1].rstrip() | 115 committer = lines[-1].split(': ')[1].rstrip() |
130 def base(ui, repo, node1, node2): | 131 def base(ui, repo, node1, node2): |
131 """Output common ancestor information""" | 132 """Output common ancestor information""" |
132 node1 = repo.lookup(node1) | 133 node1 = repo.lookup(node1) |
133 node2 = repo.lookup(node2) | 134 node2 = repo.lookup(node2) |
134 n = repo.changelog.ancestor(node1, node2) | 135 n = repo.changelog.ancestor(node1, node2) |
135 ui.write(hg.short(n) + "\n") | 136 ui.write(short(n) + "\n") |
136 | 137 |
137 def catfile(ui, repo, type=None, r=None, **opts): | 138 def catfile(ui, repo, type=None, r=None, **opts): |
138 """cat a specific revision""" | 139 """cat a specific revision""" |
139 # in stdin mode, every line except the commit is prefixed with two | 140 # in stdin mode, every line except the commit is prefixed with two |
140 # spaces. This way the our caller can find the commit without magic | 141 # spaces. This way the our caller can find the commit without magic |
250 mask = is_reachable(want_sha1, reachable, n) | 251 mask = is_reachable(want_sha1, reachable, n) |
251 if mask: | 252 if mask: |
252 parentstr = "" | 253 parentstr = "" |
253 if parents: | 254 if parents: |
254 pp = repo.changelog.parents(n) | 255 pp = repo.changelog.parents(n) |
255 if pp[0] != hg.nullid: | 256 if pp[0] != nullid: |
256 parentstr += " " + hg.short(pp[0]) | 257 parentstr += " " + short(pp[0]) |
257 if pp[1] != hg.nullid: | 258 if pp[1] != nullid: |
258 parentstr += " " + hg.short(pp[1]) | 259 parentstr += " " + short(pp[1]) |
259 if not full: | 260 if not full: |
260 ui.write("%s%s\n" % (hg.short(n), parentstr)) | 261 ui.write("%s%s\n" % (short(n), parentstr)) |
261 elif full == "commit": | 262 elif full == "commit": |
262 ui.write("%s%s\n" % (hg.short(n), parentstr)) | 263 ui.write("%s%s\n" % (short(n), parentstr)) |
263 catcommit(ui, repo, n, ' ', ctx) | 264 catcommit(ui, repo, n, ' ', ctx) |
264 else: | 265 else: |
265 (p1, p2) = repo.changelog.parents(n) | 266 (p1, p2) = repo.changelog.parents(n) |
266 (h, h1, h2) = map(hg.short, (n, p1, p2)) | 267 (h, h1, h2) = map(short, (n, p1, p2)) |
267 (i1, i2) = map(repo.changelog.rev, (p1, p2)) | 268 (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
268 | 269 |
269 date = ctx.date()[0] | 270 date = ctx.date()[0] |
270 ui.write("%s %s:%s" % (date, h, mask)) | 271 ui.write("%s %s:%s" % (date, h, mask)) |
271 mask = is_reachable(want_sha1, reachable, p1) | 272 mask = is_reachable(want_sha1, reachable, p1) |
272 if i1 != hg.nullrev and mask > 0: | 273 if i1 != nullrev and mask > 0: |
273 ui.write("%s:%s " % (h1, mask)), | 274 ui.write("%s:%s " % (h1, mask)), |
274 mask = is_reachable(want_sha1, reachable, p2) | 275 mask = is_reachable(want_sha1, reachable, p2) |
275 if i2 != hg.nullrev and mask > 0: | 276 if i2 != nullrev and mask > 0: |
276 ui.write("%s:%s " % (h2, mask)) | 277 ui.write("%s:%s " % (h2, mask)) |
277 ui.write("\n") | 278 ui.write("\n") |
278 if maxnr and count >= maxnr: | 279 if maxnr and count >= maxnr: |
279 break | 280 break |
280 count += 1 | 281 count += 1 |