annotate src/org/tmatesoft/hg/internal/CommitFacility.java @ 607:66f1cc23b906

Refresh revlogs if a change to a file has been detected; do not force reload of the whole repository
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 07 May 2013 16:52:46 +0200
parents c56edf42be64
children 5c68567b3645
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
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
21 import java.io.IOException;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.nio.ByteBuffer;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
23 import java.util.ArrayList;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.HashMap;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.LinkedHashMap;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.util.Map;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
27 import java.util.Set;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.TreeMap;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
29 import java.util.TreeSet;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
31 import org.tmatesoft.hg.core.HgCommitCommand;
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
32 import org.tmatesoft.hg.core.HgIOException;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import org.tmatesoft.hg.core.HgRepositoryLockException;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import org.tmatesoft.hg.core.Nodeid;
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
35 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
36 import org.tmatesoft.hg.repo.HgDataFile;
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
37 import org.tmatesoft.hg.repo.HgRepository;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.util.Pair;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.util.Path;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
40 import org.tmatesoft.hg.util.LogFacility.Severity;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 /**
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * WORK IN PROGRESS
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
44 * Name: CommitObject, FutureCommit or PendingCommit
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
45 * Only public API now: {@link HgCommitCommand}.
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 *
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 * @author Artem Tikhomirov
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 * @author TMate Software Ltd.
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 @Experimental(reason="Work in progress")
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
51 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
52 private final Internals repo;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 private final int p1Commit, p2Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 private Map<Path, Pair<HgDataFile, ByteDataSupplier>> files = new LinkedHashMap<Path, Pair<HgDataFile, ByteDataSupplier>>();
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
55 private Set<Path> removals = new TreeSet<Path>();
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
56 private String branch, user;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
58 public CommitFacility(Internals hgRepo, int parentCommit) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 this(hgRepo, parentCommit, NO_REVISION);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
62 public CommitFacility(Internals hgRepo, int parent1Commit, int parent2Commit) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 repo = hgRepo;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 p1Commit = parent1Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 p2Commit = parent2Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 if (parent1Commit != NO_REVISION && parent1Commit == parent2Commit) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 throw new IllegalArgumentException("Merging same revision is dubious");
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 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 public boolean isMerge() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 return p1Commit != NO_REVISION && p2Commit != NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
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 public void add(HgDataFile dataFile, ByteDataSupplier content) {
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
76 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
77 throw new IllegalArgumentException();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
78 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
79 removals.remove(dataFile.getPath());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 files.put(dataFile.getPath(), new Pair<HgDataFile, ByteDataSupplier>(dataFile, content));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
82
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
83 public void forget(HgDataFile dataFile) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
84 files.remove(dataFile.getPath());
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
85 removals.add(dataFile.getPath());
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
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
88 public void branch(String branchName) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
89 branch = branchName;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
90 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
92 public void user(String userName) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
93 user = userName;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
94 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
95
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
96 public Nodeid commit(String message) throws HgIOException, HgRepositoryLockException {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
97 final HgChangelog clog = repo.getRepo().getChangelog();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 final int clogRevisionIndex = clog.getRevisionCount();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 ManifestRevision c1Manifest = new ManifestRevision(null, null);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 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
101 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
102 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
103 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
104 repo.getRepo().getManifest().walk(p1Commit, p1Commit, c1Manifest);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 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
107 repo.getRepo().getManifest().walk(p2Commit, p2Commit, c2Manifest);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 // Pair<Integer, Integer> manifestParents = getManifestParents();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 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
111 TreeMap<Path, Nodeid> newManifestRevision = new TreeMap<Path, Nodeid>();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 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
113 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
114 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
115 Nodeid fileKnownRev1 = c1Manifest.nodeid(f), fileKnownRev2;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
116 final int fileRevIndex1 = df.getRevisionIndex(fileKnownRev1);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
117 final int fileRevIndex2;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
118 if ((fileKnownRev2 = c2Manifest.nodeid(f)) != null) {
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
119 // merged files
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
120 fileRevIndex2 = df.getRevisionIndex(fileKnownRev2);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
121 } else {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
122 fileRevIndex2 = NO_REVISION;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
123 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
124
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
125 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
126 newManifestRevision.put(f, fileKnownRev1);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 //
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
129 // Forget removed
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
130 for (Path p : removals) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
131 newManifestRevision.remove(p);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
132 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
133 //
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
134 // Register new/changed
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
135 ArrayList<Path> newlyAddedFiles = new ArrayList<Path>();
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
136 ArrayList<Path> touchInDirstate = new ArrayList<Path>();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 for (Pair<HgDataFile, ByteDataSupplier> e : files.values()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 HgDataFile df = e.first();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 Pair<Integer, Integer> fp = fileParents.get(df.getPath());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 if (fp == null) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 // NEW FILE
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 ByteDataSupplier bds = e.second();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 // FIXME quickfix, instead, pass ByteDataSupplier directly to RevlogStreamWriter
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 ByteBuffer bb = ByteBuffer.allocate(2048);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 ByteArrayChannel bac = new ByteArrayChannel();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 while (bds.read(bb) != -1) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 bb.flip();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 bac.write(bb);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 bb.clear();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 }
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
153 RevlogStream contentStream;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
154 if (df.exists()) {
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
155 contentStream = repo.getImplAccess().getStream(df);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
156 } else {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
157 contentStream = repo.createStoreFile(df.getPath());
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
158 newlyAddedFiles.add(df.getPath());
540
67d4b0f73984 Include commit tests into Ant's test suite
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
159 // FIXME df doesn't get df.content updated, and clients
67d4b0f73984 Include commit tests into Ant's test suite
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
160 // that would attempt to access newly added file after commit would fail
67d4b0f73984 Include commit tests into Ant's test suite
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
161 // (despite the fact the file is in there)
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
162 }
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
163 RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 Nodeid fileRev = fileWriter.addRevision(bac.toArray(), clogRevisionIndex, fp.first(), fp.second());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 newManifestRevision.put(df.getPath(), fileRev);
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
166 touchInDirstate.add(df.getPath());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 // Manifest
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder();
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 }
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
174 RevlogStreamWriter manifestWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getManifestStream());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 Nodeid manifestRev = manifestWriter.addRevision(manifestBuilder.build(), clogRevisionIndex, manifestParents.first(), manifestParents.second());
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
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 changelogBuilder.setModified(files.keySet());
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
180 changelogBuilder.branch(branch == null ? HgRepository.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));
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182 byte[] clogContent = changelogBuilder.build(manifestRev, message);
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
183 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getChangelogStream());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 Nodeid changesetRev = changelogWriter.addRevision(clogContent, clogRevisionIndex, p1Commit, p2Commit);
605
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
185 // FIXME move fncache update to an external facility, along with dirstate and bookmark update
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
186 if (!newlyAddedFiles.isEmpty() && repo.fncacheInUse()) {
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
187 FNCacheFile fncache = new FNCacheFile(repo);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
188 for (Path p : newlyAddedFiles) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
189 fncache.add(p);
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
190 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
191 try {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
192 fncache.write();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
193 } catch (IOException ex) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
194 // see comment above for fnchache.read()
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
195 repo.getSessionContext().getLog().dump(getClass(), Severity.Error, ex, "Failed to write fncache, error ignored");
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
196 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
197 }
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
198 // bring dirstate up to commit state
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
199 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
200 dirstateBuilder.fillFrom(new DirstateReader(repo, new Path.SimpleSource()));
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
201 for (Path p : removals) {
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
202 dirstateBuilder.recordRemoved(p);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
203 }
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
204 for (Path p : touchInDirstate) {
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
205 dirstateBuilder.recordUncertain(p);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
206 }
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
207 dirstateBuilder.parents(changesetRev, Nodeid.NULL);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
208 dirstateBuilder.serialize();
605
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
209 // update bookmarks
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
210 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
211 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
212 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 return changesetRev;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215 /*
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 private Pair<Integer, Integer> getManifestParents() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 return new Pair<Integer, Integer>(extractManifestRevisionIndex(p1Commit), extractManifestRevisionIndex(p2Commit));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 private int extractManifestRevisionIndex(int clogRevIndex) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 if (clogRevIndex == NO_REVISION) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222 return NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 RawChangeset commitObject = repo.getChangelog().range(clogRevIndex, clogRevIndex).get(0);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 Nodeid manifestRev = commitObject.manifest();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
226 if (manifestRev.isNull()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
227 return NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
228 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 return repo.getManifest().getRevisionIndex(manifestRev);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 */
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 // unlike DataAccess (which provides structured access), this one
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 // deals with a sequence of bytes, when there's no need in structure of the data
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
235 // FIXME java.nio.ReadableByteChannel or ByteStream/ByteSequence(read, length, reset)
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
236 // SHALL be inline with util.ByteChannel, reading bytes from HgDataFile, preferably DataAccess#readBytes(BB) to match API,
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
237 // and a wrap for ByteVector
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 public interface ByteDataSupplier { // TODO look if can resolve DataAccess in HgCloneCommand visibility issue
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
239 // FIXME needs lifecycle, e.g. for supplier that reads from WC
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 int read(ByteBuffer buf);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 public interface ByteDataConsumer {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 void write(ByteBuffer buf);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246 }