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