comparison mercurial/commands.py @ 246:96cde50a746f

Migrate rawcommit, import, export, history, and merge -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Migrate rawcommit, import, export, history, and merge manifest hash: f932108ee40e34b460e94b6fe60d6a06ac9f760c -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCoguVywK+sNU5EO8RAtohAKCe9Qr5R+YeLRluJlTxRGrJW/nnoQCfW/+F I0BSOeNpb6jdUxTZY1jV0xo= =hNXm -----END PGP SIGNATURE-----
author mpm@selenic.com
date Sat, 04 Jun 2005 12:14:14 -0800
parents fef0f8e041aa
children 863b508c5b36
comparison
equal deleted inserted replaced
245:fef0f8e041aa 246:96cde50a746f
181 else: 181 else:
182 files = relpath(repo, [""]) 182 files = relpath(repo, [""])
183 183
184 dodiff(repo, files, *revs) 184 dodiff(repo, files, *revs)
185 185
186 def export(ui, repo, changeset):
187 node = repo.lookup(changeset)
188 prev, other = repo.changelog.parents(node)
189 change = repo.changelog.read(node)
190 print "# HG changeset patch"
191 print "# User %s" % change[1]
192 print "# Node ID %s" % hg.hex(node)
193 print "# Parent %s" % hg.hex(prev)
194 print
195 if other != hg.nullid:
196 print "# Parent %s" % hg.hex(other)
197 print change[4].rstrip()
198 print
199
200 dodiff(repo, None, prev, node)
201
186 def forget(ui, repo, file, *files): 202 def forget(ui, repo, file, *files):
187 """don't add the specified files on the next commit""" 203 """don't add the specified files on the next commit"""
188 repo.forget(relpath(repo, (file,) + files)) 204 repo.forget(relpath(repo, (file,) + files))
189 205
190 def heads(ui, repo): 206 def heads(ui, repo):
205 time.localtime(float(changes[2].split(' ')[0]))) 221 time.localtime(float(changes[2].split(' ')[0])))
206 if ui.verbose: print "files:", " ".join(changes[3]) 222 if ui.verbose: print "files:", " ".join(changes[3])
207 print "description:" 223 print "description:"
208 print changes[4] 224 print changes[4]
209 225
226 def history(ui, repo):
227 """show the changelog history"""
228 for i in range(repo.changelog.count()):
229 n = repo.changelog.node(i)
230 changes = repo.changelog.read(n)
231 (p1, p2) = repo.changelog.parents(n)
232 (h, h1, h2) = map(hg.hex, (n, p1, p2))
233 (i1, i2) = map(repo.changelog.rev, (p1, p2))
234 print "rev: %4d:%s" % (i, h)
235 print "parents: %4d:%s" % (i1, h1)
236 if i2: print " %4d:%s" % (i2, h2)
237 print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]),
238 hg.hex(changes[0]))
239 print "user:", changes[1]
240 print "date:", time.asctime(
241 time.localtime(float(changes[2].split(' ')[0])))
242 if ui.verbose: print "files:", " ".join(changes[3])
243 print "description:"
244 print changes[4]
245
246 def patch(ui, repo, patches, opts):
247 """import an ordered set of patches"""
248 try:
249 import psyco
250 psyco.full()
251 except:
252 pass
253
254 d = opts["base"]
255 strip = opts["strip"]
256 quiet = opts["quiet"] and "> /dev/null" or ""
257
258 for patch in patches:
259 ui.status("applying %s\n" % patch)
260 pf = os.path.join(d, patch)
261
262 text = ""
263 for l in file(pf):
264 if l[:4] == "--- ": break
265 text += l
266
267 f = os.popen("lsdiff --strip %d %s" % (strip, pf))
268 files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines()))
269 f.close()
270
271 if files:
272 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
273 raise "patch failed!"
274 repo.commit(files, text)
275
210 def init(ui): 276 def init(ui):
211 """create a repository""" 277 """create a repository"""
212 hg.repository(ui, ".", create=1) 278 hg.repository(ui, ".", create=1)
213 279
214 def log(ui, repo, f): 280 def log(ui, repo, f):
243 309
244 for n in p: 310 for n in p:
245 if n != hg.nullid: 311 if n != hg.nullid:
246 ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n))) 312 ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n)))
247 313
314 def pull(ui, repo, source):
315 """pull changes from the specified source"""
316 paths = {}
317 try:
318 pf = os.path.expanduser("~/.hgpaths")
319 for l in file(pf):
320 name, path = l.split()
321 paths[name] = path
322 except IOError:
323 pass
324
325 if source in paths: source = paths[source]
326
327 other = hg.repository(ui, source)
328 cg = repo.getchangegroup(other)
329 repo.addchangegroup(cg)
330
331 def rawcommit(ui, repo, files, rc):
332 "raw commit interface"
333
334 text = rc['text']
335 if not text and rc['logfile']:
336 try: text = open(rc['logfile']).read()
337 except IOError: pass
338 if not text and not rc['logfile']:
339 print "missing commit text"
340 return 1
341
342 files = relpath(repo, files)
343 if rc['files']:
344 files += open(rc['files']).read().splitlines()
345
346 repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent'])
347
248 def recover(ui, repo): 348 def recover(ui, repo):
249 repo.recover() 349 repo.recover()
250 350
251 def remove(ui, repo, file, *files): 351 def remove(ui, repo, file, *files):
252 """remove the specified files on the next commit""" 352 """remove the specified files on the next commit"""
301 "branch|clone": (branch, [], 'hg branch [path]'), 401 "branch|clone": (branch, [], 'hg branch [path]'),
302 "checkout|co": (checkout, [], 'hg checkout [changeset]'), 402 "checkout|co": (checkout, [], 'hg checkout [changeset]'),
303 "commit|ci": (commit, [], 'hg commit [files]'), 403 "commit|ci": (commit, [], 'hg commit [files]'),
304 "diff": (diff, [('r', 'rev', [], 'revision')], 404 "diff": (diff, [('r', 'rev', [], 'revision')],
305 'hg diff [-r A] [-r B] [files]'), 405 'hg diff [-r A] [-r B] [files]'),
406 "export": (export, [], "hg export <changeset>"),
306 "forget": (forget, [], "hg forget [files]"), 407 "forget": (forget, [], "hg forget [files]"),
307 "heads": (heads, [], 'hg heads'), 408 "heads": (heads, [], 'hg heads'),
409 "history": (history, [], 'hg history'),
308 "help": (help, [], 'hg help [command]'), 410 "help": (help, [], 'hg help [command]'),
309 "init": (init, [], 'hg init'), 411 "init": (init, [], 'hg init'),
310 "log": (log, [], 'hg log <file>'), 412 "log": (log, [], 'hg log <file>'),
311 "parents": (parents, [], 'hg parents [node]'), 413 "parents": (parents, [], 'hg parents [node]'),
414 "patch|import": (patch,
415 [('p', 'strip', 1, 'path strip'),
416 ('b', 'base', "", 'base path'),
417 ('q', 'quiet', "", 'silence diff')],
418 "hg import [options] patches"),
419 "pull|merge": (pull, [], 'hg pull [source]'),
420 "rawcommit": (rawcommit,
421 [('p', 'parent', [], 'parent'),
422 ('d', 'date', "", 'data'),
423 ('u', 'user', "", 'user'),
424 ('F', 'files', "", 'file list'),
425 ('t', 'text', "", 'commit text'),
426 ('l', 'logfile', "", 'commit text file')],
427 'hg rawcommit [options] [files]'),
312 "recover": (recover, [], "hg recover"), 428 "recover": (recover, [], "hg recover"),
313 "remove": (remove, [], "hg remove [files]"), 429 "remove": (remove, [], "hg remove [files]"),
314 "resolve": (resolve, [], 'hg resolve [node]'), 430 "resolve": (resolve, [], 'hg resolve [node]'),
315 "serve": (serve, [('p', 'port', 8000, 'listen port'), 431 "serve": (serve, [('p', 'port', 8000, 'listen port'),
316 ('a', 'address', '', 'interface address'), 432 ('a', 'address', '', 'interface address'),
369 d = lambda: i[0](u, repo, *args, **cmdoptions) 485 d = lambda: i[0](u, repo, *args, **cmdoptions)
370 else: 486 else:
371 d = lambda: i[0](u, *args, **cmdoptions) 487 d = lambda: i[0](u, *args, **cmdoptions)
372 488
373 try: 489 try:
374 d() 490 return d()
375 except SignalInterrupt: 491 except SignalInterrupt:
376 u.warn("killed!\n") 492 u.warn("killed!\n")
377 except KeyboardInterrupt: 493 except KeyboardInterrupt:
378 u.warn("interrupted!\n") 494 u.warn("interrupted!\n")
379 except TypeError, inst: 495 except TypeError, inst: