annotate src/org/tmatesoft/hg/core/HgCheckoutCommand.java @ 590:8cbc2a883d95

Use requested encoding in LineReader
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 29 Apr 2013 17:04:51 +0200
parents 0890628ed51e
children f41dd9a3b8af
rev   line source
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012-2013 TMate Software Ltd
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Branch;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
21
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.File;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.FileOutputStream;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.IOException;
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
25 import java.io.OutputStreamWriter;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.nio.channels.FileChannel;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
28 import org.tmatesoft.hg.internal.CsetParamKeeper;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.internal.DirstateBuilder;
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
30 import org.tmatesoft.hg.internal.EncodingHelper;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.internal.Experimental;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import org.tmatesoft.hg.internal.Internals;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.internal.WorkingDirFileWriter;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.repo.HgDataFile;
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
35 import org.tmatesoft.hg.repo.HgDirstate;
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
36 import org.tmatesoft.hg.repo.HgDirstate.EntryKind;
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
37 import org.tmatesoft.hg.repo.HgDirstate.Record;
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
38 import org.tmatesoft.hg.repo.HgInternals;
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
39 import org.tmatesoft.hg.repo.HgManifest;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
40 import org.tmatesoft.hg.repo.HgManifest.Flags;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 import org.tmatesoft.hg.repo.HgRepository;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 import org.tmatesoft.hg.repo.HgRuntimeException;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
43 import org.tmatesoft.hg.util.CancelSupport;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 import org.tmatesoft.hg.util.CancelledException;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 import org.tmatesoft.hg.util.Path;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
46 import org.tmatesoft.hg.util.ProgressSupport;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 /**
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 * WORK IN PROGRESS.
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 * Update working directory to specific state, 'hg checkout' counterpart.
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 * For the time being, only 'clean' checkout is supported ('hg co --clean')
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 * @since 1.1
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 * @author Artem Tikhomirov
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 * @author TMate Software Ltd.
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 */
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 @Experimental(reason="Work in progress")
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 public class HgCheckoutCommand extends HgAbstractCommand<HgCheckoutCommand>{
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 private final HgRepository repo;
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
62 private final CsetParamKeeper revisionToCheckout;
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
63 private boolean cleanCheckout;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public HgCheckoutCommand(HgRepository hgRepo) {
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 repo = hgRepo;
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
67 revisionToCheckout = new CsetParamKeeper(repo);
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 /**
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
71 * Whether to discard all uncommited changes prior to check-out.
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
72 *
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
73 * NOTE, at the moment, only clean checkout is supported!
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
74 *
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
75 * @param clean <code>true</code> to discard any change
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
76 * @return <code>this</code> for convenience
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
77 */
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
78 public HgCheckoutCommand clean(boolean clean) {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
79 cleanCheckout = clean;
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
80 return this;
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
81 }
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
82
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
83 /**
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 * Select revision to check out
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 * @param nodeid revision
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 * @return <code>this</code> for convenience
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 * @throws HgBadArgumentException if failed to find supplied changeset
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 */
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 public HgCheckoutCommand changeset(Nodeid nodeid) throws HgBadArgumentException {
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
91 revisionToCheckout.set(nodeid);
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
92 return this;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 }
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 /**
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 * Select revision to check out using local revision index
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 *
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
98 * @param changesetIndex local changelog revision index, or {@link HgRepository#TIP}
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 * @return <code>this</code> for convenience
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 * @throws HgBadArgumentException if failed to find supplied changeset
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 */
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 public HgCheckoutCommand changeset(int changesetIndex) throws HgBadArgumentException {
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
103 revisionToCheckout.set(changesetIndex);
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 return this;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 /**
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
108 * Update working copy to match state of the selected revision.
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 *
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 * @throws HgIOException to indicate troubles updating files in working copy
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
111 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
112 * @throws CancelledException if execution of the command was cancelled
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 */
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 public void execute() throws HgException, CancelledException {
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
115 try {
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
116 final ProgressSupport progress = getProgressSupport(null);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
117 final CancelSupport cancellation = getCancelSupport(null, true);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
118 cancellation.checkCancelled();
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
119 progress.start(6);
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
120 Internals internalRepo = Internals.getInstance(repo);
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
121 if (cleanCheckout) {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
122 // remove tracked files from wd (perhaps, just forget 'Added'?)
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
123 // for now, just delete each and every tracked file
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
124 // TODO WorkingCopy container with getFile(HgDataFile/Path) to access files in WD
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
125 HgDirstate dirstate = new HgInternals(repo).getDirstate();
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
126 dirstate.walk(new HgDirstate.Inspector() {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
127
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
128 public boolean next(EntryKind kind, Record entry) {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
129 File f = new File(repo.getWorkingDir(), entry.name().toString());
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
130 if (f.exists()) {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
131 f.delete();
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
132 }
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
133 return true;
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
134 }
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
135 });
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
136 } else {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
137 throw new HgBadArgumentException("Sorry, only clean checkout is supported now, use #clean(true)", null);
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
138 }
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
139 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
140 cancellation.checkCancelled();
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
141 final DirstateBuilder dirstateBuilder = new DirstateBuilder(internalRepo);
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
142 final CheckoutWorker worker = new CheckoutWorker(internalRepo);
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
143 HgManifest.Inspector insp = new HgManifest.Inspector() {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
144
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
145 public boolean next(Nodeid nid, Path fname, Flags flags) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
146 if (worker.next(nid, fname, flags)) {
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
147 // Mercurial seems to write "n 0 -1 unset fname" on `hg --clean co -rev <earlier rev>`
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
148 // and the reason for 'force lookup' I suspect is a slight chance of simultaneous modification
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
149 // of the file by user that doesn't alter its size the very second dirstate is being written
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
150 // (or the file is being updated and the update brought in changes that didn't alter the file size -
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
151 // with size and timestamp set, later `hg status` won't notice these changes)
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
152
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
153 // However, as long as we use this class to write clean copies of the files, we can put all the fields
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
154 // right away.
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
155 int mtime = worker.getLastFileModificationTime();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
156 // Manifest flags are chars (despite octal values `hg manifest --debug` displays),
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
157 // while dirstate keeps actual unix flags.
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
158 int fmode = worker.getLastFileMode();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
159 dirstateBuilder.recordNormal(fname, fmode, mtime, worker.getLastFileSize());
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
160 return true;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
161 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
162 return false;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
163 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
164
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
165 public boolean end(int manifestRevision) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
166 return false;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
167 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
168
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
169 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 return true;
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 }
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
172 };
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
173 // checkout tip if no revision set
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
174 final int coRevision = revisionToCheckout.get(HgRepository.TIP);
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
175 dirstateBuilder.parents(repo.getChangelog().getRevision(coRevision), null);
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
176 repo.getManifest().walk(coRevision, coRevision, insp);
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
177 worker.checkFailed();
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
178 progress.worked(3);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
179 cancellation.checkCancelled();
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
180 File dirstateFile = internalRepo.getRepositoryFile(Dirstate);
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
181 try {
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
182 FileChannel dirstateFileChannel = new FileOutputStream(dirstateFile).getChannel();
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
183 dirstateBuilder.serialize(dirstateFileChannel);
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
184 dirstateFileChannel.close();
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
185 } catch (IOException ex) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
186 throw new HgIOException("Can't write down new directory state", ex, dirstateFile);
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 }
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
188 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
189 cancellation.checkCancelled();
565
78a9e26e670d Refactor common code to initialize changelog revision for a command into standalone class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
190 String branchName = repo.getChangelog().range(coRevision, coRevision).get(0).branch();
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
191 assert branchName != null;
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
192 File branchFile = internalRepo.getRepositoryFile(Branch);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
193 if (HgRepository.DEFAULT_BRANCH_NAME.equals(branchName)) {
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
194 // clean actual branch, if any
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
195 if (branchFile.isFile()) {
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
196 branchFile.delete();
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
197 }
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
198 } else {
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
199 try {
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
200 // branch file is UTF-8, see http://mercurial.selenic.com/wiki/EncodingStrategy#UTF-8_strings
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
201 OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(branchFile), EncodingHelper.getUTF8());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
202 ow.write(branchName);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
203 ow.close();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
204 } catch (IOException ex) {
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
205 throw new HgIOException("Can't write down branch information", ex, branchFile);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
206 }
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
207 }
581
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
208 progress.worked(1);
0890628ed51e Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 580
diff changeset
209 progress.done();
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
210 } catch (HgRuntimeException ex) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
211 throw new HgLibraryFailureException(ex);
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
212 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
213 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
214
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
215 static class CheckoutWorker {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
216 private final Internals hgRepo;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
217 private HgException failure;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
218 private int lastWrittenFileSize;
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
219 private int lastFileMode;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
220 private int lastFileModificationTime;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
221
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
222 CheckoutWorker(Internals implRepo) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
223 hgRepo = implRepo;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
224 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
225
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
226 public boolean next(Nodeid nid, Path fname, Flags flags) {
572
becd2a1310a2 Report file object in case of error to be helpful as much as possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 565
diff changeset
227 WorkingDirFileWriter workingDirWriter = null;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
228 try {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
229 HgDataFile df = hgRepo.getRepo().getFileNode(fname);
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
230 int fileRevIndex = df.getRevisionIndex(nid);
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
231 // check out files based on manifest
572
becd2a1310a2 Report file object in case of error to be helpful as much as possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 565
diff changeset
232 workingDirWriter = new WorkingDirFileWriter(hgRepo);
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
233 workingDirWriter.processFile(df, fileRevIndex, flags);
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
234 lastWrittenFileSize = workingDirWriter.bytesWritten();
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
235 lastFileMode = workingDirWriter.fmode();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
236 lastFileModificationTime = workingDirWriter.mtime();
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 return true;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
238 } catch (IOException ex) {
572
becd2a1310a2 Report file object in case of error to be helpful as much as possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 565
diff changeset
239 failure = new HgIOException("Failed to write down file revision", ex, workingDirWriter.getDestinationFile());
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
240 } catch (HgRuntimeException ex) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
241 failure = new HgLibraryFailureException(ex);
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 }
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
243 return false;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 }
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
245
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
246 public int getLastFileMode() {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
247 return lastFileMode;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
248 }
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
249
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
250 public int getLastFileModificationTime() {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
251 return lastFileModificationTime;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
252 }
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
253
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 572
diff changeset
254 public int getLastFileSize() {
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
255 return lastWrittenFileSize;
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 }
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
257
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
258 public void checkFailed() throws HgException {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
259 if (failure != null) {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
260 throw failure;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
261 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
262 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 525
diff changeset
263 };
525
0be5be8d57e9 Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 }