annotate contrib/hgit @ 719:dda258572847

Fix hgit usage of repo.changes and fancyopts to reflect current hg api
author mason@suse.com
date Tue, 19 Jul 2005 12:40:46 -0500
parents 688d03d6997a
children 095dd8c757e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
1 #!/usr/bin/env python
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
2 #
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
3 # Minimal support for git commands on an hg repository
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
4 #
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
5 # Copyright 2005 Chris Mason <mason@suse.com>
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
6 #
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
7 # This software may be used and distributed according to the terms
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
8 # of the GNU General Public License, incorporated herein by reference.
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
9
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
10 import time, sys, signal
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
11 from mercurial import hg, mdiff, fancyopts, commands, ui
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
12
396
8f8bb77d560e Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 357
diff changeset
13 def difftree(args, ui, repo):
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
14 def __difftree(repo, files = None, node1 = None, node2 = None):
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
15 def date(c):
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
16 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
17
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
18 if node2:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
19 change = repo.changelog.read(node2)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
20 mmap2 = repo.manifest.read(change[0])
719
dda258572847 Fix hgit usage of repo.changes and fancyopts to reflect current hg api
mason@suse.com
parents: 429
diff changeset
21 (c, a, d, u) = repo.changes(node1, node2)
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
22 def read(f): return repo.file(f).read(mmap2[f])
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
23 date2 = date(change)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
24 else:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
25 date2 = time.asctime()
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
26 (c, a, d, u) = repo.diffdir(repo.root, node1)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
27 if not node1:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
28 node1 = repo.dirstate.parents()[0]
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
29 def read(f): return file(os.path.join(repo.root, f)).read()
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
30
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
31 change = repo.changelog.read(node1)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
32 mmap = repo.manifest.read(change[0])
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
33 date1 = date(change)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
34 empty = "0" * 40;
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
35
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
36 if files:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
37 c, a, d = map(lambda x: filterfiles(files, x), (c, a, d))
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
38
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
39 for f in c:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
40 # TODO get file permissions
406
d8abb687d501 [PATCH] Using monotone-viz/git-viz with mercurial
mpm@selenic.com
parents: 396
diff changeset
41 print ":100664 100664 %s %s M\t%s\t%s" % (hg.hex(mmap[f]),
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
42 hg.hex(mmap2[f]), f, f)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
43 for f in a:
406
d8abb687d501 [PATCH] Using monotone-viz/git-viz with mercurial
mpm@selenic.com
parents: 396
diff changeset
44 print ":000000 100664 %s %s N\t%s\t%s" % (empty, hg.hex(mmap2[f]), f, f)
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
45 for f in d:
406
d8abb687d501 [PATCH] Using monotone-viz/git-viz with mercurial
mpm@selenic.com
parents: 396
diff changeset
46 print ":100664 000000 %s %s D\t%s\t%s" % (hg.hex(mmap[f]), empty, f, f)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
47 ##
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
48
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
49 revs = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
50 if args:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
51 doptions = {}
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
52 opts = [('p', 'patch', None, 'patch'),
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
53 ('r', 'recursive', None, 'recursive')]
719
dda258572847 Fix hgit usage of repo.changes and fancyopts to reflect current hg api
mason@suse.com
parents: 429
diff changeset
54 args = fancyopts.fancyopts(args, opts, doptions)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
55
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
56 if len(args) < 2:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
57 help()
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
58 sys.exit(1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
59 revs.append(repo.lookup(args[0]))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
60 revs.append(repo.lookup(args[1]))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
61 args = args[2:]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
62 if doptions['patch']:
719
dda258572847 Fix hgit usage of repo.changes and fancyopts to reflect current hg api
mason@suse.com
parents: 429
diff changeset
63 commands.dodiff(sys.stdout, ui, repo, args, *revs)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
64 else:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
65 __difftree(repo, args, *revs)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
66
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
67 def catcommit(repo, n, prefix):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
68 nlprefix = '\n' + prefix;
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
69 changes = repo.changelog.read(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
70 (p1, p2) = repo.changelog.parents(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
71 (h, h1, h2) = map(hg.hex, (n, p1, p2))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
72 (i1, i2) = map(repo.changelog.rev, (p1, p2))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
73 print "tree %s" % (h)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
74 if i1 != -1: print "%sparent %s" % (prefix, h1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
75 if i2 != -1: print "%sparent %s" % (prefix, h2)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
76 date_ar = changes[2].split(' ')
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
77 date = int(float(date_ar[0]))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
78 print "%sauthor <%s> %s %s" % (prefix, changes[1], date, date_ar[1])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
79 print "%scommitter <%s> %s %s" % (prefix, changes[1], date, date_ar[1])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
80 print prefix
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
81 if prefix != "":
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
82 print "%s%s" % (prefix, changes[4].replace('\n', nlprefix).strip())
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
83 else:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
84 print changes[4]
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
85
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
86 def catfile(args, ui, repo):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
87 doptions = {}
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
88 opts = [('s', 'stdin', None, 'stdin')]
719
dda258572847 Fix hgit usage of repo.changes and fancyopts to reflect current hg api
mason@suse.com
parents: 429
diff changeset
89 args = fancyopts.fancyopts(args, opts, doptions)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
90
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
91 # in stdin mode, every line except the commit is prefixed with two
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
92 # spaces. This way the our caller can find the commit without magic
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
93 # strings
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
94 #
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
95 prefix = ""
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
96 if doptions['stdin']:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
97 try:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
98 (type, r) = raw_input().split(' ');
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
99 prefix = " "
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
100 except EOFError:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
101 return
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
102
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
103 else:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
104 if len(args) < 2:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
105 help()
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
106 sys.exit(1)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
107 type = args[0]
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
108 r = args[1]
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
109
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
110 while r:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
111 if type != "commit":
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
112 sys.stderr.write("aborting hg cat-file only understands commits\n")
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
113 sys.exit(1);
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
114 n = repo.changelog.lookup(r)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
115 catcommit(repo, n, prefix)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
116 if doptions['stdin']:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
117 try:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
118 (type, r) = raw_input().split(' ');
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
119 except EOFError:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
120 break
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
121 else:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
122 break
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
123
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
124 # git rev-tree is a confusing thing. You can supply a number of
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
125 # commit sha1s on the command line, and it walks the commit history
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
126 # telling you which commits are reachable from the supplied ones via
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
127 # a bitmask based on arg position.
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
128 # you can specify a commit to stop at by starting the sha1 with ^
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
129 def revtree(args, repo, full="tree", maxnr=0):
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
130 # calculate and return the reachability bitmask for sha
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
131 def is_reachable(ar, reachable, sha):
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
132 if len(ar) == 0:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
133 return 1
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
134 mask = 0
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
135 for i in range(len(ar)):
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
136 if sha in reachable[i]:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
137 mask |= 1 << i
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
138
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
139 return mask
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
140
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
141 reachable = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
142 stop_sha1 = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
143 want_sha1 = []
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
144 count = 0
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
145
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
146 # figure out which commits they are asking for and which ones they
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
147 # want us to stop on
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
148 for i in range(len(args)):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
149 if args[i].count('^'):
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
150 s = args[i].split('^')[1]
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
151 stop_sha1.append(repo.changelog.lookup(s))
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
152 want_sha1.append(s)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
153 elif args[i] != 'HEAD':
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
154 want_sha1.append(args[i])
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
155
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
156 # calculate the graph for the supplied commits
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
157 for i in range(len(want_sha1)):
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
158 reachable.append({});
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
159 n = repo.changelog.lookup(want_sha1[i]);
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
160 visit = [n];
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
161 reachable[i][n] = 1
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
162 while visit:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
163 n = visit.pop(0)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
164 if n in stop_sha1:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
165 break
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
166 for p in repo.changelog.parents(n):
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
167 if p not in reachable[i]:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
168 reachable[i][p] = 1
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
169 visit.append(p)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
170 if p in stop_sha1:
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
171 break
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
172
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
173 # walk the repository looking for commits that are in our
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
174 # reachability graph
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
175 for i in range(repo.changelog.count()-1, -1, -1):
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
176 n = repo.changelog.node(i)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
177 mask = is_reachable(want_sha1, reachable, n)
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
178 if mask:
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
179 if not full:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
180 print hg.hex(n)
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
181 elif full is "commit":
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
182 print hg.hex(n)
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
183 catcommit(repo, n, ' ')
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
184 else:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
185 changes = repo.changelog.read(n)
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
186 (p1, p2) = repo.changelog.parents(n)
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
187 (h, h1, h2) = map(hg.hex, (n, p1, p2))
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
188 (i1, i2) = map(repo.changelog.rev, (p1, p2))
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
189
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
190 date = changes[2].split(' ')[0]
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
191 print "%s %s:%s" % (date, h, mask),
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
192 mask = is_reachable(want_sha1, reachable, p1)
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
193 if i1 != -1 and mask > 0:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
194 print "%s:%s " % (h1, mask),
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
195 mask = is_reachable(want_sha1, reachable, p2)
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
196 if i2 != -1 and mask > 0:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
197 print "%s:%s " % (h2, mask),
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
198 print ""
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
199 if maxnr and count >= maxnr:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
200 break
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
201 count += 1
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
202
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
203 # git rev-list tries to order things by date, and has the ability to stop
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
204 # at a given commit without walking the whole repo. TODO add the stop
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
205 # parameter
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
206 def revlist(args, repo):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
207 doptions = {}
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
208 opts = [('c', 'commit', None, 'commit'),
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
209 ('n', 'max-nr', 0, 'max-nr')]
719
dda258572847 Fix hgit usage of repo.changes and fancyopts to reflect current hg api
mason@suse.com
parents: 429
diff changeset
210 args = fancyopts.fancyopts(args, opts, doptions)
356
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
211 if doptions['commit']:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
212 full = "commit"
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
213 else:
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
214 full = None
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
215 for i in range(1, len(args)):
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
216 args[i] = '^' + args[i]
7dec9a46d82a hgit rev-list support
mpm@selenic.com
parents: 350
diff changeset
217 revtree(args, repo, full, doptions['max-nr'])
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
218
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
219 def catchterm(*args):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
220 raise SignalInterrupt
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
221
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
222 def help():
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
223 sys.stderr.write("commands:\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
224 sys.stderr.write(" hgit cat-file [type] sha1\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
225 sys.stderr.write(" hgit diff-tree [-p] [-r] sha1 sha1\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
226 sys.stderr.write(" hgit rev-tree [sha1 ... [^stop sha1]]\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
227 sys.stderr.write(" hgit rev-list [-c]\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
228
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
229 cmd = sys.argv[1]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
230 args = sys.argv[2:]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
231 u = ui.ui()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
232 signal.signal(signal.SIGTERM, catchterm)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
233 repo = hg.repository(ui = u)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
234
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
235 if cmd == "diff-tree":
396
8f8bb77d560e Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 357
diff changeset
236 difftree(args, u, repo)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
237
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
238 elif cmd == "cat-file":
396
8f8bb77d560e Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 357
diff changeset
239 catfile(args, u, repo)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
240
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
241 elif cmd == "rev-tree":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
242 revtree(args, repo)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
243
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
244 elif cmd == "rev-list":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
245 revlist(args, repo)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
246
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
247 elif cmd == "help":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
248 help()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
249
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
250 else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
251 if cmd: sys.stderr.write("unknown command\n\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
252 help()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
253 sys.exit(1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
254
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
255 sys.exit(0)