author | mpm@selenic.com |
Sat, 04 Jun 2005 12:14:14 -0800 | |
changeset 246 | 96cde50a746f |
parent 245 | fef0f8e041aa |
child 247 | 863b508c5b36 |
permissions | -rw-r--r-- |
245 | 1 |
import os, re, traceback, sys, signal, time, mdiff |
209 | 2 |
from mercurial import fancyopts, ui, hg |
3 |
||
4 |
class UnknownCommand(Exception): pass |
|
5 |
||
245 | 6 |
def filterfiles(filters, files): |
7 |
l = [ x for x in files if x in filters ] |
|
213 | 8 |
|
245 | 9 |
for t in filters: |
10 |
if t and t[-1] != os.sep: t += os.sep |
|
11 |
l += [ x for x in files if x.startswith(t) ] |
|
213 | 12 |
return l |
13 |
||
245 | 14 |
def relfilter(repo, files): |
213 | 15 |
if os.getcwd() != repo.root: |
16 |
p = os.getcwd()[len(repo.root) + 1: ] |
|
245 | 17 |
return filterfiles(p, files) |
18 |
return files |
|
213 | 19 |
|
209 | 20 |
def relpath(repo, args): |
21 |
if os.getcwd() != repo.root: |
|
22 |
p = os.getcwd()[len(repo.root) + 1: ] |
|
245 | 23 |
return [ os.path.normpath(os.path.join(p, x)) for x in args ] |
209 | 24 |
return args |
245 | 25 |
|
26 |
def dodiff(repo, files = None, node1 = None, node2 = None): |
|
27 |
def date(c): |
|
28 |
return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
|
29 |
||
30 |
if node2: |
|
31 |
change = repo.changelog.read(node2) |
|
32 |
mmap2 = repo.manifest.read(change[0]) |
|
33 |
(c, a, d) = repo.diffrevs(node1, node2) |
|
34 |
def read(f): return repo.file(f).read(mmap2[f]) |
|
35 |
date2 = date(change) |
|
36 |
else: |
|
37 |
date2 = time.asctime() |
|
38 |
(c, a, d, u) = repo.diffdir(repo.root, node1) |
|
39 |
if not node1: |
|
40 |
node1 = repo.dirstate.parents()[0] |
|
41 |
def read(f): return file(os.path.join(repo.root, f)).read() |
|
42 |
||
43 |
change = repo.changelog.read(node1) |
|
44 |
mmap = repo.manifest.read(change[0]) |
|
45 |
date1 = date(change) |
|
46 |
||
47 |
if files: |
|
48 |
c, a, d = map(lambda x: filterfiles(files, x), (c, a, d)) |
|
49 |
||
50 |
for f in c: |
|
51 |
to = repo.file(f).read(mmap[f]) |
|
52 |
tn = read(f) |
|
53 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
54 |
for f in a: |
|
55 |
to = "" |
|
56 |
tn = read(f) |
|
57 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
58 |
for f in d: |
|
59 |
to = repo.file(f).read(mmap[f]) |
|
60 |
tn = "" |
|
61 |
sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
209 | 62 |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
63 |
def help(ui, cmd=None): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
64 |
'''show help''' |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
65 |
if cmd: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
66 |
try: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
67 |
i = find(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
68 |
ui.write("%s\n\n" % i[2]) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
69 |
ui.write(i[0].__doc__, "\n") |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
70 |
except UnknownCommand: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
71 |
ui.warn("unknown command %s", cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
72 |
sys.exit(0) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
73 |
|
209 | 74 |
ui.status("""\ |
75 |
hg commands: |
|
76 |
||
77 |
add [files...] add the given files in the next commit |
|
78 |
addremove add all new files, delete all missing files |
|
79 |
annotate [files...] show changeset number per file line |
|
80 |
branch <path> create a branch of <path> in this directory |
|
81 |
checkout [changeset] checkout the latest or given changeset |
|
82 |
commit commit all changes to the repository |
|
83 |
diff [files...] diff working directory (or selected files) |
|
84 |
dump <file> [rev] dump the latest or given revision of a file |
|
85 |
dumpmanifest [rev] dump the latest or given revision of the manifest |
|
86 |
export <rev> dump the changeset header and diffs for a revision |
|
87 |
history show changeset history |
|
88 |
init create a new repository in this directory |
|
89 |
log <file> show revision history of a single file |
|
90 |
merge <path> merge changes from <path> into local repository |
|
91 |
recover rollback an interrupted transaction |
|
92 |
remove [files...] remove the given files in the next commit |
|
93 |
serve export the repository via HTTP |
|
94 |
status show new, missing, and changed files in working dir |
|
95 |
tags show current changeset tags |
|
96 |
undo undo the last transaction |
|
97 |
""") |
|
98 |
||
245 | 99 |
def add(ui, repo, file, *files): |
100 |
'''add the specified files on the next commit''' |
|
101 |
repo.add(relpath(repo, (file,) + files)) |
|
213 | 102 |
|
245 | 103 |
def addremove(ui, repo): |
230 | 104 |
(c, a, d, u) = repo.diffdir(repo.root) |
245 | 105 |
repo.add(a) |
106 |
repo.remove(d) |
|
219
8ff4532376a4
hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents:
214
diff
changeset
|
107 |
|
245 | 108 |
def annotate(u, repo, file, *files, **ops): |
209 | 109 |
def getnode(rev): |
110 |
return hg.short(repo.changelog.node(rev)) |
|
111 |
||
112 |
def getname(rev): |
|
113 |
try: |
|
114 |
return bcache[rev] |
|
115 |
except KeyError: |
|
116 |
cl = repo.changelog.read(repo.changelog.node(rev)) |
|
117 |
name = cl[1] |
|
118 |
f = name.find('@') |
|
119 |
if f >= 0: |
|
120 |
name = name[:f] |
|
121 |
bcache[rev] = name |
|
122 |
return name |
|
123 |
||
124 |
bcache = {} |
|
125 |
opmap = [['user', getname], ['number', str], ['changeset', getnode]] |
|
126 |
if not ops['user'] and not ops['changeset']: |
|
127 |
ops['number'] = 1 |
|
128 |
||
227 | 129 |
node = repo.dirstate.parents()[0] |
209 | 130 |
if ops['revision']: |
131 |
node = repo.changelog.lookup(ops['revision']) |
|
132 |
change = repo.changelog.read(node) |
|
133 |
mmap = repo.manifest.read(change[0]) |
|
134 |
maxuserlen = 0 |
|
135 |
maxchangelen = 0 |
|
245 | 136 |
for f in relpath(repo, (file,) + files): |
209 | 137 |
lines = repo.file(f).annotate(mmap[f]) |
138 |
pieces = [] |
|
139 |
||
140 |
for o, f in opmap: |
|
141 |
if ops[o]: |
|
142 |
l = [ f(n) for n,t in lines ] |
|
143 |
m = max(map(len, l)) |
|
144 |
pieces.append([ "%*s" % (m, x) for x in l]) |
|
145 |
||
146 |
for p,l in zip(zip(*pieces), lines): |
|
147 |
u.write(" ".join(p) + ": " + l[1]) |
|
148 |
||
245 | 149 |
def branch(ui, path): |
150 |
'''branch from a local repository''' |
|
151 |
# this should eventually support remote repos |
|
152 |
os.system("cp -al %s/.hg .hg" % path) |
|
153 |
||
154 |
def checkout(ui, repo, changeset=None): |
|
155 |
'''checkout a given changeset or the current tip''' |
|
156 |
(c, a, d, u) = repo.diffdir(repo.root) |
|
157 |
if c or a or d: |
|
158 |
ui.warn("aborting (outstanding changes in working directory)\n") |
|
159 |
sys.exit(1) |
|
160 |
||
161 |
node = repo.changelog.tip() |
|
162 |
if changeset: |
|
163 |
node = repo.lookup(changeset) |
|
164 |
repo.checkout(node) |
|
165 |
||
166 |
def commit(ui, repo, *files): |
|
167 |
"""commit the specified files or all outstanding changes""" |
|
168 |
repo.commit(relpath(repo, files)) |
|
169 |
||
170 |
def diff(ui, repo, *files, **opts): |
|
171 |
revs = [] |
|
172 |
if opts['rev']: |
|
173 |
revs = map(lambda x: repo.lookup(x), opts['rev']) |
|
174 |
||
175 |
if len(revs) > 2: |
|
176 |
self.ui.warn("too many revisions to diff\n") |
|
177 |
sys.exit(1) |
|
178 |
||
179 |
if files: |
|
180 |
files = relpath(repo, files) |
|
181 |
else: |
|
182 |
files = relpath(repo, [""]) |
|
183 |
||
184 |
dodiff(repo, files, *revs) |
|
185 |
||
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
186 |
def export(ui, repo, changeset): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
187 |
node = repo.lookup(changeset) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
188 |
prev, other = repo.changelog.parents(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
189 |
change = repo.changelog.read(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
190 |
print "# HG changeset patch" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
191 |
print "# User %s" % change[1] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
192 |
print "# Node ID %s" % hg.hex(node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
193 |
print "# Parent %s" % hg.hex(prev) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
194 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
195 |
if other != hg.nullid: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
196 |
print "# Parent %s" % hg.hex(other) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
197 |
print change[4].rstrip() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
198 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
199 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
200 |
dodiff(repo, None, prev, node) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
201 |
|
245 | 202 |
def forget(ui, repo, file, *files): |
203 |
"""don't add the specified files on the next commit""" |
|
204 |
repo.forget(relpath(repo, (file,) + files)) |
|
205 |
||
221 | 206 |
def heads(ui, repo): |
207 |
'''show current repository heads''' |
|
208 |
for n in repo.changelog.heads(): |
|
209 |
i = repo.changelog.rev(n) |
|
210 |
changes = repo.changelog.read(n) |
|
211 |
(p1, p2) = repo.changelog.parents(n) |
|
212 |
(h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
213 |
(i1, i2) = map(repo.changelog.rev, (p1, p2)) |
|
214 |
print "rev: %4d:%s" % (i, h) |
|
215 |
print "parents: %4d:%s" % (i1, h1) |
|
216 |
if i2: print " %4d:%s" % (i2, h2) |
|
217 |
print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), |
|
218 |
hg.hex(changes[0])) |
|
219 |
print "user:", changes[1] |
|
220 |
print "date:", time.asctime( |
|
221 |
time.localtime(float(changes[2].split(' ')[0]))) |
|
222 |
if ui.verbose: print "files:", " ".join(changes[3]) |
|
223 |
print "description:" |
|
224 |
print changes[4] |
|
225 |
||
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
226 |
def history(ui, repo): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
227 |
"""show the changelog history""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
228 |
for i in range(repo.changelog.count()): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
229 |
n = repo.changelog.node(i) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
230 |
changes = repo.changelog.read(n) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
231 |
(p1, p2) = repo.changelog.parents(n) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
232 |
(h, h1, h2) = map(hg.hex, (n, p1, p2)) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
233 |
(i1, i2) = map(repo.changelog.rev, (p1, p2)) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
234 |
print "rev: %4d:%s" % (i, h) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
235 |
print "parents: %4d:%s" % (i1, h1) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
236 |
if i2: print " %4d:%s" % (i2, h2) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
237 |
print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
238 |
hg.hex(changes[0])) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
239 |
print "user:", changes[1] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
240 |
print "date:", time.asctime( |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
241 |
time.localtime(float(changes[2].split(' ')[0]))) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
242 |
if ui.verbose: print "files:", " ".join(changes[3]) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
243 |
print "description:" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
244 |
print changes[4] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
245 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
246 |
def patch(ui, repo, patches, opts): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
247 |
"""import an ordered set of patches""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
248 |
try: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
249 |
import psyco |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
250 |
psyco.full() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
251 |
except: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
252 |
pass |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
253 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
254 |
d = opts["base"] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
255 |
strip = opts["strip"] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
256 |
quiet = opts["quiet"] and "> /dev/null" or "" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
257 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
258 |
for patch in patches: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
259 |
ui.status("applying %s\n" % patch) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
260 |
pf = os.path.join(d, patch) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
261 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
262 |
text = "" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
263 |
for l in file(pf): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
264 |
if l[:4] == "--- ": break |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
265 |
text += l |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
266 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
267 |
f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
268 |
files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
269 |
f.close() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
270 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
271 |
if files: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
272 |
if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
273 |
raise "patch failed!" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
274 |
repo.commit(files, text) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
275 |
|
245 | 276 |
def init(ui): |
277 |
"""create a repository""" |
|
278 |
hg.repository(ui, ".", create=1) |
|
279 |
||
280 |
def log(ui, repo, f): |
|
281 |
f = relpath(repo, [f])[0] |
|
282 |
||
283 |
r = repo.file(f) |
|
284 |
for i in range(r.count()): |
|
285 |
n = r.node(i) |
|
286 |
(p1, p2) = r.parents(n) |
|
287 |
(h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
288 |
(i1, i2) = map(r.rev, (p1, p2)) |
|
289 |
cr = r.linkrev(n) |
|
290 |
cn = hg.hex(repo.changelog.node(cr)) |
|
291 |
print "rev: %4d:%s" % (i, h) |
|
292 |
print "changeset: %4d:%s" % (cr, cn) |
|
293 |
print "parents: %4d:%s" % (i1, h1) |
|
294 |
if i2: print " %4d:%s" % (i2, h2) |
|
295 |
changes = repo.changelog.read(repo.changelog.node(cr)) |
|
296 |
print "user: %s" % changes[1] |
|
297 |
print "date: %s" % time.asctime( |
|
298 |
time.localtime(float(changes[2].split(' ')[0]))) |
|
299 |
print "description:" |
|
300 |
print changes[4].rstrip() |
|
301 |
||
302 |
||
227 | 303 |
def parents(ui, repo, node = None): |
304 |
'''show the parents of the current working dir''' |
|
305 |
if node: |
|
306 |
p = repo.changelog.parents(repo.lookup(hg.bin(node))) |
|
307 |
else: |
|
308 |
p = repo.dirstate.parents() |
|
309 |
||
310 |
for n in p: |
|
311 |
if n != hg.nullid: |
|
312 |
ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n))) |
|
313 |
||
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
314 |
def pull(ui, repo, source): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
315 |
"""pull changes from the specified source""" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
316 |
paths = {} |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
317 |
try: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
318 |
pf = os.path.expanduser("~/.hgpaths") |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
319 |
for l in file(pf): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
320 |
name, path = l.split() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
321 |
paths[name] = path |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
322 |
except IOError: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
323 |
pass |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
324 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
325 |
if source in paths: source = paths[source] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
326 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
327 |
other = hg.repository(ui, source) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
328 |
cg = repo.getchangegroup(other) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
329 |
repo.addchangegroup(cg) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
330 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
331 |
def rawcommit(ui, repo, files, rc): |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
332 |
"raw commit interface" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
333 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
334 |
text = rc['text'] |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
335 |
if not text and rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
336 |
try: text = open(rc['logfile']).read() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
337 |
except IOError: pass |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
338 |
if not text and not rc['logfile']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
339 |
print "missing commit text" |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
340 |
return 1 |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
341 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
342 |
files = relpath(repo, files) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
343 |
if rc['files']: |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
344 |
files += open(rc['files']).read().splitlines() |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
345 |
|
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
346 |
repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
347 |
|
245 | 348 |
def recover(ui, repo): |
349 |
repo.recover() |
|
350 |
||
351 |
def remove(ui, repo, file, *files): |
|
352 |
"""remove the specified files on the next commit""" |
|
353 |
repo.remove(relpath(repo, (file,) + files)) |
|
354 |
||
355 |
def resolve(ui, repo, node=None): |
|
232
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
356 |
'''merge a given node or the current tip into the working dir''' |
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
357 |
if not node: |
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
358 |
node = repo.changelog.tip() |
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
359 |
else: |
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
360 |
node = repo.lookup(node) |
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
361 |
repo.resolve(node) |
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
362 |
|
245 | 363 |
def serve(ui, repo, **opts): |
364 |
from mercurial import hgweb |
|
365 |
hgweb.server(repo.root, opts["name"], opts["templates"], |
|
366 |
opts["address"], opts["port"]) |
|
367 |
||
213 | 368 |
def status(ui, repo): |
369 |
'''show changed files in the working directory |
|
370 |
||
245 | 371 |
C = changed |
372 |
A = added |
|
373 |
R = removed |
|
374 |
? = not tracked''' |
|
375 |
||
230 | 376 |
(c, a, d, u) = repo.diffdir(repo.root) |
220 | 377 |
(c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) |
213 | 378 |
|
379 |
for f in c: print "C", f |
|
220 | 380 |
for f in a: print "A", f |
213 | 381 |
for f in d: print "R", f |
220 | 382 |
for f in u: print "?", f |
213 | 383 |
|
245 | 384 |
def tip(ui, repo): |
385 |
n = repo.changelog.tip() |
|
386 |
t = repo.changelog.rev(n) |
|
387 |
ui.status("%d:%s\n" % (t, hg.hex(n))) |
|
388 |
||
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
389 |
def undo(ui, repo): |
210 | 390 |
repo.undo() |
391 |
||
209 | 392 |
table = { |
245 | 393 |
"add": (add, [], "hg add [files]"), |
394 |
"addremove": (addremove, [], "hg addremove"), |
|
209 | 395 |
"ann|annotate": (annotate, |
396 |
[('r', 'revision', '', 'revision'), |
|
397 |
('u', 'user', None, 'show user'), |
|
398 |
('n', 'number', None, 'show revision number'), |
|
399 |
('c', 'changeset', None, 'show changeset')], |
|
400 |
'hg annotate [-u] [-c] [-n] [-r id] [files]'), |
|
245 | 401 |
"branch|clone": (branch, [], 'hg branch [path]'), |
402 |
"checkout|co": (checkout, [], 'hg checkout [changeset]'), |
|
403 |
"commit|ci": (commit, [], 'hg commit [files]'), |
|
404 |
"diff": (diff, [('r', 'rev', [], 'revision')], |
|
405 |
'hg diff [-r A] [-r B] [files]'), |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
406 |
"export": (export, [], "hg export <changeset>"), |
245 | 407 |
"forget": (forget, [], "hg forget [files]"), |
408 |
"heads": (heads, [], 'hg heads'), |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
409 |
"history": (history, [], 'hg history'), |
245 | 410 |
"help": (help, [], 'hg help [command]'), |
411 |
"init": (init, [], 'hg init'), |
|
412 |
"log": (log, [], 'hg log <file>'), |
|
227 | 413 |
"parents": (parents, [], 'hg parents [node]'), |
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
414 |
"patch|import": (patch, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
415 |
[('p', 'strip', 1, 'path strip'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
416 |
('b', 'base', "", 'base path'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
417 |
('q', 'quiet', "", 'silence diff')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
418 |
"hg import [options] patches"), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
419 |
"pull|merge": (pull, [], 'hg pull [source]'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
420 |
"rawcommit": (rawcommit, |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
421 |
[('p', 'parent', [], 'parent'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
422 |
('d', 'date', "", 'data'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
423 |
('u', 'user', "", 'user'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
424 |
('F', 'files', "", 'file list'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
425 |
('t', 'text', "", 'commit text'), |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
426 |
('l', 'logfile', "", 'commit text file')], |
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
427 |
'hg rawcommit [options] [files]'), |
245 | 428 |
"recover": (recover, [], "hg recover"), |
429 |
"remove": (remove, [], "hg remove [files]"), |
|
232
fc4a6e5b5812
hg resolve: merge a given node into the working directory
mpm@selenic.com
parents:
230
diff
changeset
|
430 |
"resolve": (resolve, [], 'hg resolve [node]'), |
245 | 431 |
"serve": (serve, [('p', 'port', 8000, 'listen port'), |
432 |
('a', 'address', '', 'interface address'), |
|
433 |
('n', 'name', os.getcwd(), 'repository name'), |
|
434 |
('t', 'templates', "", 'template map')], |
|
435 |
"hg serve [options]"), |
|
213 | 436 |
"status": (status, [], 'hg status'), |
245 | 437 |
"tip": (tip, [], 'hg tip'), |
210 | 438 |
"undo": (undo, [], 'hg undo'), |
209 | 439 |
} |
440 |
||
441 |
norepo = "init branch help" |
|
442 |
||
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
443 |
def find(cmd): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
444 |
i = None |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
445 |
for e in table.keys(): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
446 |
if re.match(e + "$", cmd): |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
447 |
return table[e] |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
448 |
|
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
449 |
raise UnknownCommand(cmd) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
450 |
|
214 | 451 |
class SignalInterrupt(Exception): pass |
452 |
||
453 |
def catchterm(*args): |
|
454 |
raise SignalInterrupt |
|
455 |
||
209 | 456 |
def dispatch(args): |
457 |
options = {} |
|
458 |
opts = [('v', 'verbose', None, 'verbose'), |
|
459 |
('d', 'debug', None, 'debug'), |
|
460 |
('q', 'quiet', None, 'quiet'), |
|
461 |
('y', 'noninteractive', None, 'run non-interactively'), |
|
462 |
] |
|
463 |
||
464 |
args = fancyopts.fancyopts(args, opts, options, |
|
465 |
'hg [options] <command> [options] [files]') |
|
466 |
||
467 |
if not args: |
|
468 |
cmd = "help" |
|
469 |
else: |
|
470 |
cmd, args = args[0], args[1:] |
|
471 |
||
472 |
u = ui.ui(options["verbose"], options["debug"], options["quiet"], |
|
473 |
not options["noninteractive"]) |
|
474 |
||
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
475 |
# deal with unfound commands later |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
476 |
i = find(cmd) |
209 | 477 |
|
214 | 478 |
signal.signal(signal.SIGTERM, catchterm) |
479 |
||
209 | 480 |
cmdoptions = {} |
481 |
args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) |
|
482 |
||
483 |
if cmd not in norepo.split(): |
|
484 |
repo = hg.repository(ui = u) |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
485 |
d = lambda: i[0](u, repo, *args, **cmdoptions) |
209 | 486 |
else: |
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
487 |
d = lambda: i[0](u, *args, **cmdoptions) |
209 | 488 |
|
489 |
try: |
|
246
96cde50a746f
Migrate rawcommit, import, export, history, and merge
mpm@selenic.com
parents:
245
diff
changeset
|
490 |
return d() |
214 | 491 |
except SignalInterrupt: |
492 |
u.warn("killed!\n") |
|
209 | 493 |
except KeyboardInterrupt: |
494 |
u.warn("interrupted!\n") |
|
212
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
495 |
except TypeError, inst: |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
496 |
# was this an argument error? |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
497 |
tb = traceback.extract_tb(sys.exc_info()[2]) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
498 |
if len(tb) > 2: # no |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
499 |
raise |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
500 |
u.warn("%s: invalid arguments\n" % i[0].__name__) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
501 |
u.warn("syntax: %s\n" % i[2]) |
48398a5353e3
commands: better argument processing, per-command help
mpm@selenic.com
parents:
211
diff
changeset
|
502 |
sys.exit(-1) |