Mercurial > hg
annotate hgext/hgk.py @ 3059:3dab573a4330
hgk: use short changeset hashes
this fixes the missing tags on hgk window
author | TK Soh <teekaysoh@yahoo.com> |
---|---|
date | Thu, 24 Aug 2006 16:12:23 -0500 |
parents | abcd6ae3cf5a |
children | aa1cee5b8afb |
rev | line source |
---|---|
267 | 1 # Minimal support for git commands on an hg repository |
2 # | |
2859 | 3 # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
267 | 4 # |
5 # This software may be used and distributed according to the terms | |
6 # of the GNU General Public License, incorporated herein by reference. | |
7 | |
2908
2497fa1c6b76
Use demandload in hgk
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2744
diff
changeset
|
8 from mercurial.demandload import * |
2497fa1c6b76
Use demandload in hgk
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2744
diff
changeset
|
9 demandload(globals(), 'time sys signal os') |
2497fa1c6b76
Use demandload in hgk
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2744
diff
changeset
|
10 demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util') |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
11 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
12 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
13 changes=None, text=False): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
14 def date(c): |
1344 | 15 return time.asctime(time.gmtime(c[2][0])) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
16 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
17 if not changes: |
2875
3d6efcbbd1c9
remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
18 changes = repo.status(node1, node2, files, match=match)[:5] |
1619
1ba0d7041ac4
Distinguish removed and deleted files. Tests are not fixed yet.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1618
diff
changeset
|
19 modified, added, removed, deleted, unknown = changes |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
20 if files: |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
21 modified, added, removed = map(lambda x: filterfiles(files, x), |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
22 (modified, added, removed)) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
23 |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
24 if not modified and not added and not removed: |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
25 return |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
26 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
27 if node2: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
28 change = repo.changelog.read(node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
29 mmap2 = repo.manifest.read(change[0]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
30 date2 = date(change) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
31 def read(f): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
32 return repo.file(f).read(mmap2[f]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
33 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
34 date2 = time.asctime() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
35 if not node1: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
36 node1 = repo.dirstate.parents()[0] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
37 def read(f): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
38 return repo.wfile(f).read() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
39 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
40 change = repo.changelog.read(node1) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
41 mmap = repo.manifest.read(change[0]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
42 date1 = date(change) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
43 |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
44 for f in modified: |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
45 to = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
46 if f in mmap: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
47 to = repo.file(f).read(mmap[f]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
48 tn = read(f) |
3012
abcd6ae3cf5a
Fix hgk extension due to 4ec58b157265 refactoring
Edouard Gomez <ed.gomez@free.fr>
parents:
2909
diff
changeset
|
49 opts = mdiff.diffopts() |
abcd6ae3cf5a
Fix hgk extension due to 4ec58b157265 refactoring
Edouard Gomez <ed.gomez@free.fr>
parents:
2909
diff
changeset
|
50 opts.text = text |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
51 fp.write("diff --git a/%s b/%s\n" % (f, f)) |
3012
abcd6ae3cf5a
Fix hgk extension due to 4ec58b157265 refactoring
Edouard Gomez <ed.gomez@free.fr>
parents:
2909
diff
changeset
|
52 fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts)) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
53 for f in added: |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
54 to = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
55 tn = read(f) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
56 fp.write("diff --git /dev/null b/%s\n" % (f)) |
3012
abcd6ae3cf5a
Fix hgk extension due to 4ec58b157265 refactoring
Edouard Gomez <ed.gomez@free.fr>
parents:
2909
diff
changeset
|
57 fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts)) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
58 for f in removed: |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
59 to = repo.file(f).read(mmap[f]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
60 tn = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
61 fp.write("diff --git a/%s /dev/null\n" % (f)) |
3012
abcd6ae3cf5a
Fix hgk extension due to 4ec58b157265 refactoring
Edouard Gomez <ed.gomez@free.fr>
parents:
2909
diff
changeset
|
62 fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, opts=opts)) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
63 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
64 def difftree(ui, repo, node1=None, node2=None, **opts): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
65 """diff trees from two commits""" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
66 def __difftree(repo, node1, node2): |
334 | 67 def date(c): |
1344 | 68 return time.asctime(time.gmtime(c[2][0])) |
267 | 69 |
334 | 70 if node2: |
71 change = repo.changelog.read(node2) | |
72 mmap2 = repo.manifest.read(change[0]) | |
2875
3d6efcbbd1c9
remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
73 modified, added, removed, deleted, unknown = repo.status(node1, node2)[:5] |
334 | 74 def read(f): return repo.file(f).read(mmap2[f]) |
75 date2 = date(change) | |
76 else: | |
77 date2 = time.asctime() | |
2875
3d6efcbbd1c9
remove localrepository.changes.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
78 modified, added, removed, deleted, unknown = repo.status(node1)[:5] |
334 | 79 if not node1: |
80 node1 = repo.dirstate.parents()[0] | |
81 def read(f): return file(os.path.join(repo.root, f)).read() | |
267 | 82 |
334 | 83 change = repo.changelog.read(node1) |
84 mmap = repo.manifest.read(change[0]) | |
85 date1 = date(change) | |
86 empty = "0" * 40; | |
267 | 87 |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
88 for f in modified: |
334 | 89 # TODO get file permissions |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
90 print ":100664 100664 %s %s M\t%s\t%s" % (hg.short(mmap[f]), |
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
91 hg.short(mmap2[f]), |
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
92 f, f) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
93 for f in added: |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
94 print ":000000 100664 %s %s N\t%s\t%s" % (empty, |
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
95 hg.short(mmap2[f]), |
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
96 f, f) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1614
diff
changeset
|
97 for f in removed: |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
98 print ":100664 000000 %s %s D\t%s\t%s" % (hg.short(mmap[f]), |
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
99 empty, |
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
100 f, f) |
267 | 101 ## |
102 | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
103 while True: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
104 if opts['stdin']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
105 try: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
106 line = raw_input().split(' ') |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
107 node1 = line[0] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
108 if len(line) > 1: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
109 node2 = line[1] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
110 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
111 node2 = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
112 except EOFError: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
113 break |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
114 node1 = repo.lookup(node1) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
115 if node2: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
116 node2 = repo.lookup(node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
117 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
118 node2 = node1 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
119 node1 = repo.changelog.parents(node1)[0] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
120 if opts['patch']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
121 if opts['pretty']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
122 catcommit(repo, node2, "") |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
123 dodiff(sys.stdout, ui, repo, node1, node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
124 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
125 __difftree(repo, node1, node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
126 if not opts['stdin']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
127 break |
267 | 128 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
129 def catcommit(repo, n, prefix, changes=None): |
267 | 130 nlprefix = '\n' + prefix; |
131 (p1, p2) = repo.changelog.parents(n) | |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
132 (h, h1, h2) = map(hg.short, (n, p1, p2)) |
267 | 133 (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
134 if not changes: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
135 changes = repo.changelog.read(n) |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
136 print "tree %s" % (hg.short(changes[0])) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
137 if i1 != -1: print "parent %s" % (h1) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
138 if i2 != -1: print "parent %s" % (h2) |
1344 | 139 date_ar = changes[2] |
267 | 140 date = int(float(date_ar[0])) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
141 lines = changes[4].splitlines() |
2525
c49dc6f38a19
hgk: Don't choke on empty changelogs
Brendan Cully <brendan@kublai.com>
parents:
2432
diff
changeset
|
142 if lines and lines[-1].startswith('committer:'): |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
143 committer = lines[-1].split(': ')[1].rstrip() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
144 else: |
1950
5f581f337b05
hgk "committer:" bug
Hollis Blanchard <hollisb@us.ibm.com>
parents:
1626
diff
changeset
|
145 committer = changes[1] |
1308
2073e5a71008
Cleanup of tabs and trailing spaces.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1278
diff
changeset
|
146 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
147 print "author %s %s %s" % (changes[1], date, date_ar[1]) |
1950
5f581f337b05
hgk "committer:" bug
Hollis Blanchard <hollisb@us.ibm.com>
parents:
1626
diff
changeset
|
148 print "committer %s %s %s" % (committer, date, date_ar[1]) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
149 print "" |
267 | 150 if prefix != "": |
334 | 151 print "%s%s" % (prefix, changes[4].replace('\n', nlprefix).strip()) |
267 | 152 else: |
334 | 153 print changes[4] |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
154 if prefix: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
155 sys.stdout.write('\0') |
267 | 156 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
157 def base(ui, repo, node1, node2): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
158 """Output common ancestor information""" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
159 node1 = repo.lookup(node1) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
160 node2 = repo.lookup(node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
161 n = repo.changelog.ancestor(node1, node2) |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
162 print hg.short(n) |
267 | 163 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
164 def catfile(ui, repo, type=None, r=None, **opts): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
165 """cat a specific revision""" |
267 | 166 # in stdin mode, every line except the commit is prefixed with two |
167 # spaces. This way the our caller can find the commit without magic | |
168 # strings | |
169 # | |
170 prefix = "" | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
171 if opts['stdin']: |
334 | 172 try: |
173 (type, r) = raw_input().split(' '); | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
174 prefix = " " |
334 | 175 except EOFError: |
176 return | |
267 | 177 |
178 else: | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
179 if not type or not r: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
180 ui.warn("cat-file: type or revision not supplied\n") |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
181 commands.help_(ui, 'cat-file') |
267 | 182 |
183 while r: | |
334 | 184 if type != "commit": |
185 sys.stderr.write("aborting hg cat-file only understands commits\n") | |
186 sys.exit(1); | |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
187 n = repo.lookup(r) |
334 | 188 catcommit(repo, n, prefix) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
189 if opts['stdin']: |
334 | 190 try: |
191 (type, r) = raw_input().split(' '); | |
192 except EOFError: | |
193 break | |
194 else: | |
195 break | |
267 | 196 |
197 # git rev-tree is a confusing thing. You can supply a number of | |
198 # commit sha1s on the command line, and it walks the commit history | |
199 # telling you which commits are reachable from the supplied ones via | |
200 # a bitmask based on arg position. | |
201 # you can specify a commit to stop at by starting the sha1 with ^ | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
202 def revtree(args, repo, full="tree", maxnr=0, parents=False): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
203 def chlogwalk(): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
204 ch = repo.changelog |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
205 count = ch.count() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
206 i = count |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
207 l = [0] * 100 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
208 chunk = 100 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
209 while True: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
210 if chunk > i: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
211 chunk = i |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
212 i = 0 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
213 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
214 i -= chunk |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
215 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
216 for x in xrange(0, chunk): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
217 if i + x >= count: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
218 l[chunk - x:] = [0] * (chunk - x) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
219 break |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
220 if full != None: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
221 l[x] = ch.read(ch.node(i + x)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
222 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
223 l[x] = 1 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
224 for x in xrange(chunk-1, -1, -1): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
225 if l[x] != 0: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
226 yield (i + x, full != None and l[x] or None) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
227 if i == 0: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
228 break |
1308
2073e5a71008
Cleanup of tabs and trailing spaces.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1278
diff
changeset
|
229 |
267 | 230 # calculate and return the reachability bitmask for sha |
231 def is_reachable(ar, reachable, sha): | |
334 | 232 if len(ar) == 0: |
233 return 1 | |
234 mask = 0 | |
235 for i in range(len(ar)): | |
236 if sha in reachable[i]: | |
237 mask |= 1 << i | |
267 | 238 |
334 | 239 return mask |
267 | 240 |
241 reachable = [] | |
242 stop_sha1 = [] | |
243 want_sha1 = [] | |
356 | 244 count = 0 |
267 | 245 |
246 # figure out which commits they are asking for and which ones they | |
247 # want us to stop on | |
248 for i in range(len(args)): | |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
249 if args[i].startswith('^'): |
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
250 s = repo.lookup(args[i][1:]) |
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
251 stop_sha1.append(s) |
334 | 252 want_sha1.append(s) |
253 elif args[i] != 'HEAD': | |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
254 want_sha1.append(repo.lookup(args[i])) |
356 | 255 |
267 | 256 # calculate the graph for the supplied commits |
257 for i in range(len(want_sha1)): | |
334 | 258 reachable.append({}); |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
259 n = want_sha1[i]; |
334 | 260 visit = [n]; |
261 reachable[i][n] = 1 | |
262 while visit: | |
263 n = visit.pop(0) | |
264 if n in stop_sha1: | |
1243
9d10f89b75a5
Fix hgit revtree bug with stop revision handling
root@coffee.suse.com
parents:
1239
diff
changeset
|
265 continue |
334 | 266 for p in repo.changelog.parents(n): |
267 if p not in reachable[i]: | |
268 reachable[i][p] = 1 | |
269 visit.append(p) | |
270 if p in stop_sha1: | |
1243
9d10f89b75a5
Fix hgit revtree bug with stop revision handling
root@coffee.suse.com
parents:
1239
diff
changeset
|
271 continue |
356 | 272 |
267 | 273 # walk the repository looking for commits that are in our |
274 # reachability graph | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
275 #for i in range(repo.changelog.count()-1, -1, -1): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
276 for i, changes in chlogwalk(): |
334 | 277 n = repo.changelog.node(i) |
278 mask = is_reachable(want_sha1, reachable, n) | |
279 if mask: | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
280 parentstr = "" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
281 if parents: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
282 pp = repo.changelog.parents(n) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
283 if pp[0] != hg.nullid: |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
284 parentstr += " " + hg.short(pp[0]) |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
285 if pp[1] != hg.nullid: |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
286 parentstr += " " + hg.short(pp[1]) |
356 | 287 if not full: |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
288 print hg.short(n) + parentstr |
356 | 289 elif full is "commit": |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
290 print hg.short(n) + parentstr |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
291 catcommit(repo, n, ' ', changes) |
356 | 292 else: |
293 (p1, p2) = repo.changelog.parents(n) | |
3059
3dab573a4330
hgk: use short changeset hashes
TK Soh <teekaysoh@yahoo.com>
parents:
3012
diff
changeset
|
294 (h, h1, h2) = map(hg.short, (n, p1, p2)) |
356 | 295 (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
267 | 296 |
1344 | 297 date = changes[2][0] |
356 | 298 print "%s %s:%s" % (date, h, mask), |
299 mask = is_reachable(want_sha1, reachable, p1) | |
300 if i1 != -1 and mask > 0: | |
301 print "%s:%s " % (h1, mask), | |
302 mask = is_reachable(want_sha1, reachable, p2) | |
303 if i2 != -1 and mask > 0: | |
304 print "%s:%s " % (h2, mask), | |
305 print "" | |
306 if maxnr and count >= maxnr: | |
307 break | |
308 count += 1 | |
267 | 309 |
310 # git rev-list tries to order things by date, and has the ability to stop | |
311 # at a given commit without walking the whole repo. TODO add the stop | |
312 # parameter | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
313 def revlist(ui, repo, *revs, **opts): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
314 """print revisions""" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
315 if opts['header']: |
356 | 316 full = "commit" |
317 else: | |
318 full = None | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
319 copy = [x for x in revs] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
320 revtree(copy, repo, full, opts['max_count'], opts['parents']) |
267 | 321 |
1278 | 322 def view(ui, repo, *etc): |
323 "start interactive history viewer" | |
324 os.chdir(repo.root) | |
1345
c5594ff3f95c
hgk: Allow specifying hgk path in [hgk]path
mpm@selenic.com
parents:
1344
diff
changeset
|
325 os.system(ui.config("hgk", "path", "hgk") + " " + " ".join(etc)) |
1278 | 326 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
327 cmdtable = { |
1278 | 328 "view": (view, [], 'hg view'), |
329 "debug-diff-tree": (difftree, [('p', 'patch', None, 'generate patch'), | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
330 ('r', 'recursive', None, 'recursive'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
331 ('P', 'pretty', None, 'pretty'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
332 ('s', 'stdin', None, 'stdin'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
333 ('C', 'copy', None, 'detect copies'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
334 ('S', 'search', "", 'search')], |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
335 "hg git-diff-tree [options] node1 node2"), |
1278 | 336 "debug-cat-file": (catfile, [('s', 'stdin', None, 'stdin')], |
337 "hg debug-cat-file [options] type file"), | |
338 "debug-merge-base": (base, [], "hg debug-merge-base node node"), | |
339 "debug-rev-list": (revlist, [('H', 'header', None, 'header'), | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
340 ('t', 'topo-order', None, 'topo-order'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
341 ('p', 'parents', None, 'parents'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
342 ('n', 'max-count', 0, 'max-count')], |
1278 | 343 "hg debug-rev-list [options] revs"), |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
344 } |