Mercurial > hg4j
annotate src/org/tmatesoft/hg/core/HgCheckoutCommand.java @ 712:a864fb309e4b
Issue 49: NoClassDefFoundError: org/tmatesoft/hg/auth/HgAuthenticator. Missing package in the binary bundle
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 03 Aug 2014 18:04:13 +0200 |
parents | b4242b7e7dfe |
children |
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.Internals; |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.internal.WorkingDirFileWriter; |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 import org.tmatesoft.hg.repo.HgManifest.Flags; |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.repo.HgRepository; |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 import org.tmatesoft.hg.repo.HgRuntimeException; |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
42 import org.tmatesoft.hg.util.CancelSupport; |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 import org.tmatesoft.hg.util.CancelledException; |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 import org.tmatesoft.hg.util.Path; |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
45 import org.tmatesoft.hg.util.ProgressSupport; |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
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 * Update working directory to specific state, 'hg checkout' counterpart. |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 * 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
|
50 * |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 * @since 1.1 |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 * @author Artem Tikhomirov |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 * @author TMate Software Ltd. |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 */ |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 public class HgCheckoutCommand extends HgAbstractCommand<HgCheckoutCommand>{ |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 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
|
58 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
|
59 private boolean cleanCheckout; |
525
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 public HgCheckoutCommand(HgRepository hgRepo) { |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 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
|
63 revisionToCheckout = new CsetParamKeeper(repo); |
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 |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 /** |
563
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
67 * 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
|
68 * |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
69 * 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
|
70 * |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
71 * @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
|
72 * @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
|
73 */ |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
74 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
|
75 cleanCheckout = clean; |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
76 return this; |
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 |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
79 /** |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 * Select revision to check out |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 * |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 * @param nodeid revision |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 * @return <code>this</code> for convenience |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 * @throws HgBadArgumentException if failed to find supplied changeset |
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 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
|
87 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
|
88 return this; |
525
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 |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 /** |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 * Select revision to check out using local revision index |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 * |
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
|
94 * @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
|
95 * @return <code>this</code> for convenience |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 * @throws HgBadArgumentException if failed to find supplied changeset |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 */ |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 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
|
99 revisionToCheckout.set(changesetIndex); |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 return this; |
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 |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 /** |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
104 * 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
|
105 * |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 * @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
|
107 * @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
|
108 * @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
|
109 */ |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 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
|
111 try { |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
112 final ProgressSupport progress = getProgressSupport(null); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
113 final CancelSupport cancellation = getCancelSupport(null, true); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
114 cancellation.checkCancelled(); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
115 progress.start(6); |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
116 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
|
117 if (cleanCheckout) { |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
118 // 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
|
119 // 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
|
120 // 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
|
121 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
|
122 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
|
123 |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 f.delete(); |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
128 } |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
129 return true; |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
130 } |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
131 }); |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
132 } else { |
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
133 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
|
134 } |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
135 progress.worked(1); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
136 cancellation.checkCancelled(); |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
141 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
|
142 if (worker.next(nid, fname, flags)) { |
580
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
143 // 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
|
144 // 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
|
145 // 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
|
146 // (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
|
147 // 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
|
148 |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
149 // 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
|
150 // right away. |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
151 int mtime = worker.getLastFileModificationTime(); |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
152 // 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
|
153 // while dirstate keeps actual unix flags. |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
154 int fmode = worker.getLastFileMode(); |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
155 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
|
156 return true; |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
157 } |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
158 return false; |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
159 } |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
160 |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
161 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
|
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 begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 return true; |
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 } |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
168 }; |
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
|
169 // 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
|
170 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
|
171 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
|
172 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
|
173 worker.checkFailed(); |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
174 progress.worked(3); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
175 cancellation.checkCancelled(); |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
176 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
|
177 try { |
563
ca56a36c2eea
HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
527
diff
changeset
|
178 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
|
179 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
|
180 dirstateFileChannel.close(); |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
181 } catch (IOException ex) { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
182 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
|
183 } |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
184 progress.worked(1); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
185 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
|
186 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
|
187 assert branchName != null; |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
188 File branchFile = internalRepo.getRepositoryFile(Branch); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
189 if (HgRepository.DEFAULT_BRANCH_NAME.equals(branchName)) { |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
190 // clean actual branch, if any |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
191 if (branchFile.isFile()) { |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
192 branchFile.delete(); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
193 } |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
194 } 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
|
195 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
|
196 // 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
|
197 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
|
198 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
|
199 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
|
200 } 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
|
201 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
|
202 } |
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 } |
581
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
204 progress.worked(1); |
0890628ed51e
Progress/cancel support in new commands
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
580
diff
changeset
|
205 progress.done(); |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
206 } catch (HgRuntimeException ex) { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
207 throw new HgLibraryFailureException(ex); |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
208 } |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
209 } |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
210 |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
211 static class CheckoutWorker { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
212 private final Internals hgRepo; |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
213 private HgException failure; |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
214 private int lastWrittenFileSize; |
580
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
215 private int lastFileMode; |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
216 private int lastFileModificationTime; |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
217 |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
218 CheckoutWorker(Internals implRepo) { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
219 hgRepo = implRepo; |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
220 } |
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 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
|
223 WorkingDirFileWriter workingDirWriter = null; |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
224 try { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
225 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
|
226 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
|
227 // 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
|
228 workingDirWriter = new WorkingDirFileWriter(hgRepo); |
580
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
229 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
|
230 lastWrittenFileSize = workingDirWriter.bytesWritten(); |
580
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
231 lastFileMode = workingDirWriter.fmode(); |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
232 lastFileModificationTime = workingDirWriter.mtime(); |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 return true; |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
613
diff
changeset
|
234 } catch (HgIOException ex) { |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
613
diff
changeset
|
235 failure = ex; |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
236 } catch (HgRuntimeException ex) { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
237 failure = new HgLibraryFailureException(ex); |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 } |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
239 return false; |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
240 } |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
241 |
580
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
242 public int getLastFileMode() { |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
243 return lastFileMode; |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
244 } |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
245 |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
246 public int getLastFileModificationTime() { |
bd5926e24aa3
Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
572
diff
changeset
|
247 return lastFileModificationTime; |
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 getLastFileSize() { |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
251 return lastWrittenFileSize; |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
252 } |
526
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
253 |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
254 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
|
255 if (failure != null) { |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
256 throw failure; |
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 } |
2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
525
diff
changeset
|
259 }; |
525
0be5be8d57e9
Repository checkout support, first iteration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 } |