##// END OF EJS Templates
record: refactor record into generic record driver...
Kirill Smelkov -
r5827:0c29977b default
parent child Browse files
Show More
@@ -358,10 +358,29 def record(ui, repo, *pats, **opts):
358 358
359 359 ? - display help'''
360 360
361 def record_commiter(ui, repo, pats, opts):
362 commands.commit(ui, repo, *pats, **opts)
363
364 dorecord(ui, repo, record_commiter, *pats, **opts)
365
366
367 def dorecord(ui, repo, committer, *pats, **opts):
361 368 if not ui.interactive:
362 369 raise util.Abort(_('running non-interactively, use commit instead'))
363 370
364 371 def recordfunc(ui, repo, files, message, match, opts):
372 """This is generic record driver.
373
374 It's job is to interactively filter local changes, and accordingly
375 prepare working dir into a state, where the job can be delegated to
376 non-interactive commit command such as 'commit' or 'qrefresh'.
377
378 After the actual job is done by non-interactive command, working dir
379 state is restored to original.
380
381 In the end we'll record intresting changes, and everything else will be
382 left in place, so the user can continue his work.
383 """
365 384 if files:
366 385 changes = None
367 386 else:
@@ -374,6 +393,7 def record(ui, repo, *pats, **opts):
374 393 match=match, changes=changes, opts=diffopts, fp=fp)
375 394 fp.seek(0)
376 395
396 # 1. filter patch, so we have intending-to apply subset of it
377 397 chunks = filterpatch(ui, parsepatch(fp))
378 398 del fp
379 399
@@ -392,6 +412,7 def record(ui, repo, *pats, **opts):
392 412 changes = repo.status(files=newfiles, match=match)[:5]
393 413 modified = dict.fromkeys(changes[0])
394 414
415 # 2. backup changed files, so we can restore them in the end
395 416 backups = {}
396 417 backupdir = repo.join('record-backups')
397 418 try:
@@ -400,6 +421,7 def record(ui, repo, *pats, **opts):
400 421 if err.errno != errno.EEXIST:
401 422 raise
402 423 try:
424 # backup continues
403 425 for f in newfiles:
404 426 if f not in modified:
405 427 continue
@@ -417,19 +439,32 def record(ui, repo, *pats, **opts):
417 439 dopatch = fp.tell()
418 440 fp.seek(0)
419 441
442 # 3a. apply filtered patch to clean repo (clean)
420 443 if backups:
421 444 hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
422 445
446 # 3b. (apply)
423 447 if dopatch:
424 448 ui.debug('applying patch\n')
425 449 ui.debug(fp.getvalue())
426 450 patch.internalpatch(fp, ui, 1, repo.root)
427 451 del fp
428 452
429 repo.commit(newfiles, message, opts['user'], opts['date'], match,
430 force_editor=opts.get('force_editor'))
453 # 4. We prepared working directory according to filtered patch.
454 # Now is the time to delegate the job to commit/qrefresh or the like!
455
456 # it is important to first chdir to repo root -- we'll call a
457 # highlevel command with list of pathnames relative to repo root
458 cwd = os.getcwd()
459 os.chdir(repo.root)
460 try:
461 committer(ui, repo, newfiles, opts)
462 finally:
463 os.chdir(cwd)
464
431 465 return 0
432 466 finally:
467 # 5. finally restore backed-up files
433 468 try:
434 469 for realname, tmpname in backups.iteritems():
435 470 ui.debug('restoring %r to %r\n' % (tmpname, realname))
General Comments 0
You need to be logged in to leave comments. Login now