Mercurial > jhg
changeset 581:0890628ed51e
Progress/cancel support in new commands
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 22 Apr 2013 16:02:17 +0200 |
parents | bd5926e24aa3 |
children | 90df078d6418 |
files | src/org/tmatesoft/hg/core/HgAddRemoveCommand.java src/org/tmatesoft/hg/core/HgAnnotateCommand.java src/org/tmatesoft/hg/core/HgCheckoutCommand.java src/org/tmatesoft/hg/core/HgRevertCommand.java |
diffstat | 4 files changed, 70 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgAddRemoveCommand.java Fri Apr 19 20:30:34 2013 +0200 +++ b/src/org/tmatesoft/hg/core/HgAddRemoveCommand.java Mon Apr 22 16:02:17 2013 +0200 @@ -25,7 +25,10 @@ import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgRuntimeException; +import org.tmatesoft.hg.util.CancelSupport; +import org.tmatesoft.hg.util.CancelledException; import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.ProgressSupport; /** * WORK IN PROGRESS @@ -94,20 +97,33 @@ /** * Perform scheduled addition/removal * - * @throws HgException + * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state + * @throws CancelledException if execution of the command was cancelled */ - public void execute() throws HgException { + public void execute() throws HgException, CancelledException { try { + final ProgressSupport progress = getProgressSupport(null); + final CancelSupport cancellation = getCancelSupport(null, true); + cancellation.checkCancelled(); + progress.start(2 + toAdd.size() + toRemove.size()); Internals implRepo = Internals.getInstance(repo); final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo); dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource())); + progress.worked(1); + cancellation.checkCancelled(); for (Path p : toAdd) { dirstateBuilder.recordAdded(p, Flags.RegularFile, -1); + progress.worked(1); + cancellation.checkCancelled(); } for (Path p : toRemove) { dirstateBuilder.recordRemoved(p); + progress.worked(1); + cancellation.checkCancelled(); } dirstateBuilder.serialize(); + progress.worked(1); + progress.done(); } catch (HgRuntimeException ex) { throw new HgLibraryFailureException(ex); }
--- a/src/org/tmatesoft/hg/core/HgAnnotateCommand.java Fri Apr 19 20:30:34 2013 +0200 +++ b/src/org/tmatesoft/hg/core/HgAnnotateCommand.java Mon Apr 22 16:02:17 2013 +0200 @@ -30,8 +30,10 @@ import org.tmatesoft.hg.repo.HgBlameFacility; import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.CancelSupport; import org.tmatesoft.hg.util.CancelledException; import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.ProgressSupport; /** * WORK IN PROGRESS. UNSTABLE API @@ -97,6 +99,10 @@ if (file == null) { throw new HgBadArgumentException("Command needs file argument", null); } + final ProgressSupport progress = getProgressSupport(inspector); + final CancelSupport cancellation = getCancelSupport(inspector, true); + cancellation.checkCancelled(); + progress.start(2); HgDataFile df = repo.getFileNode(file); if (!df.exists()) { return; @@ -106,11 +112,17 @@ FileAnnotation fa = new FileAnnotation(c); HgBlameFacility af = new HgBlameFacility(df); af.annotate(changesetStart, annotateRevision.get(), fa, HgIterateDirection.NewToOld); + progress.worked(1); + ProgressSupport.Sub subProgress = new ProgressSupport.Sub(progress, 1); LineImpl li = new LineImpl(); for (int i = 0; i < c.lineRevisions.length; i++) { li.init(i+1, c.lineRevisions[i], c.line(i)); inspector.next(li); + subProgress.worked(1); + cancellation.checkCancelled(); } + subProgress.done(); + progress.done(); } /**
--- a/src/org/tmatesoft/hg/core/HgCheckoutCommand.java Fri Apr 19 20:30:34 2013 +0200 +++ b/src/org/tmatesoft/hg/core/HgCheckoutCommand.java Mon Apr 22 16:02:17 2013 +0200 @@ -40,8 +40,10 @@ import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgRuntimeException; +import org.tmatesoft.hg.util.CancelSupport; import org.tmatesoft.hg.util.CancelledException; import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.ProgressSupport; /** * WORK IN PROGRESS. @@ -103,13 +105,18 @@ } /** + * Update working copy to match state of the selected revision. * * @throws HgIOException to indicate troubles updating files in working copy - * @throws HgException - * @throws CancelledException + * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state + * @throws CancelledException if execution of the command was cancelled */ public void execute() throws HgException, CancelledException { try { + final ProgressSupport progress = getProgressSupport(null); + final CancelSupport cancellation = getCancelSupport(null, true); + cancellation.checkCancelled(); + progress.start(6); Internals internalRepo = Internals.getInstance(repo); if (cleanCheckout) { // remove tracked files from wd (perhaps, just forget 'Added'?) @@ -129,6 +136,8 @@ } else { throw new HgBadArgumentException("Sorry, only clean checkout is supported now, use #clean(true)", null); } + progress.worked(1); + cancellation.checkCancelled(); final DirstateBuilder dirstateBuilder = new DirstateBuilder(internalRepo); final CheckoutWorker worker = new CheckoutWorker(internalRepo); HgManifest.Inspector insp = new HgManifest.Inspector() { @@ -166,6 +175,8 @@ dirstateBuilder.parents(repo.getChangelog().getRevision(coRevision), null); repo.getManifest().walk(coRevision, coRevision, insp); worker.checkFailed(); + progress.worked(3); + cancellation.checkCancelled(); File dirstateFile = internalRepo.getRepositoryFile(Dirstate); try { FileChannel dirstateFileChannel = new FileOutputStream(dirstateFile).getChannel(); @@ -174,10 +185,17 @@ } catch (IOException ex) { throw new HgIOException("Can't write down new directory state", ex, dirstateFile); } + progress.worked(1); + cancellation.checkCancelled(); String branchName = repo.getChangelog().range(coRevision, coRevision).get(0).branch(); assert branchName != null; - if (!HgRepository.DEFAULT_BRANCH_NAME.equals(branchName)) { - File branchFile = internalRepo.getRepositoryFile(Branch); + File branchFile = internalRepo.getRepositoryFile(Branch); + if (HgRepository.DEFAULT_BRANCH_NAME.equals(branchName)) { + // clean actual branch, if any + if (branchFile.isFile()) { + branchFile.delete(); + } + } else { try { // branch file is UTF-8, see http://mercurial.selenic.com/wiki/EncodingStrategy#UTF-8_strings OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(branchFile), EncodingHelper.getUTF8()); @@ -187,6 +205,8 @@ throw new HgIOException("Can't write down branch information", ex, branchFile); } } + progress.worked(1); + progress.done(); } catch (HgRuntimeException ex) { throw new HgLibraryFailureException(ex); }
--- a/src/org/tmatesoft/hg/core/HgRevertCommand.java Fri Apr 19 20:30:34 2013 +0200 +++ b/src/org/tmatesoft/hg/core/HgRevertCommand.java Mon Apr 22 16:02:17 2013 +0200 @@ -30,8 +30,10 @@ import org.tmatesoft.hg.repo.HgManifest.Flags; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.repo.HgRuntimeException; +import org.tmatesoft.hg.util.CancelSupport; import org.tmatesoft.hg.util.CancelledException; import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.ProgressSupport; /** * WORK IN PROGRESS. @@ -95,12 +97,16 @@ /** * Perform the back out for the given files * - * @throws HgIOException - * @throws HgException - * @throws CancelledException + * @throws HgIOException to indicate troubles updating files in working copy + * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state + * @throws CancelledException if execution of the command was cancelled */ public void execute() throws HgException, CancelledException { try { + final ProgressSupport progress = getProgressSupport(null); + final CancelSupport cancellation = getCancelSupport(null, true); + cancellation.checkCancelled(); + progress.start(files.size() + 2); final int csetRevision; if (changesetToCheckout.get() == HgRepository.WORKING_COPY) { csetRevision = repo.getChangelog().getRevisionIndex(repo.getWorkingCopyParents().first()); @@ -110,6 +116,9 @@ Internals implRepo = Internals.getInstance(repo); final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo); dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource())); + progress.worked(1); + cancellation.checkCancelled(); + final HgCheckoutCommand.CheckoutWorker worker = new HgCheckoutCommand.CheckoutWorker(implRepo); HgManifest.Inspector insp = new HgManifest.Inspector() { @@ -146,8 +155,12 @@ } repo.getManifest().walkFileRevisions(file, insp, csetRevision); worker.checkFailed(); + progress.worked(1); + cancellation.checkCancelled(); } dirstateBuilder.serialize(); + progress.worked(1); + progress.done(); } catch (HgRuntimeException ex) { throw new HgLibraryFailureException(ex); }