Mercurial > hg > mercurial-crew-with-dirclash
annotate contrib/hgit @ 1270:fc3b41570082
Switch to new syntax for .hgignore files.
Here is the new syntax, in summary.
Trailing white space is dropped.
The escape character is "\".
Comments start with #.
Empty lines are skipped.
Lines can be of the following formats:
syntax: regexp # defaults following lines to non-rooted regexps
syntax: glob # defaults following lines to non-rooted globs
re:pattern # non-rooted regular expression
glob:pattern # non-rooted glob
pattern # pattern of the current default type
The default pattern type is regexp, which is completely backwards
compatible with the old hgignore syntax.
In the dirstate class, the ignore method has been reworked to be based
on the util.matcher function, by way of a new dirstate.hgignore
method.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sat, 17 Sep 2005 00:27:27 -0700 |
parents | 9d10f89b75a5 |
children |
rev | line source |
---|---|
267 | 1 #!/usr/bin/env python |
2 # | |
3 # Minimal support for git commands on an hg repository | |
4 # | |
5 # Copyright 2005 Chris Mason <mason@suse.com> | |
6 # | |
7 # This software may be used and distributed according to the terms | |
8 # of the GNU General Public License, incorporated herein by reference. | |
9 | |
10 import time, sys, signal | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
11 from mercurial import hg, mdiff, fancyopts, commands, ui, util |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
12 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
13 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
|
14 changes=None, text=False): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
15 def date(c): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
16 return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
17 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
18 if not changes: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
19 (c, a, d, u) = repo.changes(node1, node2, files, match=match) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
20 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
21 (c, a, d, u) = changes |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
22 if files: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
23 c, a, d = map(lambda x: filterfiles(files, x), (c, a, d)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
24 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
25 if not c and not a and not d: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
26 return |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
27 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
28 if node2: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
29 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
|
30 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
|
31 date2 = date(change) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
32 def read(f): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
33 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
|
34 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
35 date2 = time.asctime() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
36 if not node1: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
37 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
|
38 def read(f): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
39 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
|
40 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
41 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
|
42 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
|
43 date1 = date(change) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
44 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
45 for f in c: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
46 to = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
47 if f in mmap: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
48 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
|
49 tn = read(f) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
50 fp.write("diff --git a/%s b/%s\n" % (f, f)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
51 fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, text=text)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
52 for f in a: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
53 to = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
54 tn = read(f) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
55 fp.write("diff --git /dev/null b/%s\n" % (f)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
56 fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, text=text)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
57 for f in d: |
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 = None |
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 /dev/null\n" % (f)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
61 fp.write(mdiff.unidiff(to, date1, tn, date2, f, None, text=text)) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
62 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
63 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
|
64 """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
|
65 def __difftree(repo, node1, node2): |
334 | 66 def date(c): |
67 return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) | |
267 | 68 |
334 | 69 if node2: |
70 change = repo.changelog.read(node2) | |
71 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
|
72 (c, a, d, u) = repo.changes(node1, node2) |
334 | 73 def read(f): return repo.file(f).read(mmap2[f]) |
74 date2 = date(change) | |
75 else: | |
76 date2 = time.asctime() | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
77 (c, a, d, u) = repo.changes(node1, None) |
334 | 78 if not node1: |
79 node1 = repo.dirstate.parents()[0] | |
80 def read(f): return file(os.path.join(repo.root, f)).read() | |
267 | 81 |
334 | 82 change = repo.changelog.read(node1) |
83 mmap = repo.manifest.read(change[0]) | |
84 date1 = date(change) | |
85 empty = "0" * 40; | |
267 | 86 |
334 | 87 for f in c: |
88 # TODO get file permissions | |
406
d8abb687d501
[PATCH] Using monotone-viz/git-viz with mercurial
mpm@selenic.com
parents:
396
diff
changeset
|
89 print ":100664 100664 %s %s M\t%s\t%s" % (hg.hex(mmap[f]), |
334 | 90 hg.hex(mmap2[f]), f, f) |
91 for f in a: | |
406
d8abb687d501
[PATCH] Using monotone-viz/git-viz with mercurial
mpm@selenic.com
parents:
396
diff
changeset
|
92 print ":000000 100664 %s %s N\t%s\t%s" % (empty, hg.hex(mmap2[f]), f, f) |
334 | 93 for f in d: |
406
d8abb687d501
[PATCH] Using monotone-viz/git-viz with mercurial
mpm@selenic.com
parents:
396
diff
changeset
|
94 print ":100664 000000 %s %s D\t%s\t%s" % (hg.hex(mmap[f]), empty, f, f) |
267 | 95 ## |
96 | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
97 while True: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
98 if opts['stdin']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
99 try: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
100 line = raw_input().split(' ') |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
101 node1 = line[0] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
102 if len(line) > 1: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
103 node2 = line[1] |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
104 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
105 node2 = None |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
106 except EOFError: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
107 break |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
108 node1 = repo.lookup(node1) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
109 if node2: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
110 node2 = repo.lookup(node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
111 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
112 node2 = node1 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
113 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
|
114 if opts['patch']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
115 if opts['pretty']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
116 catcommit(repo, node2, "") |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
117 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
|
118 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
119 __difftree(repo, node1, node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
120 if not opts['stdin']: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
121 break |
267 | 122 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
123 def catcommit(repo, n, prefix, changes=None): |
267 | 124 nlprefix = '\n' + prefix; |
125 (p1, p2) = repo.changelog.parents(n) | |
126 (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
127 (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
|
128 if not changes: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
129 changes = repo.changelog.read(n) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
130 print "tree %s" % (hg.hex(changes[0])) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
131 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
|
132 if i2 != -1: print "parent %s" % (h2) |
267 | 133 date_ar = changes[2].split(' ') |
134 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
|
135 lines = changes[4].splitlines() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
136 if lines[-1].startswith('committer:'): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
137 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
|
138 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
139 committer = "%s %s %s" % (changes[1], date, date_ar[1]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
140 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
141 print "author %s %s %s" % (changes[1], date, date_ar[1]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
142 print "committer %s" % (committer) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
143 print "" |
267 | 144 if prefix != "": |
334 | 145 print "%s%s" % (prefix, changes[4].replace('\n', nlprefix).strip()) |
267 | 146 else: |
334 | 147 print changes[4] |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
148 if prefix: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
149 sys.stdout.write('\0') |
267 | 150 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
151 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
|
152 """Output common ancestor information""" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
153 node1 = repo.lookup(node1) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
154 node2 = repo.lookup(node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
155 n = repo.changelog.ancestor(node1, node2) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
156 print hg.hex(n) |
267 | 157 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
158 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
|
159 """cat a specific revision""" |
267 | 160 # in stdin mode, every line except the commit is prefixed with two |
161 # spaces. This way the our caller can find the commit without magic | |
162 # strings | |
163 # | |
164 prefix = "" | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
165 if opts['stdin']: |
334 | 166 try: |
167 (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
|
168 prefix = " " |
334 | 169 except EOFError: |
170 return | |
267 | 171 |
172 else: | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
173 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
|
174 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
|
175 commands.help_(ui, 'cat-file') |
267 | 176 |
177 while r: | |
334 | 178 if type != "commit": |
179 sys.stderr.write("aborting hg cat-file only understands commits\n") | |
180 sys.exit(1); | |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
181 n = repo.lookup(r) |
334 | 182 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
|
183 if opts['stdin']: |
334 | 184 try: |
185 (type, r) = raw_input().split(' '); | |
186 except EOFError: | |
187 break | |
188 else: | |
189 break | |
267 | 190 |
191 # git rev-tree is a confusing thing. You can supply a number of | |
192 # commit sha1s on the command line, and it walks the commit history | |
193 # telling you which commits are reachable from the supplied ones via | |
194 # a bitmask based on arg position. | |
195 # 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
|
196 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
|
197 def chlogwalk(): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
198 ch = repo.changelog |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
199 count = ch.count() |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
200 i = count |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
201 l = [0] * 100 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
202 chunk = 100 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
203 while True: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
204 if chunk > i: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
205 chunk = i |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
206 i = 0 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
207 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
208 i -= chunk |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
209 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
210 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
|
211 if i + x >= count: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
212 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
|
213 break |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
214 if full != None: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
215 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
|
216 else: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
217 l[x] = 1 |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
218 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
|
219 if l[x] != 0: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
220 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
|
221 if i == 0: |
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 |
267 | 224 # calculate and return the reachability bitmask for sha |
225 def is_reachable(ar, reachable, sha): | |
334 | 226 if len(ar) == 0: |
227 return 1 | |
228 mask = 0 | |
229 for i in range(len(ar)): | |
230 if sha in reachable[i]: | |
231 mask |= 1 << i | |
267 | 232 |
334 | 233 return mask |
267 | 234 |
235 reachable = [] | |
236 stop_sha1 = [] | |
237 want_sha1 = [] | |
356 | 238 count = 0 |
267 | 239 |
240 # figure out which commits they are asking for and which ones they | |
241 # want us to stop on | |
242 for i in range(len(args)): | |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
243 if args[i].startswith('^'): |
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
244 s = repo.lookup(args[i][1:]) |
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
245 stop_sha1.append(s) |
334 | 246 want_sha1.append(s) |
247 elif args[i] != 'HEAD': | |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
248 want_sha1.append(repo.lookup(args[i])) |
356 | 249 |
267 | 250 # calculate the graph for the supplied commits |
251 for i in range(len(want_sha1)): | |
334 | 252 reachable.append({}); |
720
095dd8c757e0
Change hgit revision lookup to use repo.lookup
mason@suse.com
parents:
719
diff
changeset
|
253 n = want_sha1[i]; |
334 | 254 visit = [n]; |
255 reachable[i][n] = 1 | |
256 while visit: | |
257 n = visit.pop(0) | |
258 if n in stop_sha1: | |
1243
9d10f89b75a5
Fix hgit revtree bug with stop revision handling
root@coffee.suse.com
parents:
1239
diff
changeset
|
259 continue |
334 | 260 for p in repo.changelog.parents(n): |
261 if p not in reachable[i]: | |
262 reachable[i][p] = 1 | |
263 visit.append(p) | |
264 if p in stop_sha1: | |
1243
9d10f89b75a5
Fix hgit revtree bug with stop revision handling
root@coffee.suse.com
parents:
1239
diff
changeset
|
265 continue |
356 | 266 |
267 | 267 # walk the repository looking for commits that are in our |
268 # reachability graph | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
269 #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
|
270 for i, changes in chlogwalk(): |
334 | 271 n = repo.changelog.node(i) |
272 mask = is_reachable(want_sha1, reachable, n) | |
273 if mask: | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
274 parentstr = "" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
275 if parents: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
276 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
|
277 if pp[0] != hg.nullid: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
278 parentstr += " " + hg.hex(pp[0]) |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
279 if pp[1] != hg.nullid: |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
280 parentstr += " " + hg.hex(pp[1]) |
356 | 281 if not full: |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
282 print hg.hex(n) + parentstr |
356 | 283 elif full is "commit": |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
284 print hg.hex(n) + parentstr |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
285 catcommit(repo, n, ' ', changes) |
356 | 286 else: |
287 (p1, p2) = repo.changelog.parents(n) | |
288 (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
289 (i1, i2) = map(repo.changelog.rev, (p1, p2)) | |
267 | 290 |
356 | 291 date = changes[2].split(' ')[0] |
292 print "%s %s:%s" % (date, h, mask), | |
293 mask = is_reachable(want_sha1, reachable, p1) | |
294 if i1 != -1 and mask > 0: | |
295 print "%s:%s " % (h1, mask), | |
296 mask = is_reachable(want_sha1, reachable, p2) | |
297 if i2 != -1 and mask > 0: | |
298 print "%s:%s " % (h2, mask), | |
299 print "" | |
300 if maxnr and count >= maxnr: | |
301 break | |
302 count += 1 | |
267 | 303 |
304 # git rev-list tries to order things by date, and has the ability to stop | |
305 # at a given commit without walking the whole repo. TODO add the stop | |
306 # parameter | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
307 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
|
308 """print revisions""" |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
309 if opts['header']: |
356 | 310 full = "commit" |
311 else: | |
312 full = None | |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
313 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
|
314 revtree(copy, repo, full, opts['max_count'], opts['parents']) |
267 | 315 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
316 cmdtable = { |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
317 "git-diff-tree": (difftree, [('p', 'patch', None, 'generate patch'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
318 ('r', 'recursive', None, 'recursive'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
319 ('P', 'pretty', None, 'pretty'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
320 ('s', 'stdin', None, 'stdin'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
321 ('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
|
322 ('S', 'search', "", 'search')], |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
323 "hg git-diff-tree [options] node1 node2"), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
324 "git-cat-file": (catfile, [('s', 'stdin', None, 'stdin')], |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
325 "hg cat-file [options] type file"), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
326 "git-merge-base": (base, [], "hg git-merge-base node node"), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
327 "git-rev-list": (revlist, [('H', 'header', None, 'header'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
328 ('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
|
329 ('p', 'parents', None, 'parents'), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
330 ('n', 'max-count', 0, 'max-count')], |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
331 "hg git-rev-list [options] revs"), |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
332 } |
267 | 333 |
1239
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
334 def reposetup(ui, repo): |
29f17e083e84
Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents:
740
diff
changeset
|
335 pass |