annotate src/org/tmatesoft/hg/core/HgCommitCommand.java @ 709:497e697636fc

Report merged lines as changed block if possible, not as a sequence of added/deleted blocks. To facilitate access to merge parent lines AddBlock got mergeLineAt() method that reports index of the line in the second parent (if any), while insertedAt() has been changed to report index in the first parent always
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 21 Aug 2013 16:23:27 +0200
parents 4ffc17c0b534
children
rev   line source
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
23 import org.tmatesoft.hg.internal.CommitFacility;
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
24 import org.tmatesoft.hg.internal.CompleteRepoLock;
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.internal.FileContentSupplier;
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
26 import org.tmatesoft.hg.internal.Internals;
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
27 import org.tmatesoft.hg.internal.Transaction;
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
28 import org.tmatesoft.hg.internal.WorkingCopyContent;
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgChangelog;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.repo.HgDataFile;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.repo.HgInternals;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
32 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.repo.HgRepository;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.repo.HgRuntimeException;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import org.tmatesoft.hg.repo.HgStatusCollector.Record;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 import org.tmatesoft.hg.util.CancelledException;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.util.Outcome;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.util.Outcome.Kind;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 import org.tmatesoft.hg.util.Pair;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 import org.tmatesoft.hg.util.Path;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 /**
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * 'hg commit' counterpart, commit changes
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 *
626
5afc7eedb3dd @since, TODOs. Tests: add 1 sec to deal with fs timestamp granularity on linux
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
46 * @since 1.1
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 * @author Artem Tikhomirov
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 * @author TMate Software Ltd.
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 */
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public class HgCommitCommand extends HgAbstractCommand<HgCommitCommand> {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 private final HgRepository repo;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 private String message;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 private String user;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 // nodeid of newly added revision
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 private Nodeid newRevision;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 public HgCommitCommand(HgRepository hgRepo) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 repo = hgRepo;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 public HgCommitCommand message(String msg) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 message = msg;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 return this;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 public HgCommitCommand user(String userName) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 user = userName;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 return this;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 /**
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 * Tell if changes in the working directory constitute merge commit. May be invoked prior to (and independently from) {@link #execute()}
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 *
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 * @return <code>true</code> if working directory changes are result of a merge
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
77 * @throws HgLibraryFailureException to indicate unexpected issue with the repository
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
78 * @throws HgException subclass thereof to indicate other specific issue with repository state
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 */
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 public boolean isMergeCommit() throws HgException {
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
81 try {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
82 int[] parents = new int[2];
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
83 detectParentFromDirstate(parents);
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
84 return parents[0] != NO_REVISION && parents[1] != NO_REVISION;
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
85 } catch (HgRuntimeException ex) {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
86 throw new HgLibraryFailureException(ex);
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
87 }
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 /**
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
92 * @throws HgRepositoryLockException if failed to lock the repo for modifications
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 * @throws IOException propagated IO errors from status walker over working directory
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 * @throws CancelledException if execution of the command was cancelled
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 */
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 public Outcome execute() throws HgException, IOException, CancelledException {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 if (message == null) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 throw new HgBadArgumentException("Shall supply commit message", null);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
100 final CompleteRepoLock repoLock = new CompleteRepoLock(repo);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
101 repoLock.acquire();
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 try {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 int[] parentRevs = new int[2];
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 detectParentFromDirstate(parentRevs);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 HgWorkingCopyStatusCollector sc = new HgWorkingCopyStatusCollector(repo);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 Record status = sc.status(HgRepository.WORKING_COPY);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 if (status.getModified().size() == 0 && status.getAdded().size() == 0 && status.getRemoved().size() == 0) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 newRevision = Nodeid.NULL;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 return new Outcome(Kind.Failure, "nothing to add");
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 }
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
111 final Internals implRepo = Internals.getInstance(repo);
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
112 CommitFacility cf = new CommitFacility(implRepo, parentRevs[0], parentRevs[1]);
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 for (Path m : status.getModified()) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 HgDataFile df = repo.getFileNode(m);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 cf.add(df, new WorkingCopyContent(df));
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 for (Path a : status.getAdded()) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 HgDataFile df = repo.getFileNode(a); // TODO need smth explicit, like repo.createNewFileNode(Path) here
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 // XXX might be an interesting exercise not to demand a content supplier, but instead return a "DataRequester"
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 // object, that would indicate interest in data, and this code would "push" it to requester, so that any exception
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 // is handled here, right away, and won't need to travel supplier and CommitFacility. (although try/catch inside
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 // supplier.read (with empty throws declaration)
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
123 cf.add(df, new FileContentSupplier(repo, a));
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 for (Path r : status.getRemoved()) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 HgDataFile df = repo.getFileNode(r);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 cf.forget(df);
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 cf.branch(detectBranch());
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 cf.user(detectUser());
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
131 Transaction.Factory trFactory = implRepo.getTransactionFactory();
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
132 Transaction tr = trFactory.create(repo);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
133 try {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
134 newRevision = cf.commit(message, tr);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
135 tr.commit();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
136 } catch (RuntimeException ex) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
137 tr.rollback();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
138 throw ex;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
139 } catch (HgException ex) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
140 tr.rollback();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
141 throw ex;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
142 }
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 return new Outcome(Kind.Success, "Commit ok");
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 } catch (HgRuntimeException ex) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 throw new HgLibraryFailureException(ex);
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
146 } finally {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
147 repoLock.release();
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 public Nodeid getCommittedRevision() {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 if (newRevision == null) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 throw new IllegalStateException("Call #execute() first!");
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 return newRevision;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
158 private String detectBranch() throws HgInvalidControlFileException {
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 return repo.getWorkingCopyBranchName();
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 private String detectUser() {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 if (user != null) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 return user;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 // TODO HgInternals is odd place for getNextCommitUsername()
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 return new HgInternals(repo).getNextCommitUsername();
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 626
diff changeset
170 private void detectParentFromDirstate(int[] parents) throws HgRuntimeException {
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 Pair<Nodeid, Nodeid> pn = repo.getWorkingCopyParents();
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 HgChangelog clog = repo.getChangelog();
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 parents[0] = pn.first().isNull() ? NO_REVISION : clog.getRevisionIndex(pn.first());
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 parents[1] = pn.second().isNull() ? NO_REVISION : clog.getRevisionIndex(pn.second());
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 }