Show More
@@ -358,10 +358,29 b' def record(ui, repo, *pats, **opts):' | |||||
358 |
|
358 | |||
359 | ? - display help''' |
|
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 | if not ui.interactive: |
|
368 | if not ui.interactive: | |
362 | raise util.Abort(_('running non-interactively, use commit instead')) |
|
369 | raise util.Abort(_('running non-interactively, use commit instead')) | |
363 |
|
370 | |||
364 | def recordfunc(ui, repo, files, message, match, opts): |
|
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 | if files: |
|
384 | if files: | |
366 | changes = None |
|
385 | changes = None | |
367 | else: |
|
386 | else: | |
@@ -374,6 +393,7 b' def record(ui, repo, *pats, **opts):' | |||||
374 | match=match, changes=changes, opts=diffopts, fp=fp) |
|
393 | match=match, changes=changes, opts=diffopts, fp=fp) | |
375 | fp.seek(0) |
|
394 | fp.seek(0) | |
376 |
|
395 | |||
|
396 | # 1. filter patch, so we have intending-to apply subset of it | |||
377 | chunks = filterpatch(ui, parsepatch(fp)) |
|
397 | chunks = filterpatch(ui, parsepatch(fp)) | |
378 | del fp |
|
398 | del fp | |
379 |
|
399 | |||
@@ -392,6 +412,7 b' def record(ui, repo, *pats, **opts):' | |||||
392 | changes = repo.status(files=newfiles, match=match)[:5] |
|
412 | changes = repo.status(files=newfiles, match=match)[:5] | |
393 | modified = dict.fromkeys(changes[0]) |
|
413 | modified = dict.fromkeys(changes[0]) | |
394 |
|
414 | |||
|
415 | # 2. backup changed files, so we can restore them in the end | |||
395 | backups = {} |
|
416 | backups = {} | |
396 | backupdir = repo.join('record-backups') |
|
417 | backupdir = repo.join('record-backups') | |
397 | try: |
|
418 | try: | |
@@ -400,6 +421,7 b' def record(ui, repo, *pats, **opts):' | |||||
400 | if err.errno != errno.EEXIST: |
|
421 | if err.errno != errno.EEXIST: | |
401 | raise |
|
422 | raise | |
402 | try: |
|
423 | try: | |
|
424 | # backup continues | |||
403 | for f in newfiles: |
|
425 | for f in newfiles: | |
404 | if f not in modified: |
|
426 | if f not in modified: | |
405 | continue |
|
427 | continue | |
@@ -417,19 +439,32 b' def record(ui, repo, *pats, **opts):' | |||||
417 | dopatch = fp.tell() |
|
439 | dopatch = fp.tell() | |
418 | fp.seek(0) |
|
440 | fp.seek(0) | |
419 |
|
441 | |||
|
442 | # 3a. apply filtered patch to clean repo (clean) | |||
420 | if backups: |
|
443 | if backups: | |
421 | hg.revert(repo, repo.dirstate.parents()[0], backups.has_key) |
|
444 | hg.revert(repo, repo.dirstate.parents()[0], backups.has_key) | |
422 |
|
445 | |||
|
446 | # 3b. (apply) | |||
423 | if dopatch: |
|
447 | if dopatch: | |
424 | ui.debug('applying patch\n') |
|
448 | ui.debug('applying patch\n') | |
425 | ui.debug(fp.getvalue()) |
|
449 | ui.debug(fp.getvalue()) | |
426 | patch.internalpatch(fp, ui, 1, repo.root) |
|
450 | patch.internalpatch(fp, ui, 1, repo.root) | |
427 | del fp |
|
451 | del fp | |
428 |
|
452 | |||
429 | repo.commit(newfiles, message, opts['user'], opts['date'], match, |
|
453 | # 4. We prepared working directory according to filtered patch. | |
430 | force_editor=opts.get('force_editor')) |
|
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 | return 0 |
|
465 | return 0 | |
432 | finally: |
|
466 | finally: | |
|
467 | # 5. finally restore backed-up files | |||
433 | try: |
|
468 | try: | |
434 | for realname, tmpname in backups.iteritems(): |
|
469 | for realname, tmpname in backups.iteritems(): | |
435 | ui.debug('restoring %r to %r\n' % (tmpname, realname)) |
|
470 | ui.debug('restoring %r to %r\n' % (tmpname, realname)) |
General Comments 0
You need to be logged in to leave comments.
Login now