author | mpm@selenic.com |
Mon, 30 May 2005 08:03:54 -0800 | |
changeset 192 | 5d8553352d2e |
parent 188 | f40273b0ad7b |
child 193 | 0a28dfe59f8f |
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 |
188 | 4 |
# v0.5 "katje" |
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(): |
175
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
23 |
ui.status("""\ |
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 |
|
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
26 |
add [files...] add the given files in the next commit |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
27 |
addremove add all new files, delete all missing files |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
28 |
annotate [files...] show changeset number per file line |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
29 |
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
|
30 |
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
|
31 |
commit commit all changes to the repository |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
32 |
diff [files...] diff working directory (or selected files) |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
33 |
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
|
34 |
dumpmanifest [rev] dump the latest or given revision of the manifest |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
35 |
history show changeset history |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
36 |
init create a new repository in this directory |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
37 |
log <file> show revision history of a single file |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
38 |
merge <path> merge changes from <path> into local repository |
163 | 39 |
recover rollback an interrupted transaction |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
40 |
remove [files...] remove the given files in the next commit |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
41 |
serve export the repository via HTTP |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
42 |
status show new, missing, and changed files in working dir |
67 | 43 |
tags show current changeset tags |
163 | 44 |
undo undo the last transaction |
175
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
45 |
""") |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
46 |
|
33 | 47 |
def filterfiles(list, files): |
48 |
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
|
49 |
|
33 | 50 |
for f in files: |
51 |
if f[-1] != os.sep: f += os.sep |
|
52 |
l += [ x for x in list if x.startswith(f) ] |
|
53 |
return l |
|
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
54 |
|
34 | 55 |
def diff(files = None, node1 = None, node2 = None): |
64 | 56 |
def date(c): |
57 |
return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
|
34 | 58 |
|
59 |
if node2: |
|
60 |
change = repo.changelog.read(node2) |
|
61 |
mmap2 = repo.manifest.read(change[0]) |
|
62 |
(c, a, d) = repo.diffrevs(node1, node2) |
|
63 |
def read(f): return repo.file(f).read(mmap2[f]) |
|
64 | 64 |
date2 = date(change) |
34 | 65 |
else: |
64 | 66 |
date2 = time.asctime() |
34 | 67 |
if not node1: |
68 |
node1 = repo.current |
|
69 |
(c, a, d) = repo.diffdir(repo.root, node1) |
|
129
1db9207def07
Fix diff and export not showing added files
mpm@selenic.com
parents:
124
diff
changeset
|
70 |
a = [] # ignore unknown files in repo, by popular request |
64 | 71 |
def read(f): return file(os.path.join(repo.root, f)).read() |
34 | 72 |
|
73 |
change = repo.changelog.read(node1) |
|
74 |
mmap = repo.manifest.read(change[0]) |
|
64 | 75 |
date1 = date(change) |
34 | 76 |
|
77 |
if files: |
|
129
1db9207def07
Fix diff and export not showing added files
mpm@selenic.com
parents:
124
diff
changeset
|
78 |
c, a, d = map(lambda x: filterfiles(x, files), (c, a, d)) |
34 | 79 |
|
80 |
for f in c: |
|
130
e6678a1beb6a
Make hg diff handle files that have been added but not yet committed.
mpm@selenic.com
parents:
129
diff
changeset
|
81 |
to = "" |
e6678a1beb6a
Make hg diff handle files that have been added but not yet committed.
mpm@selenic.com
parents:
129
diff
changeset
|
82 |
if mmap.has_key(f): |
e6678a1beb6a
Make hg diff handle files that have been added but not yet committed.
mpm@selenic.com
parents:
129
diff
changeset
|
83 |
to = repo.file(f).read(mmap[f]) |
34 | 84 |
tn = read(f) |
64 | 85 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
129
1db9207def07
Fix diff and export not showing added files
mpm@selenic.com
parents:
124
diff
changeset
|
86 |
for f in a: |
1db9207def07
Fix diff and export not showing added files
mpm@selenic.com
parents:
124
diff
changeset
|
87 |
to = "" |
1db9207def07
Fix diff and export not showing added files
mpm@selenic.com
parents:
124
diff
changeset
|
88 |
tn = read(f) |
1db9207def07
Fix diff and export not showing added files
mpm@selenic.com
parents:
124
diff
changeset
|
89 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
34 | 90 |
for f in d: |
91 |
to = repo.file(f).read(mmap[f]) |
|
92 |
tn = "" |
|
64 | 93 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
34 | 94 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
95 |
options = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
96 |
opts = [('v', 'verbose', None, 'verbose'), |
83 | 97 |
('d', 'debug', None, 'debug'), |
107 | 98 |
('q', 'quiet', None, 'quiet'), |
99 |
('y', 'noninteractive', None, 'run non-interactively'), |
|
100 |
] |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
101 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
102 |
args = fancyopts.fancyopts(sys.argv[1:], opts, options, |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
103 |
'hg [options] <command> [command options] [files]') |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
104 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
105 |
try: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
106 |
cmd = args[0] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
107 |
args = args[1:] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
108 |
except: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
109 |
cmd = "" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
110 |
|
107 | 111 |
ui = hg.ui(options["verbose"], options["debug"], options["quiet"], |
112 |
not options["noninteractive"]) |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
113 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
114 |
if cmd == "init": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
115 |
repo = hg.repository(ui, ".", create=1) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
116 |
sys.exit(0) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
117 |
elif cmd == "branch" or cmd == "clone": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
118 |
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
|
119 |
sys.exit(0) |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
120 |
elif cmd == "help": |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
121 |
help() |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
122 |
sys.exit(0) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
123 |
else: |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
124 |
try: |
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
125 |
repo = hg.repository(ui=ui) |
74 | 126 |
except IOError: |
83 | 127 |
ui.warn("Unable to open repository\n") |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
128 |
sys.exit(0) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
129 |
|
103
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
130 |
relpath = None |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
131 |
if os.getcwd() != repo.root: |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
132 |
relpath = os.getcwd()[len(repo.root) + 1: ] |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
133 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
134 |
if cmd == "checkout" or cmd == "co": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
135 |
node = repo.changelog.tip() |
39 | 136 |
if args: |
67 | 137 |
node = repo.lookup(args[0]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
138 |
repo.checkout(node) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
139 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
140 |
elif cmd == "add": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
141 |
repo.add(args) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
142 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
143 |
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
|
144 |
repo.remove(args) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
145 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
146 |
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
|
147 |
if 1: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
148 |
if len(args) > 0: |
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
149 |
repo.commit(repo.current, args) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
150 |
else: |
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
151 |
repo.commit(repo.current) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
152 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
153 |
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
|
154 |
try: |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
155 |
import psyco |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
156 |
psyco.full() |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
157 |
except: |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
158 |
pass |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
159 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
160 |
ioptions = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
161 |
opts = [('p', 'strip', 1, 'path strip'), |
50 | 162 |
('b', 'base', "", 'base path'), |
163 |
('q', 'quiet', "", 'silence diff') |
|
164 |
] |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
165 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
166 |
args = fancyopts.fancyopts(args, opts, ioptions, |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
167 |
'hg import [options] <patch names>') |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
168 |
d = ioptions["base"] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
169 |
strip = ioptions["strip"] |
50 | 170 |
quiet = ioptions["quiet"] and "> /dev/null" or "" |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
171 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
172 |
for patch in args: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
173 |
ui.status("applying %s\n" % patch) |
49 | 174 |
pf = os.path.join(d, patch) |
175 |
||
62 | 176 |
text = "" |
177 |
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
|
178 |
if l[:4] == "--- ": break |
62 | 179 |
text += l |
180 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
181 |
f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
54 | 182 |
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
|
183 |
f.close() |
69
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
184 |
|
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
185 |
if files: |
ab03c7a52cf2
Minor changes to import so that we can successfully import Ingo's
mpm@selenic.com
parents:
68
diff
changeset
|
186 |
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
|
187 |
raise "patch failed!" |
49 | 188 |
repo.commit(repo.current, files, text) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
189 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
190 |
elif cmd == "status": |
33 | 191 |
(c, a, d) = repo.diffdir(repo.root, repo.current) |
103
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
192 |
if relpath: |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
193 |
(c, a, d) = map(lambda x: filterfiles(x, [ relpath ]), (c, a, d)) |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
194 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
195 |
for f in c: print "C", f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
196 |
for f in a: print "?", f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
197 |
for f in d: print "R", f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
198 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
199 |
elif cmd == "diff": |
34 | 200 |
revs = [] |
31
642058291e74
diffdir tidy in preparation for arg handling
mpm@selenic.com
parents:
29
diff
changeset
|
201 |
|
33 | 202 |
if args: |
38 | 203 |
doptions = {} |
33 | 204 |
opts = [('r', 'revision', [], 'revision')] |
205 |
args = fancyopts.fancyopts(args, opts, doptions, |
|
206 |
'hg diff [options] [files]') |
|
67 | 207 |
revs = map(lambda x: repo.lookup(x), doptions['revision']) |
33 | 208 |
|
209 |
if len(revs) > 2: |
|
83 | 210 |
self.ui.warn("too many revisions to diff\n") |
33 | 211 |
sys.exit(1) |
64 | 212 |
|
103
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
213 |
if relpath: |
64 | 214 |
if not args: args = [ relpath ] |
215 |
else: args = [ os.path.join(relpath, x) for x in args ] |
|
216 |
||
217 |
diff(args, *revs) |
|
33 | 218 |
|
79 | 219 |
elif cmd == "annotate": |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
220 |
bcache = {} |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
221 |
|
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
222 |
def getnode(rev): |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
223 |
return hg.short(repo.changelog.node(rev)) |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
224 |
|
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
225 |
def getname(rev): |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
226 |
try: |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
227 |
return bcache[rev] |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
228 |
except KeyError: |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
229 |
cl = repo.changelog.read(repo.changelog.node(rev)) |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
230 |
name = cl[1] |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
231 |
f = name.find('@') |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
232 |
if f >= 0: |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
233 |
name = name[:f] |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
234 |
bcache[rev] = name |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
235 |
return name |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
236 |
|
79 | 237 |
aoptions = {} |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
238 |
opts = [('r', 'revision', '', 'revision'), |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
239 |
('u', 'user', None, 'show user'), |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
240 |
('n', 'number', None, 'show revision number'), |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
241 |
('c', 'changeset', None, 'show changeset')] |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
242 |
|
79 | 243 |
args = fancyopts.fancyopts(args, opts, aoptions, |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
244 |
'hg annotate [-u] [-c] [-n] [-r id] [files]') |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
245 |
|
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
246 |
opmap = [['user', getname], ['number', str], ['changeset', getnode]] |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
247 |
if not aoptions['user'] and not aoptions['changeset']: |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
248 |
aoptions['number'] = 1 |
122 | 249 |
|
79 | 250 |
if args: |
122 | 251 |
if relpath: args = [ os.path.join(relpath, x) for x in args ] |
79 | 252 |
node = repo.current |
253 |
if aoptions['revision']: |
|
254 |
node = repo.changelog.lookup(aoptions['revision']) |
|
255 |
change = repo.changelog.read(node) |
|
256 |
mmap = repo.manifest.read(change[0]) |
|
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
257 |
maxuserlen = 0 |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
258 |
maxchangelen = 0 |
79 | 259 |
for f in args: |
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
260 |
lines = repo.file(f).annotate(mmap[f]) |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
261 |
pieces = [] |
80 | 262 |
|
150
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
263 |
for o, f in opmap: |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
264 |
if aoptions[o]: |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
265 |
l = [ f(n) for n,t in lines ] |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
266 |
m = max(map(len, l)) |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
267 |
pieces.append([ "%*s" % (m, x) for x in l]) |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
268 |
|
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
269 |
for p,l in zip(zip(*pieces), lines): |
8029ee2949b8
Add options to annotate for user/rev/changeset
mpm@selenic.com
parents:
145
diff
changeset
|
270 |
sys.stdout.write(" ".join(p) + ": " + l[1]) |
79 | 271 |
|
34 | 272 |
elif cmd == "export": |
67 | 273 |
node = repo.lookup(args[0]) |
68 | 274 |
prev, other = repo.changelog.parents(node) |
275 |
change = repo.changelog.read(node) |
|
276 |
print "# HG changeset patch" |
|
277 |
print "# User %s" % change[1] |
|
278 |
print "# Node ID %s" % hg.hex(node) |
|
279 |
print "# Parent %s" % hg.hex(prev) |
|
280 |
||
281 |
if other != hg.nullid: |
|
282 |
print "# Parent %s" % hg.hex(other) |
|
283 |
print change[4] |
|
284 |
||
34 | 285 |
diff(None, prev, node) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
286 |
|
46 | 287 |
elif cmd == "debugchangegroup": |
67 | 288 |
newer = repo.newer(map(repo.lookup, args)) |
62 | 289 |
for chunk in repo.changegroup(newer): |
290 |
sys.stdout.write(chunk) |
|
46 | 291 |
|
292 |
elif cmd == "debugaddchangegroup": |
|
293 |
data = sys.stdin.read() |
|
294 |
repo.addchangegroup(data) |
|
295 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
296 |
elif cmd == "addremove": |
29 | 297 |
(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
|
298 |
repo.add(a) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
299 |
repo.remove(d) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
300 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
301 |
elif cmd == "history": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
302 |
for i in range(repo.changelog.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
303 |
n = repo.changelog.node(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
304 |
changes = repo.changelog.read(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
305 |
(p1, p2) = repo.changelog.parents(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
306 |
(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
|
307 |
(i1, i2) = map(repo.changelog.rev, (p1, p2)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
308 |
print "rev: %4d:%s" % (i, h) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
309 |
print "parents: %4d:%s" % (i1, h1) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
310 |
if i2: print " %4d:%s" % (i2, h2) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
311 |
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
|
312 |
hg.hex(changes[0])) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
313 |
print "user:", changes[1] |
21 | 314 |
print "date:", time.asctime( |
315 |
time.localtime(float(changes[2].split(' ')[0]))) |
|
123
b93cc016eec9
hg history: don't print file list without -v switch
mpm@selenic.com
parents:
122
diff
changeset
|
316 |
if ui.verbose: print "files:", " ".join(changes[3]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
317 |
print "description:" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
318 |
print changes[4] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
319 |
|
89 | 320 |
elif cmd == "tip": |
321 |
n = repo.changelog.tip() |
|
322 |
t = repo.changelog.rev(n) |
|
323 |
ui.status("%d:%s\n" % (t, hg.hex(n))) |
|
324 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
325 |
elif cmd == "log": |
103
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
326 |
|
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
327 |
if len(args) == 1: |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
328 |
if relpath: |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
329 |
args[0] = os.path.join(relpath, args[0]) |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
330 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
331 |
r = repo.file(args[0]) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
332 |
for i in range(r.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
333 |
n = r.node(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
334 |
(p1, p2) = r.parents(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
335 |
(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
|
336 |
(i1, i2) = map(r.rev, (p1, p2)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
337 |
cr = r.linkrev(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
338 |
cn = hg.hex(repo.changelog.node(cr)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
339 |
print "rev: %4d:%s" % (i, h) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
340 |
print "changeset: %4d:%s" % (cr, cn) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
341 |
print "parents: %4d:%s" % (i1, h1) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
342 |
if i2: print " %4d:%s" % (i2, h2) |
103
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
343 |
changes = repo.changelog.read(repo.changelog.node(cr)) |
105 | 344 |
print "user: %s" % changes[1] |
345 |
print "date: %s" % time.asctime( |
|
106 | 346 |
time.localtime(float(changes[2].split(' ')[0]))) |
103
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
347 |
print "description:" |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
348 |
print changes[4] |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
349 |
|
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
350 |
elif len(args) > 1: |
33500fe7d56c
adding subdir support for log and status commands
jake@edge2.net
parents:
70
diff
changeset
|
351 |
print "too many args" |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
352 |
else: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
353 |
print "missing filename" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
354 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
355 |
elif cmd == "dump": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
356 |
if args: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
357 |
r = repo.file(args[0]) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
358 |
n = r.tip() |
39 | 359 |
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
|
360 |
sys.stdout.write(r.read(n)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
361 |
else: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
362 |
print "missing filename" |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
363 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
364 |
elif cmd == "dumpmanifest": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
365 |
n = repo.manifest.tip() |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
366 |
if len(args) > 0: |
39 | 367 |
n = repo.manifest.lookup(args[0]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
368 |
m = repo.manifest.read(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
369 |
files = m.keys() |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
370 |
files.sort() |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
371 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
372 |
for f in files: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
373 |
print hg.hex(m[f]), f |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
374 |
|
24 | 375 |
elif cmd == "debugindex": |
91 | 376 |
if ".hg" not in args[0]: |
377 |
args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i" |
|
378 |
||
24 | 379 |
r = hg.revlog(open, args[0], "") |
70 | 380 |
print " rev offset length base linkrev"+\ |
24 | 381 |
" p1 p2 nodeid" |
382 |
for i in range(r.count()): |
|
383 |
e = r.index[i] |
|
70 | 384 |
print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( |
24 | 385 |
i, e[0], e[1], e[2], e[3], |
386 |
hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) |
|
387 |
||
92
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
388 |
elif cmd == "debugindexdot": |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
389 |
if ".hg" not in args[0]: |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
390 |
args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i" |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
391 |
|
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
392 |
r = hg.revlog(open, args[0], "") |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
393 |
print "digraph G {" |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
394 |
for i in range(r.count()): |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
395 |
e = r.index[i] |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
396 |
print "\t%d -> %d" % (r.rev(e[4]), i) |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
397 |
if e[5] != hg.nullid: |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
398 |
print "\t%d -> %d" % (r.rev(e[5]), i) |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
399 |
print "}" |
e6fc7ff52246
Add debugindexdot to generate graphviz dot files from indexes
mpm@selenic.com
parents:
91
diff
changeset
|
400 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
401 |
elif cmd == "merge": |
174
23057dc57d1b
hg merge: abort if there are outstanding changes in the working directory
mpm@selenic.com
parents:
163
diff
changeset
|
402 |
(c, a, d) = repo.diffdir(repo.root, repo.current) |
23057dc57d1b
hg merge: abort if there are outstanding changes in the working directory
mpm@selenic.com
parents:
163
diff
changeset
|
403 |
if c: |
23057dc57d1b
hg merge: abort if there are outstanding changes in the working directory
mpm@selenic.com
parents:
163
diff
changeset
|
404 |
ui.warn("aborting (outstanding changes in working directory)\n") |
23057dc57d1b
hg merge: abort if there are outstanding changes in the working directory
mpm@selenic.com
parents:
163
diff
changeset
|
405 |
sys.exit(1) |
23057dc57d1b
hg merge: abort if there are outstanding changes in the working directory
mpm@selenic.com
parents:
163
diff
changeset
|
406 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
407 |
if args: |
175
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
408 |
paths = {} |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
409 |
try: |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
410 |
pf = os.path.join(os.environ["HOME"], ".hgpaths") |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
411 |
for l in file(pf): |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
412 |
name, path = l.split() |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
413 |
paths[name] = path |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
414 |
except: |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
415 |
pass |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
416 |
|
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
417 |
if args[0] in paths: args[0] = paths[args[0]] |
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
418 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
419 |
other = hg.repository(ui, args[0]) |
62 | 420 |
cg = repo.getchangegroup(other) |
421 |
repo.addchangegroup(cg) |
|
422 |
else: |
|
423 |
print "missing source repository" |
|
424 |
||
67 | 425 |
elif cmd == "tags": |
426 |
repo.lookup(0) # prime the cache |
|
427 |
i = repo.tags.items() |
|
428 |
i.sort() |
|
429 |
for k, n in i: |
|
430 |
try: |
|
431 |
r = repo.changelog.rev(n) |
|
432 |
except KeyError: |
|
433 |
r = "?" |
|
434 |
print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) |
|
435 |
||
162 | 436 |
elif cmd == "recover": |
437 |
repo.recover() |
|
438 |
||
439 |
elif cmd == "undo": |
|
440 |
repo.recover("undo") |
|
441 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
442 |
elif cmd == "verify": |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
443 |
filelinkrevs = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
444 |
filenodes = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
445 |
manifestchangeset = {} |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
446 |
changesets = revisions = files = 0 |
87 | 447 |
errors = 0 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
448 |
|
87 | 449 |
ui.status("checking changesets\n") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
450 |
for i in range(repo.changelog.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
451 |
changesets += 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
452 |
n = repo.changelog.node(i) |
87 | 453 |
for p in repo.changelog.parents(n): |
454 |
if p not in repo.changelog.nodemap: |
|
455 |
ui.warn("changeset %s has unknown parent %s\n" % |
|
456 |
(hg.short(n), hg.short(p))) |
|
457 |
errors += 1 |
|
458 |
try: |
|
459 |
changes = repo.changelog.read(n) |
|
145 | 460 |
except Exception, inst: |
87 | 461 |
ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) |
462 |
errors += 1 |
|
463 |
||
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
464 |
manifestchangeset[changes[0]] = n |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
465 |
for f in changes[3]: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
466 |
revisions += 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
467 |
filelinkrevs.setdefault(f, []).append(i) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
468 |
|
87 | 469 |
ui.status("checking manifests\n") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
470 |
for i in range(repo.manifest.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
471 |
n = repo.manifest.node(i) |
87 | 472 |
for p in repo.manifest.parents(n): |
473 |
if p not in repo.manifest.nodemap: |
|
474 |
ui.warn("manifest %s has unknown parent %s\n" % |
|
475 |
(hg.short(n), hg.short(p))) |
|
476 |
errors += 1 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
477 |
ca = repo.changelog.node(repo.manifest.linkrev(n)) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
478 |
cc = manifestchangeset[n] |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
479 |
if ca != cc: |
87 | 480 |
ui.warn("manifest %s points to %s, not %s\n" % |
481 |
(hg.hex(n), hg.hex(ca), hg.hex(cc))) |
|
482 |
errors += 1 |
|
483 |
||
484 |
try: |
|
121
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
485 |
delta = mdiff.patchtext(repo.manifest.delta(n)) |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
486 |
except KeyboardInterrupt: |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
487 |
print "aborted" |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
488 |
sys.exit(0) |
93 | 489 |
except Exception, inst: |
87 | 490 |
ui.warn("unpacking manifest %s: %s\n" % (hg.short(n), inst)) |
491 |
errors += 1 |
|
142 | 492 |
|
121
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
493 |
ff = [ l.split('\0') for l in delta.splitlines() ] |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
494 |
for f, fn in ff: |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
495 |
filenodes.setdefault(f, {})[hg.bin(fn)] = 1 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
496 |
|
87 | 497 |
ui.status("crosschecking files in changesets and manifests\n") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
498 |
for f in filenodes: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
499 |
if f not in filelinkrevs: |
87 | 500 |
ui.warn("file %s in manifest but not in changesets\n" % f) |
501 |
errors += 1 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
502 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
503 |
for f in filelinkrevs: |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
504 |
if f not in filenodes: |
121
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
505 |
ui.warn("file %s in changeset but not in manifest\n" % f) |
87 | 506 |
errors += 1 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
507 |
|
87 | 508 |
ui.status("checking files\n") |
121
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
509 |
ff = filenodes.keys() |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
510 |
ff.sort() |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
511 |
for f in ff: |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
512 |
if f == "/dev/null": continue |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
513 |
files += 1 |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
514 |
fl = repo.file(f) |
87 | 515 |
nodes = { hg.nullid: 1 } |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
516 |
for i in range(fl.count()): |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
517 |
n = fl.node(i) |
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
518 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
519 |
if n not in filenodes[f]: |
121
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
520 |
ui.warn("%s: %d:%s not in manifests\n" % (f, i, hg.short(n))) |
66fb61d9d97d
Use revlog.delta and mdiff.patchtext to massively speed up processing
mpm@selenic.com
parents:
107
diff
changeset
|
521 |
print len(filenodes[f].keys()), fl.count(), f |
87 | 522 |
errors += 1 |
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
523 |
else: |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
524 |
del filenodes[f][n] |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
525 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
526 |
flr = fl.linkrev(n) |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
527 |
if flr not in filelinkrevs[f]: |
87 | 528 |
ui.warn("%s:%s points to unexpected changeset rev %d\n" |
529 |
% (f, hg.short(n), fl.linkrev(n))) |
|
530 |
errors += 1 |
|
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
531 |
else: |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
532 |
filelinkrevs[f].remove(flr) |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
533 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
534 |
# verify contents |
87 | 535 |
try: |
536 |
t = fl.read(n) |
|
145 | 537 |
except Exception, inst: |
538 |
ui.warn("unpacking file %s %s: %s\n" % (f, hg.short(n), inst)) |
|
87 | 539 |
errors += 1 |
540 |
||
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
541 |
# verify parents |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
542 |
(p1, p2) = fl.parents(n) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
543 |
if p1 not in nodes: |
87 | 544 |
ui.warn("file %s:%s unknown parent 1 %s" % |
545 |
(f, hg.short(n), hg.short(p1))) |
|
546 |
errors += 1 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
547 |
if p2 not in nodes: |
87 | 548 |
ui.warn("file %s:%s unknown parent 2 %s" % |
549 |
(f, hg.short(n), hg.short(p1))) |
|
550 |
errors += 1 |
|
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
551 |
nodes[n] = 1 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
552 |
|
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
553 |
# cross-check |
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
554 |
for flr in filelinkrevs[f]: |
87 | 555 |
ui.warn("changeset rev %d not in %s\n" % (flr, f)) |
556 |
errors += 1 |
|
17
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
557 |
|
ffe6a5ca1a89
Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents:
16
diff
changeset
|
558 |
for node in filenodes[f]: |
87 | 559 |
ui.warn("node %s in manifests not in %s\n" % (hg.hex(n), f)) |
560 |
errors += 1 |
|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
561 |
|
87 | 562 |
ui.status("%d files, %d changesets, %d total revisions\n" % |
563 |
(files, changesets, revisions)) |
|
564 |
||
565 |
if errors: |
|
93 | 566 |
ui.warn("%d integrity errors encountered!\n" % errors) |
87 | 567 |
sys.exit(1) |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
568 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
569 |
elif cmd == "serve": |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
570 |
from mercurial import hgweb |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
571 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
572 |
soptions = {} |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
573 |
opts = [('p', 'port', 8000, 'listen port'), |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
574 |
('a', 'address', '', 'interface address'), |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
575 |
('n', 'name', os.getcwd(), 'repository name'), |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
576 |
('t', 'templates', "", 'template map') |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
577 |
] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
578 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
579 |
args = fancyopts.fancyopts(args, opts, soptions, |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
580 |
'hg serve [options]') |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
581 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
582 |
hgweb.server(repo.root, soptions["name"], soptions["templates"], |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
155
diff
changeset
|
583 |
soptions["address"], soptions["port"]) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
584 |
|
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
585 |
else: |
175
0eb6e2c9800d
hg: remove some debug commands, improve help messages, add .hgpaths file
mpm@selenic.com
parents:
174
diff
changeset
|
586 |
if cmd: ui.warn("unknown command\n\n") |
18
2fd3e1e3783f
Give a friendlier message when repo isn't found
mpm@selenic.com
parents:
17
diff
changeset
|
587 |
help() |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
588 |
sys.exit(1) |