Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/CommitFacility.java @ 679:19f5167c2155
HgParentChildMap: deduce common ancestor functionality
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 20 Jul 2013 17:40:52 +0200 |
parents | fba85bc1dfb8 |
children | b4242b7e7dfe |
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.repo.HgRepositoryFiles.Branch; |
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
|
23 import static org.tmatesoft.hg.repo.HgRepositoryFiles.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
|
24 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 |
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
|
26 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
|
27 import java.io.FileOutputStream; |
636
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
28 import java.io.FileWriter; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
29 import java.io.IOException; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
30 import java.util.ArrayList; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.util.HashMap; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import java.util.LinkedHashMap; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import java.util.Map; |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
34 import java.util.Set; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import java.util.TreeMap; |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
36 import java.util.TreeSet; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
586
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
38 import org.tmatesoft.hg.core.HgCommitCommand; |
588
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
39 import org.tmatesoft.hg.core.HgIOException; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.core.HgRepositoryLockException; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 import org.tmatesoft.hg.core.Nodeid; |
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; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 import org.tmatesoft.hg.util.Pair; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 import org.tmatesoft.hg.util.Path; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 /** |
586
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
51 * 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
|
52 * The only public API now: {@link HgCommitCommand}. |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 * |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 * @author Artem Tikhomirov |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 * @author TMate Software Ltd. |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 */ |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
57 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
|
58 private final Internals repo; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 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
|
60 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
|
61 private Set<Path> removals = new TreeSet<Path>(); |
586
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
62 private String branch, user; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
591
e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
588
diff
changeset
|
64 public CommitFacility(Internals hgRepo, int parentCommit) { |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 this(hgRepo, parentCommit, NO_REVISION); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 |
591
e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
588
diff
changeset
|
68 public CommitFacility(Internals hgRepo, int parent1Commit, int parent2Commit) { |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 repo = hgRepo; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 p1Commit = parent1Commit; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 p2Commit = parent2Commit; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 if (parent1Commit != NO_REVISION && parent1Commit == parent2Commit) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 throw new IllegalArgumentException("Merging same revision is dubious"); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
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 public boolean isMerge() { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 return p1Commit != NO_REVISION && p2Commit != NO_REVISION; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
617
diff
changeset
|
81 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
|
82 if (content == null) { |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
83 throw new IllegalArgumentException(); |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
84 } |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
85 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
|
86 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
|
87 } |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
88 |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
89 public void forget(HgDataFile dataFile) { |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
90 files.remove(dataFile.getPath()); |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
91 removals.add(dataFile.getPath()); |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
92 } |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
93 |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
94 public void branch(String branchName) { |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
95 branch = branchName; |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
96 } |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 |
586
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
98 public void user(String userName) { |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
99 user = userName; |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
100 } |
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
101 |
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
|
102 // 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
|
103 // 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
|
104 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
|
105 final HgChangelog clog = repo.getRepo().getChangelog(); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 final int clogRevisionIndex = clog.getRevisionCount(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 ManifestRevision c1Manifest = new ManifestRevision(null, null); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
112 repo.getRepo().getManifest().walk(p1Commit, p1Commit, c1Manifest); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 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
|
115 repo.getRepo().getManifest().walk(p2Commit, p2Commit, c2Manifest); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 // Pair<Integer, Integer> manifestParents = getManifestParents(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 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
|
119 TreeMap<Path, Nodeid> newManifestRevision = new TreeMap<Path, Nodeid>(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 Nodeid fileKnownRev1 = c1Manifest.nodeid(f), fileKnownRev2; |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
124 final int fileRevIndex1 = df.getRevisionIndex(fileKnownRev1); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
125 final int fileRevIndex2; |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
126 if ((fileKnownRev2 = c2Manifest.nodeid(f)) != null) { |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
127 // merged files |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
128 fileRevIndex2 = df.getRevisionIndex(fileKnownRev2); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
129 } else { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
130 fileRevIndex2 = NO_REVISION; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
131 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
132 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
133 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
|
134 newManifestRevision.put(f, fileKnownRev1); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 // |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
137 // Forget removed |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
138 for (Path p : removals) { |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
139 newManifestRevision.remove(p); |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
140 } |
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
141 // |
636
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
142 saveCommitMessage(message); |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
143 // |
559
6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
540
diff
changeset
|
144 // Register new/changed |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
660
diff
changeset
|
145 FNCacheFile.Mediator fncache = new FNCacheFile.Mediator(repo, transaction); |
588
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
146 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
|
147 for (Pair<HgDataFile, DataSource> e : files.values()) { |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 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
|
149 DataSource bds = e.second(); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 Pair<Integer, Integer> fp = fileParents.get(df.getPath()); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 if (fp == null) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 // NEW FILE |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 } |
621
99ad1e3a4e4d
RevlogStream: be aware of existence (not HgDataFile), facilitate use of an added HgDataFile over a commit; Rollback: be more sensitive about file changes (file size is not enough: write/rollback leaves it intact); tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
619
diff
changeset
|
155 RevlogStream contentStream = repo.getImplAccess().getStream(df); |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
660
diff
changeset
|
156 final boolean isNewFile = !df.exists(); |
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
|
157 RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream, transaction); |
660
4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
654
diff
changeset
|
158 Nodeid fileRev = fileWriter.addRevision(bds, clogRevisionIndex, fp.first(), fp.second()).second(); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 newManifestRevision.put(df.getPath(), fileRev); |
588
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
160 touchInDirstate.add(df.getPath()); |
664
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
660
diff
changeset
|
161 if (isNewFile) { |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
660
diff
changeset
|
162 // registerNew shall go after fileWriter.addRevision as it needs to know if data is inlined or not |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
660
diff
changeset
|
163 fncache.registerNew(df.getPath(), contentStream); |
ae2d439fbed3
Utilize transaction when writing fncache. Better HgIOException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
660
diff
changeset
|
164 } |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 // |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
664
diff
changeset
|
167 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
|
168 // |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 // Manifest |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
664
diff
changeset
|
170 final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder(encHelper); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 for (Map.Entry<Path, Nodeid> me : newManifestRevision.entrySet()) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 manifestBuilder.add(me.getKey().toString(), me.getValue()); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 } |
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
|
174 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
|
175 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
|
176 // |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 // Changelog |
667
fba85bc1dfb8
Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
664
diff
changeset
|
178 final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder(encHelper); |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 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
|
180 changelogBuilder.branch(branch == null ? DEFAULT_BRANCH_NAME : branch); |
586
73c20c648c1f
HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
563
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 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
|
185 // 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 // 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
|
191 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
|
192 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
|
193 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
|
194 fos = new FileOutputStream(branchFile); |
622
4e6179bde4fc
Update to comply with Java 1.5 target
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
621
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 } 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
|
201 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
|
202 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
|
203 } 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
|
204 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
|
205 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
|
206 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
|
207 } |
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
|
208 } 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
|
209 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
|
210 } |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
211 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
212 } |
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
|
213 // 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
|
214 final DirstateBuilder dirstateBuilder = new DirstateBuilder(repo); |
e447384f3771
CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
588
diff
changeset
|
215 dirstateBuilder.fillFrom(new DirstateReader(repo, new Path.SimpleSource())); |
588
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
216 for (Path p : removals) { |
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
217 dirstateBuilder.recordRemoved(p); |
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
218 } |
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
219 for (Path p : touchInDirstate) { |
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
220 dirstateBuilder.recordUncertain(p); |
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
221 } |
41218d84842a
Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
586
diff
changeset
|
222 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
|
223 dirstateBuilder.serialize(transaction); |
605
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
591
diff
changeset
|
224 // update bookmarks |
c56edf42be64
Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
591
diff
changeset
|
225 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
|
226 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
|
227 } |
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
|
228 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
|
229 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
|
230 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
|
231 // 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
|
232 // 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
|
233 // 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
|
234 return changesetRev; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 } |
636
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
236 |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
237 private void saveCommitMessage(String message) throws HgIOException { |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
238 File lastMessage = repo.getRepositoryFile(LastMessage); |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
239 // 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
|
240 if ((lastMessage.isFile() && !lastMessage.canWrite()) || !lastMessage.getParentFile().canWrite()) { |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
241 return; |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
242 } |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
243 FileWriter w = null; |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
244 try { |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
245 w = new FileWriter(lastMessage); |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
246 w.write(message == null ? new String() : message); |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
247 w.flush(); |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
248 } catch (IOException ex) { |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
249 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
|
250 } finally { |
654
12a4f60ea972
1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
652
diff
changeset
|
251 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
|
252 } |
ffce73efa2c2
HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
253 } |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
254 /* |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
255 private Pair<Integer, Integer> getManifestParents() { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
256 return new Pair<Integer, Integer>(extractManifestRevisionIndex(p1Commit), extractManifestRevisionIndex(p2Commit)); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
257 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
258 |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
259 private int extractManifestRevisionIndex(int clogRevIndex) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
260 if (clogRevIndex == NO_REVISION) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
261 return NO_REVISION; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
262 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
263 RawChangeset commitObject = repo.getChangelog().range(clogRevIndex, clogRevIndex).get(0); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
264 Nodeid manifestRev = commitObject.manifest(); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
265 if (manifestRev.isNull()) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
266 return NO_REVISION; |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
267 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
268 return repo.getManifest().getRevisionIndex(manifestRev); |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
269 } |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
270 */ |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
271 } |