author | mpm@selenic.com |
Tue, 17 May 2005 01:07:01 -0800 | |
changeset 77 | bed15e766511 |
parent 74 | 401e18c95ad3 |
child 79 | 837d473d54d5 |
permissions | -rw-r--r-- |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 |
# |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
3 |
# mercurial - a minimal scalable distributed SCM |
67 | 4 |
# v0.4f "jane dark" |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 |
# |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 |
# Copyright 2005 Matt Mackall <mpm@selenic.com> |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
# |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
8 |
# This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
9 |
# of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
10 |
|
46 | 11 |
# the psyco compiler makes commits a bit faster |
12 |
# and makes changegroup merge about 20 times slower! |
|
13 |
# try: |
|
14 |
# import psyco |
|
15 |
# psyco.full() |
|
16 |
# except: |
|
17 |
# pass |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
18 |
|
23 | 19 |
import sys, os, time |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
20 |
from mercurial import hg, mdiff, fancyopts |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
21 |
|
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
22 |
def help(): |
49 | 23 |
print """\ |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
24 |
commands: |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
25 |
|
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
26 |
init create a new repository in this directory |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
27 |
branch <path> create a branch of <path> in this directory |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
28 |
merge <path> merge changes from <path> into local repository |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
29 |
checkout [changeset] checkout the latest or given changeset |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
30 |
status show new, missing, and changed files in working dir |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
31 |
add [files...] add the given files in the next commit |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
32 |
remove [files...] remove the given files in the next commit |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
33 |
addremove add all new files, delete all missing files |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
34 |
commit commit all changes to the repository |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
35 |
history show changeset history |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
36 |
log <file> show revision history of a single file |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
37 |
dump <file> [rev] dump the latest or given revision of a file |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
38 |
dumpmanifest [rev] dump the latest or given revision of the manifest |
22 | 39 |
diff [files...] diff working directory (or selected files) |
67 | 40 |
tags show current changeset tags |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
41 |
""" |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
42 |
|
33 | 43 |
def filterfiles(list, files): |
44 |
l = [ x for x in list if x in files ] |
|
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
45 |
|
33 | 46 |
for f in files: |
47 |
if f[-1] != os.sep: f += os.sep |
|
48 |
l += [ x for x in list if x.startswith(f) ] |
|
49 |
return l |
|
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
50 |
|
34 | 51 |
def diff(files = None, node1 = None, node2 = None): |
64 | 52 |
def date(c): |
53 |
return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
|
34 | 54 |
|
55 |
if node2: |
|
56 |
change = repo.changelog.read(node2) |
|
57 |
mmap2 = repo.manifest.read(change[0]) |
|
58 |
(c, a, d) = repo.diffrevs(node1, node2) |
|
59 |
def read(f): return repo.file(f).read(mmap2[f]) |
|
64 | 60 |
date2 = date(change) |
34 | 61 |
else: |
64 | 62 |
date2 = time.asctime() |
34 | 63 |
if not node1: |
64 |
node1 = repo.current |
|
65 |
(c, a, d) = repo.diffdir(repo.root, node1) |
|
64 | 66 |
def read(f): return file(os.path.join(repo.root, f)).read() |
34 | 67 |
|
68 |
change = repo.changelog.read(node1) |
|
69 |
mmap = repo.manifest.read(change[0]) |
|
64 | 70 |
date1 = date(change) |
34 | 71 |
|
72 |
if files: |
|
73 |
(c, a, d) = map(lambda x: filterfiles(x, files), (c, a, d)) |
|
74 |
||
75 |
for f in c: |
|
76 |
to = repo.file(f).read(mmap[f]) |
|
77 |
tn = read(f) |
|
64 | 78 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
34 | 79 |
for f in a: |
80 |
to = "" |
|
81 |
tn = read(f) |
|
64 | 82 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
34 | 83 |
for f in d: |
84 |
to = repo.file(f).read(mmap[f]) |
|
85 |
tn = "" |
|
64 | 86 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
34 | 87 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
88 |
options = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
89 |
opts = [('v', 'verbose', None, 'verbose'), |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
90 |
('d', 'debug', None, 'debug')] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
91 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
92 |
args = fancyopts.fancyopts(sys.argv[1:], opts, options, |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
93 |
'hg [options] <command> [command options] [files]') |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
94 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
95 |
try: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
96 |
cmd = args[0] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
97 |
args = args[1:] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
98 |
except: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
99 |
cmd = "" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
100 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
101 |
ui = hg.ui(options["verbose"], options["debug"]) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
102 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
103 |
if cmd == "init": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
104 |
repo = hg.repository(ui, ".", create=1) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
105 |
sys.exit(0) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
106 |
elif cmd == "branch" or cmd == "clone": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
107 |
os.system("cp -al %s/.hg .hg" % args[0]) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
108 |
sys.exit(0) |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
109 |
elif cmd == "help": |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
110 |
help() |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
111 |
sys.exit(0) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
112 |
else: |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
113 |
try: |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
114 |
repo = hg.repository(ui=ui) |
74 | 115 |
except IOError: |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
116 |
print "Unable to open repository" |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
117 |
sys.exit(0) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
118 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
119 |
if cmd == "checkout" or cmd == "co": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
120 |
node = repo.changelog.tip() |
39 | 121 |
if args: |
67 | 122 |
node = repo.lookup(args[0]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
123 |
repo.checkout(node) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
124 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
125 |
elif cmd == "add": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
126 |
repo.add(args) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
127 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
128 |
elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
129 |
repo.remove(args) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
130 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
131 |
elif cmd == "commit" or cmd == "checkin" or cmd == "ci": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
132 |
if 1: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
133 |
if len(args) > 0: |
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
134 |
repo.commit(repo.current, args) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
135 |
else: |
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
136 |
repo.commit(repo.current) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
137 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
138 |
elif cmd == "import" or cmd == "patch": |
69
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
139 |
try: |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
140 |
import psyco |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
141 |
psyco.full() |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
142 |
except: |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
143 |
pass |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
144 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
145 |
ioptions = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
146 |
opts = [('p', 'strip', 1, 'path strip'), |
50 | 147 |
('b', 'base', "", 'base path'), |
148 |
('q', 'quiet', "", 'silence diff') |
|
149 |
] |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
150 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
151 |
args = fancyopts.fancyopts(args, opts, ioptions, |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
152 |
'hg import [options] <patch names>') |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
153 |
d = ioptions["base"] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
154 |
strip = ioptions["strip"] |
50 | 155 |
quiet = ioptions["quiet"] and "> /dev/null" or "" |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
156 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
157 |
for patch in args: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
158 |
ui.status("applying %s\n" % patch) |
49 | 159 |
pf = os.path.join(d, patch) |
160 |
||
62 | 161 |
text = "" |
162 |
for l in file(pf): |
|
69
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
163 |
if l[:4] == "--- ": break |
62 | 164 |
text += l |
165 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
166 |
f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
54 | 167 |
files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
168 |
f.close() |
69
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
169 |
|
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
170 |
if files: |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
171 |
if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
172 |
raise "patch failed!" |
49 | 173 |
repo.commit(repo.current, files, text) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
174 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
175 |
elif cmd == "status": |
33 | 176 |
(c, a, d) = repo.diffdir(repo.root, repo.current) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
177 |
for f in c: print "C", f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
178 |
for f in a: print "?", f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
179 |
for f in d: print "R", f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
180 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
181 |
elif cmd == "diff": |
34 | 182 |
revs = [] |
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
183 |
|
33 | 184 |
if args: |
38 | 185 |
doptions = {} |
33 | 186 |
opts = [('r', 'revision', [], 'revision')] |
187 |
args = fancyopts.fancyopts(args, opts, doptions, |
|
188 |
'hg diff [options] [files]') |
|
67 | 189 |
revs = map(lambda x: repo.lookup(x), doptions['revision']) |
33 | 190 |
|
191 |
if len(revs) > 2: |
|
192 |
print "too many revisions to diff" |
|
193 |
sys.exit(1) |
|
64 | 194 |
|
195 |
if os.getcwd() != repo.root: |
|
196 |
relpath = os.getcwd()[len(repo.root) + 1: ] |
|
197 |
if not args: args = [ relpath ] |
|
198 |
else: args = [ os.path.join(relpath, x) for x in args ] |
|
199 |
||
200 |
diff(args, *revs) |
|
33 | 201 |
|
34 | 202 |
elif cmd == "export": |
67 | 203 |
node = repo.lookup(args[0]) |
68 | 204 |
prev, other = repo.changelog.parents(node) |
205 |
change = repo.changelog.read(node) |
|
206 |
print "# HG changeset patch" |
|
207 |
print "# User %s" % change[1] |
|
208 |
print "# Node ID %s" % hg.hex(node) |
|
209 |
print "# Parent %s" % hg.hex(prev) |
|
210 |
||
211 |
if other != hg.nullid: |
|
212 |
print "# Parent %s" % hg.hex(other) |
|
213 |
print change[4] |
|
214 |
||
34 | 215 |
diff(None, prev, node) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
216 |
|
46 | 217 |
elif cmd == "debugchangegroup": |
67 | 218 |
newer = repo.newer(map(repo.lookup, args)) |
62 | 219 |
for chunk in repo.changegroup(newer): |
220 |
sys.stdout.write(chunk) |
|
46 | 221 |
|
222 |
elif cmd == "debugaddchangegroup": |
|
223 |
data = sys.stdin.read() |
|
224 |
repo.addchangegroup(data) |
|
225 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
226 |
elif cmd == "addremove": |
29 | 227 |
(c, a, d) = repo.diffdir(repo.root, repo.current) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
228 |
repo.add(a) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
229 |
repo.remove(d) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
230 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
231 |
elif cmd == "history": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
232 |
for i in range(repo.changelog.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
233 |
n = repo.changelog.node(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
234 |
changes = repo.changelog.read(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
235 |
(p1, p2) = repo.changelog.parents(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
236 |
(h, h1, h2) = map(hg.hex, (n, p1, p2)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
237 |
(i1, i2) = map(repo.changelog.rev, (p1, p2)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
238 |
print "rev: %4d:%s" % (i, h) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
239 |
print "parents: %4d:%s" % (i1, h1) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
240 |
if i2: print " %4d:%s" % (i2, h2) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
241 |
print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
242 |
hg.hex(changes[0])) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
243 |
print "user:", changes[1] |
21 | 244 |
print "date:", time.asctime( |
245 |
time.localtime(float(changes[2].split(' ')[0]))) |
|
11 | 246 |
print "files:", " ".join(changes[3]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
247 |
print "description:" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
248 |
print changes[4] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
249 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
250 |
elif cmd == "log": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
251 |
if args: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
252 |
r = repo.file(args[0]) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
253 |
for i in range(r.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
254 |
n = r.node(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
255 |
(p1, p2) = r.parents(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
256 |
(h, h1, h2) = map(hg.hex, (n, p1, p2)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
257 |
(i1, i2) = map(r.rev, (p1, p2)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
258 |
cr = r.linkrev(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
259 |
cn = hg.hex(repo.changelog.node(cr)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
260 |
print "rev: %4d:%s" % (i, h) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
261 |
print "changeset: %4d:%s" % (cr, cn) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
262 |
print "parents: %4d:%s" % (i1, h1) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
263 |
if i2: print " %4d:%s" % (i2, h2) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
264 |
else: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
265 |
print "missing filename" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
266 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
267 |
elif cmd == "dump": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
268 |
if args: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
269 |
r = repo.file(args[0]) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
270 |
n = r.tip() |
39 | 271 |
if len(args) > 1: n = r.lookup(args[1]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
272 |
sys.stdout.write(r.read(n)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
273 |
else: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
274 |
print "missing filename" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
275 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
276 |
elif cmd == "dumpmanifest": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
277 |
n = repo.manifest.tip() |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
278 |
if len(args) > 0: |
39 | 279 |
n = repo.manifest.lookup(args[0]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
280 |
m = repo.manifest.read(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
281 |
files = m.keys() |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
282 |
files.sort() |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
283 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
284 |
for f in files: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
285 |
print hg.hex(m[f]), f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
286 |
|
24 | 287 |
elif cmd == "debughash": |
288 |
f = repo.file(args[0]) |
|
289 |
print f.encodepath(args[0]) |
|
290 |
||
291 |
elif cmd == "debugindex": |
|
292 |
r = hg.revlog(open, args[0], "") |
|
70 | 293 |
print " rev offset length base linkrev"+\ |
24 | 294 |
" p1 p2 nodeid" |
295 |
for i in range(r.count()): |
|
296 |
e = r.index[i] |
|
70 | 297 |
print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( |
24 | 298 |
i, e[0], e[1], e[2], e[3], |
299 |
hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) |
|
300 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
301 |
elif cmd == "merge": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
302 |
if args: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
303 |
other = hg.repository(ui, args[0]) |
65
d40cc5aacc31
Fix up a bunch of bugs in the new merge code
mpm@selenic.com
parents:
64
diff
changeset
|
304 |
print "requesting changegroup" |
62 | 305 |
cg = repo.getchangegroup(other) |
306 |
repo.addchangegroup(cg) |
|
307 |
else: |
|
308 |
print "missing source repository" |
|
309 |
||
67 | 310 |
elif cmd == "tags": |
311 |
repo.lookup(0) # prime the cache |
|
312 |
i = repo.tags.items() |
|
313 |
i.sort() |
|
314 |
for k, n in i: |
|
315 |
try: |
|
316 |
r = repo.changelog.rev(n) |
|
317 |
except KeyError: |
|
318 |
r = "?" |
|
319 |
print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) |
|
320 |
||
62 | 321 |
elif cmd == "debugoldmerge": |
322 |
if args: |
|
323 |
other = hg.repository(ui, args[0]) |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
324 |
repo.merge(other) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
325 |
else: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
326 |
print "missing source repository" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
327 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
328 |
elif cmd == "verify": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
329 |
filelinkrevs = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
330 |
filenodes = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
331 |
manifestchangeset = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
332 |
changesets = revisions = files = 0 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
333 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
334 |
print "checking changesets" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
335 |
for i in range(repo.changelog.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
336 |
changesets += 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
337 |
n = repo.changelog.node(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
338 |
changes = repo.changelog.read(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
339 |
manifestchangeset[changes[0]] = n |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
340 |
for f in changes[3]: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
341 |
revisions += 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
342 |
filelinkrevs.setdefault(f, []).append(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
343 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
344 |
print "checking manifests" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
345 |
for i in range(repo.manifest.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
346 |
n = repo.manifest.node(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
347 |
ca = repo.changelog.node(repo.manifest.linkrev(n)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
348 |
cc = manifestchangeset[n] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
349 |
if ca != cc: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
350 |
print "manifest %s points to %s, not %s" % \ |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
351 |
(hg.hex(n), hg.hex(ca), hg.hex(cc)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
352 |
m = repo.manifest.read(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
353 |
for f, fn in m.items(): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
354 |
filenodes.setdefault(f, {})[fn] = 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
355 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
356 |
print "crosschecking files in changesets and manifests" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
357 |
for f in filenodes: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
358 |
if f not in filelinkrevs: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
359 |
print "file %s in manifest but not in changesets" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
360 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
361 |
for f in filelinkrevs: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
362 |
if f not in filenodes: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
363 |
print "file %s in changeset but not in manifest" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
364 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
365 |
print "checking files" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
366 |
for f in filenodes: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
367 |
files += 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
368 |
fl = repo.file(f) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
369 |
nodes = {"\0"*20: 1} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
370 |
for i in range(fl.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
371 |
n = fl.node(i) |
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
372 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
373 |
if n not in filenodes[f]: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
374 |
print "%s:%s not in manifests" % (f, hg.hex(n)) |
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
375 |
else: |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
376 |
del filenodes[f][n] |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
377 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
378 |
flr = fl.linkrev(n) |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
379 |
if flr not in filelinkrevs[f]: |
11 | 380 |
print "%s:%s points to unexpected changeset rev %d" \ |
381 |
% (f, hg.hex(n), fl.linkrev(n)) |
|
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
382 |
else: |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
383 |
filelinkrevs[f].remove(flr) |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
384 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
385 |
# verify contents |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
386 |
t = fl.read(n) |
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
387 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
388 |
# verify parents |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
389 |
(p1, p2) = fl.parents(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
390 |
if p1 not in nodes: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
391 |
print "%s:%s unknown parent 1 %s" % (f, hg.hex(n), hg.hex(p1)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
392 |
if p2 not in nodes: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
393 |
print "file %s:%s unknown parent %s" % (f, hg.hex(n), hg.hex(p1)) |
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
394 |
nodes[n] = 1 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
395 |
|
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
396 |
# cross-check |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
397 |
for flr in filelinkrevs[f]: |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
398 |
print "changeset rev %d not in %s" % (flr, f) |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
399 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
400 |
for node in filenodes[f]: |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
401 |
print "node %s in manifests not in %s" % (hg.hex(n), f) |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
402 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
403 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
404 |
print "%d files, %d changesets, %d total revisions" % (files, changesets, |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
405 |
revisions) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
406 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
407 |
else: |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
408 |
print "unknown command\n" |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
409 |
help() |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
410 |
sys.exit(1) |