annotate src/org/tmatesoft/hg/internal/CommitFacility.java @ 708:4ffc17c0b534

Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 20 Aug 2013 18:41:34 +0200
parents b4242b7e7dfe
children
rev   line source
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
17 package org.tmatesoft.hg.internal;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.DEFAULT_BRANCH_NAME;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepositoryFiles.*;
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Error;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
24 import java.io.File;
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
25 import java.io.FileOutputStream;
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
26 import java.io.FileWriter;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
27 import java.io.IOException;
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
28 import java.nio.ByteBuffer;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
29 import java.util.ArrayList;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.HashMap;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.LinkedHashMap;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import java.util.Map;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
33 import java.util.Set;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import java.util.TreeMap;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
35 import java.util.TreeSet;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
37 import org.tmatesoft.hg.core.HgCommitCommand;
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
38 import org.tmatesoft.hg.core.HgIOException;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.core.HgRepositoryLockException;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 import org.tmatesoft.hg.core.Nodeid;
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
41 import org.tmatesoft.hg.internal.DataSerializer.ByteArraySerializer;
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
42 import org.tmatesoft.hg.internal.DataSerializer.DataSource;
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
43 import org.tmatesoft.hg.repo.HgChangelog;
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
44 import org.tmatesoft.hg.repo.HgDataFile;
652
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
45 import org.tmatesoft.hg.repo.HgPhase;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
46 import org.tmatesoft.hg.repo.HgRuntimeException;
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
47 import org.tmatesoft.hg.util.ByteChannel;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
48 import org.tmatesoft.hg.util.CancelledException;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 import org.tmatesoft.hg.util.Pair;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 import org.tmatesoft.hg.util.Path;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 /**
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
53 * Name: CommitObject, FutureCommit or PendingCommit
613
f41dd9a3b8af Remove few Experimental annotations as the API they've marked graduates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 612
diff changeset
54 * The only public API now: {@link HgCommitCommand}.
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 *
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 * @author Artem Tikhomirov
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 * @author TMate Software Ltd.
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 */
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
59 public final class CommitFacility {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
60 private final Internals repo;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 private final int p1Commit, p2Commit;
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
62 private Map<Path, Pair<HgDataFile, DataSource>> files = new LinkedHashMap<Path, Pair<HgDataFile, DataSource>>();
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
63 private Set<Path> removals = new TreeSet<Path>();
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
64 private String branch, user;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
66 public CommitFacility(Internals hgRepo, int parentCommit) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 this(hgRepo, parentCommit, NO_REVISION);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
70 public CommitFacility(Internals hgRepo, int parent1Commit, int parent2Commit) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 repo = hgRepo;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 p1Commit = parent1Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 p2Commit = parent2Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 if (parent1Commit != NO_REVISION && parent1Commit == parent2Commit) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 throw new IllegalArgumentException("Merging same revision is dubious");
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 public boolean isMerge() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 return p1Commit != NO_REVISION && p2Commit != NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
83 public void add(HgDataFile dataFile, DataSource content) {
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
84 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
85 throw new IllegalArgumentException();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
86 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
87 removals.remove(dataFile.getPath());
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
88 files.put(dataFile.getPath(), new Pair<HgDataFile, DataSource>(dataFile, content));
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 }
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
90
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
91 public void forget(HgDataFile dataFile) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
92 files.remove(dataFile.getPath());
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
93 removals.add(dataFile.getPath());
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
94 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
95
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
96 public void branch(String branchName) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
97 branch = branchName;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
98 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
100 public void user(String userName) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
101 user = userName;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
102 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
103
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: 616
diff changeset
104 // this method doesn't roll transaction back in case of failure, caller's responsibility
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: 616
diff changeset
105 // this method expects repository to be locked, if needed
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
106 public Nodeid commit(String message, Transaction transaction) throws HgIOException, HgRepositoryLockException, HgRuntimeException {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
107 final HgChangelog clog = repo.getRepo().getChangelog();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 final int clogRevisionIndex = clog.getRevisionCount();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 ManifestRevision c1Manifest = new ManifestRevision(null, null);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 ManifestRevision c2Manifest = new ManifestRevision(null, null);
607
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 605
diff changeset
111 final Nodeid p1Cset = p1Commit == NO_REVISION ? null : clog.getRevision(p1Commit);
66f1cc23b906 Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 605
diff changeset
112 final Nodeid p2Cset = p2Commit == NO_REVISION ? null : clog.getRevision(p2Commit);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 if (p1Commit != NO_REVISION) {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
114 repo.getRepo().getManifest().walk(p1Commit, p1Commit, c1Manifest);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 if (p2Commit != NO_REVISION) {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
117 repo.getRepo().getManifest().walk(p2Commit, p2Commit, c2Manifest);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 // Pair<Integer, Integer> manifestParents = getManifestParents();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 Pair<Integer, Integer> manifestParents = new Pair<Integer, Integer>(c1Manifest.revisionIndex(), c2Manifest.revisionIndex());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 TreeMap<Path, Nodeid> newManifestRevision = new TreeMap<Path, Nodeid>();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 HashMap<Path, Pair<Integer, Integer>> fileParents = new HashMap<Path, Pair<Integer,Integer>>();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 for (Path f : c1Manifest.files()) {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
124 HgDataFile df = repo.getRepo().getFileNode(f);
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
125 Nodeid fileKnownRev1 = c1Manifest.nodeid(f), fileKnownRev2;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
126 final int fileRevIndex1 = df.getRevisionIndex(fileKnownRev1);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
127 final int fileRevIndex2;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
128 if ((fileKnownRev2 = c2Manifest.nodeid(f)) != null) {
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
129 // merged files
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
130 fileRevIndex2 = df.getRevisionIndex(fileKnownRev2);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
131 } else {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
132 fileRevIndex2 = NO_REVISION;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
133 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
134
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
135 fileParents.put(f, new Pair<Integer, Integer>(fileRevIndex1, fileRevIndex2));
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
136 newManifestRevision.put(f, fileKnownRev1);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 //
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
139 // Forget removed
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
140 for (Path p : removals) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
141 newManifestRevision.remove(p);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
142 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
143 //
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
144 saveCommitMessage(message);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
145 //
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
146 // Register new/changed
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 660
diff changeset
147 FNCacheFile.Mediator fncache = new FNCacheFile.Mediator(repo, transaction);
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
148 ArrayList<Path> touchInDirstate = new ArrayList<Path>();
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
149 for (Pair<HgDataFile, DataSource> e : files.values()) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 HgDataFile df = e.first();
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
151 DataSource bds = e.second();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 Pair<Integer, Integer> fp = fileParents.get(df.getPath());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 if (fp == null) {
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
154 // NEW FILE, either just added or resurrected from p2
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
155 Nodeid fileRevInP2;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
156 if ((fileRevInP2 = c2Manifest.nodeid(df.getPath())) != null) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
157 fp = new Pair<Integer, Integer>(df.getRevisionIndex(fileRevInP2), NO_REVISION);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
158 } else {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
159 // brand new
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
160 fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
161 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 }
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
163 // TODO if fp.first() != NO_REVISION and fp.second() != NO_REVISION check if one
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
164 // revision is ancestor of another and use the latest as p1, then
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
165 Nodeid fileRev = null;
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 660
diff changeset
166 final boolean isNewFile = !df.exists();
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
167 if (fp.first() != NO_REVISION && fp.second() == NO_REVISION && !isNewFile) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
168 // compare file contents to see if anything has changed, and reuse old revision, if unchanged.
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
169 // XXX ineffective, need better access to revision conten
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
170 ByteArraySerializer bas = new ByteArraySerializer();
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
171 bds.serialize(bas);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
172 final byte[] newContent = bas.toByteArray();
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
173 // unless there's a way to reset DataSource, replace it with the content just read
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
174 bds = new DataSerializer.ByteArrayDataSource(newContent);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
175 if (new ComparatorChannel(newContent).same(df, fp.first())) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
176 fileRev = df.getRevision(fp.first());
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
177 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
178 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
179 if (fileRev == null) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
180 RevlogStream contentStream = repo.getImplAccess().getStream(df);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
181 RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream, transaction);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
182 fileRev = fileWriter.addRevision(bds, clogRevisionIndex, fp.first(), fp.second()).second();
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
183 if (isNewFile) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
184 // registerNew shall go after fileWriter.addRevision as it needs to know if data is inlined or not
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
185 fncache.registerNew(df.getPath(), contentStream);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
186 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
187 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 newManifestRevision.put(df.getPath(), fileRev);
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
189 touchInDirstate.add(df.getPath());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 //
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 664
diff changeset
192 final EncodingHelper encHelper = repo.buildFileNameEncodingHelper();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 664
diff changeset
193 //
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 // Manifest
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 664
diff changeset
195 final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder(encHelper);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 for (Map.Entry<Path, Nodeid> me : newManifestRevision.entrySet()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 manifestBuilder.add(me.getKey().toString(), me.getValue());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 }
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: 616
diff changeset
199 RevlogStreamWriter manifestWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getManifestStream(), transaction);
660
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
200 Nodeid manifestRev = manifestWriter.addRevision(manifestBuilder, clogRevisionIndex, manifestParents.first(), manifestParents.second()).second();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 // Changelog
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 664
diff changeset
203 final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder(encHelper);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 changelogBuilder.setModified(files.keySet());
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
205 changelogBuilder.branch(branch == null ? DEFAULT_BRANCH_NAME : branch);
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
206 changelogBuilder.user(String.valueOf(user));
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 617
diff changeset
207 changelogBuilder.manifest(manifestRev).comment(message);
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: 616
diff changeset
208 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getChangelogStream(), transaction);
660
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
209 Nodeid changesetRev = changelogWriter.addRevision(changelogBuilder, clogRevisionIndex, p1Commit, p2Commit).second();
664
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 660
diff changeset
210 // TODO move dirstate and bookmark update update to an external facility
ae2d439fbed3 Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 660
diff changeset
211 fncache.complete();
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
212 String oldBranchValue = DirstateReader.readBranch(repo);
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
213 String newBranchValue = branch == null ? DEFAULT_BRANCH_NAME : branch;
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
214 if (!oldBranchValue.equals(newBranchValue)) {
619
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
215 // prepare undo.branch as described in http://mercurial.selenic.com/wiki/FileFormats#undo..2A
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: 616
diff changeset
216 File branchFile = transaction.prepare(repo.getRepositoryFile(Branch), repo.getRepositoryFile(UndoBranch));
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
217 FileOutputStream fos = null;
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
218 try {
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
219 fos = new FileOutputStream(branchFile);
622
4e6179bde4fc Update to comply with Java 1.5 target
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 621
diff changeset
220 fos.write(newBranchValue.getBytes(EncodingHelper.getUTF8().name())); // XXX Java 1.5
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
221 fos.flush();
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: 616
diff changeset
222 fos.close();
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: 616
diff changeset
223 fos = null;
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: 616
diff changeset
224 transaction.done(branchFile);
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
225 } catch (IOException 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: 616
diff changeset
226 transaction.failure(branchFile, ex);
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
227 repo.getLog().dump(getClass(), Error, ex, "Failed to write branch information, error ignored");
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
228 } finally {
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
229 try {
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
230 if (fos != null) {
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
231 fos.close();
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
232 }
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
233 } catch (IOException ex) {
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
234 repo.getLog().dump(getClass(), Error, ex, null);
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
235 }
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
236 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
237 }
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: 616
diff changeset
238 // bring dirstate up to commit state, TODO share this code with HgAddRemoveCommand
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
239 final DirstateBuilder dirstateBuilder = new DirstateBuilder(repo);
705
b4242b7e7dfe Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 667
diff changeset
240 dirstateBuilder.fillFrom(new DirstateReader(repo, repo.getSessionContext().getPathFactory()));
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
241 for (Path p : removals) {
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
242 dirstateBuilder.recordRemoved(p);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
243 }
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
244 for (Path p : touchInDirstate) {
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
245 dirstateBuilder.recordUncertain(p);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
246 }
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
247 dirstateBuilder.parents(changesetRev, Nodeid.NULL);
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: 616
diff changeset
248 dirstateBuilder.serialize(transaction);
605
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
249 // update bookmarks
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
250 if (p1Commit != NO_REVISION || p2Commit != NO_REVISION) {
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
251 repo.getRepo().getBookmarks().updateActive(p1Cset, p2Cset, changesetRev);
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
252 }
652
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
253 PhasesHelper phaseHelper = new PhasesHelper(repo);
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
254 HgPhase newCommitPhase = HgPhase.parse(repo.getRepo().getConfiguration().getStringValue("phases", "new-commit", HgPhase.Draft.mercurialString()));
cd77bf51b562 Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
255 phaseHelper.newCommitNode(changesetRev, newCommitPhase);
610
5c68567b3645 Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 607
diff changeset
256 // TODO Revisit: might be reasonable to send out a "Repo changed" notification, to clear
5c68567b3645 Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 607
diff changeset
257 // e.g. cached branch, tags and so on, not to rely on file change detection methods?
616
5e0313485eef encode directories as demanded by fncache format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 613
diff changeset
258 // The same notification might come useful once Pull is implemented
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 return changesetRev;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
260 }
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
261
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
262 private void saveCommitMessage(String message) throws HgIOException {
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
263 File lastMessage = repo.getRepositoryFile(LastMessage);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
264 // do not attempt to write if we are going to fail anyway
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
265 if ((lastMessage.isFile() && !lastMessage.canWrite()) || !lastMessage.getParentFile().canWrite()) {
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
266 return;
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
267 }
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
268 FileWriter w = null;
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
269 try {
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
270 w = new FileWriter(lastMessage);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
271 w.write(message == null ? new String() : message);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
272 w.flush();
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
273 } catch (IOException ex) {
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
274 throw new HgIOException("Failed to save last commit message", ex, lastMessage);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
275 } finally {
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 652
diff changeset
276 new FileUtils(repo.getLog(), this).closeQuietly(w, lastMessage);
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
277 }
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
278 }
708
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
279
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
280 private static class ComparatorChannel implements ByteChannel {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
281 private int index;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
282 private final byte[] content;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
283
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
284 public ComparatorChannel(byte[] contentToCompare) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
285 content = contentToCompare;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
286 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
287
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
288 public int write(ByteBuffer buffer) throws IOException, CancelledException {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
289 int consumed = 0;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
290 while (buffer.hasRemaining()) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
291 byte b = buffer.get();
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
292 consumed++;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
293 if (content[index++] != b) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
294 throw new CancelledException();
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
295 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
296 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
297 return consumed;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
298 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
299
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
300 public boolean same(HgDataFile df, int fileRevIndex) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
301 index = 0;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
302 try {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
303 df.contentWithFilters(fileRevIndex, this);
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
304 return index == content.length;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
305 } catch (CancelledException ex) {
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
306 // comparison failed, content differs, ok to go on
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
307 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
308 return false;
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
309 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
310 }
4ffc17c0b534 Merge: tests for resolver and complex scenario. Enable commit for merged revisions. Reuse file revisions if nothing changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 705
diff changeset
311
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
312 /*
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
313 private Pair<Integer, Integer> getManifestParents() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
314 return new Pair<Integer, Integer>(extractManifestRevisionIndex(p1Commit), extractManifestRevisionIndex(p2Commit));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
315 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
316
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
317 private int extractManifestRevisionIndex(int clogRevIndex) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
318 if (clogRevIndex == NO_REVISION) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
319 return NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
320 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
321 RawChangeset commitObject = repo.getChangelog().range(clogRevIndex, clogRevIndex).get(0);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
322 Nodeid manifestRev = commitObject.manifest();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
323 if (manifestRev.isNull()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
324 return NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
325 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
326 return repo.getManifest().getRevisionIndex(manifestRev);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
327 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
328 */
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
329 }