annotate src/org/tmatesoft/hg/internal/CommitFacility.java @ 615:84104448a0bf

Test for repository locks
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 13 May 2013 22:48:29 +0200
parents f41dd9a3b8af
children 5e0313485eef
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;
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
21 import static org.tmatesoft.hg.repo.HgRepositoryFiles.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
22 import static org.tmatesoft.hg.util.LogFacility.Severity.Error;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23
612
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
24 import java.io.File;
dca70c0b1f74 Test tags, branches and hgingore information get refreshed on external (and/or internal) change
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
25 import java.io.FileOutputStream;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
26 import java.io.IOException;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.nio.ByteBuffer;
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
28 import java.util.ArrayList;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import java.util.HashMap;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.LinkedHashMap;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.Map;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
32 import java.util.Set;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 import java.util.TreeMap;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
34 import java.util.TreeSet;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
36 import org.tmatesoft.hg.core.HgCommitCommand;
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
37 import org.tmatesoft.hg.core.HgIOException;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.core.HgRepositoryLockException;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 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
40 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
41 import org.tmatesoft.hg.repo.HgDataFile;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 import org.tmatesoft.hg.util.Pair;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 import org.tmatesoft.hg.util.Path;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 /**
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
46 * 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
47 * The only public API now: {@link HgCommitCommand}.
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 *
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 * @author Artem Tikhomirov
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 * @author TMate Software Ltd.
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 */
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
52 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
53 private final Internals repo;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 private final int p1Commit, p2Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 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
56 private Set<Path> removals = new TreeSet<Path>();
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
57 private String branch, user;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
59 public CommitFacility(Internals hgRepo, int parentCommit) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 this(hgRepo, parentCommit, NO_REVISION);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
63 public CommitFacility(Internals hgRepo, int parent1Commit, int parent2Commit) {
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 repo = hgRepo;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 p1Commit = parent1Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 p2Commit = parent2Commit;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 if (parent1Commit != NO_REVISION && parent1Commit == parent2Commit) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 throw new IllegalArgumentException("Merging same revision is dubious");
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
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 public boolean isMerge() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 return p1Commit != NO_REVISION && p2Commit != NO_REVISION;
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 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
77 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
78 throw new IllegalArgumentException();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
79 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
80 removals.remove(dataFile.getPath());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 files.put(dataFile.getPath(), new Pair<HgDataFile, ByteDataSupplier>(dataFile, content));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 }
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
83
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
84 public void forget(HgDataFile dataFile) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
85 files.remove(dataFile.getPath());
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
86 removals.add(dataFile.getPath());
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
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
89 public void branch(String branchName) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
90 branch = branchName;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
91 }
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
93 public void user(String userName) {
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
94 user = userName;
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
95 }
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
96
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
97 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
98 final HgChangelog clog = repo.getRepo().getChangelog();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 final int clogRevisionIndex = clog.getRevisionCount();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 ManifestRevision c1Manifest = new ManifestRevision(null, null);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 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
102 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
103 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
104 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
105 repo.getRepo().getManifest().walk(p1Commit, p1Commit, c1Manifest);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 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
108 repo.getRepo().getManifest().walk(p2Commit, p2Commit, c2Manifest);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 // Pair<Integer, Integer> manifestParents = getManifestParents();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 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
112 TreeMap<Path, Nodeid> newManifestRevision = new TreeMap<Path, Nodeid>();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 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
114 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
115 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
116 Nodeid fileKnownRev1 = c1Manifest.nodeid(f), fileKnownRev2;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
117 final int fileRevIndex1 = df.getRevisionIndex(fileKnownRev1);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
118 final int fileRevIndex2;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
119 if ((fileKnownRev2 = c2Manifest.nodeid(f)) != null) {
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
120 // merged files
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
121 fileRevIndex2 = df.getRevisionIndex(fileKnownRev2);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
122 } else {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
123 fileRevIndex2 = NO_REVISION;
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
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
126 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
127 newManifestRevision.put(f, fileKnownRev1);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 //
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
130 // Forget removed
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
131 for (Path p : removals) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
132 newManifestRevision.remove(p);
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 //
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 540
diff changeset
135 // Register new/changed
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
136 ArrayList<Path> newlyAddedFiles = new ArrayList<Path>();
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
137 ArrayList<Path> touchInDirstate = new ArrayList<Path>();
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 for (Pair<HgDataFile, ByteDataSupplier> e : files.values()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 HgDataFile df = e.first();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 Pair<Integer, Integer> fp = fileParents.get(df.getPath());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 if (fp == null) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 // NEW FILE
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 ByteDataSupplier bds = e.second();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 // FIXME quickfix, instead, pass ByteDataSupplier directly to RevlogStreamWriter
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 ByteBuffer bb = ByteBuffer.allocate(2048);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 ByteArrayChannel bac = new ByteArrayChannel();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 while (bds.read(bb) != -1) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 bb.flip();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 bac.write(bb);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 bb.clear();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 }
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
154 RevlogStream contentStream;
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
155 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
156 contentStream = repo.getImplAccess().getStream(df);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
157 } else {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
158 contentStream = repo.createStoreFile(df.getPath());
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
159 newlyAddedFiles.add(df.getPath());
540
67d4b0f73984 Include commit tests into Ant's test suite
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 539
diff changeset
160 // 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
161 // 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
162 // (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
163 }
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
164 RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream);
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 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
166 newManifestRevision.put(df.getPath(), fileRev);
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
167 touchInDirstate.add(df.getPath());
538
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 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 // Manifest
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 for (Map.Entry<Path, Nodeid> me : newManifestRevision.entrySet()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 manifestBuilder.add(me.getKey().toString(), me.getValue());
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
591
e447384f3771 CommitFacility as internal class; refactored infrastructure around internals (access to RevlogStream)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 588
diff changeset
175 RevlogStreamWriter manifestWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getManifestStream());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 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
177 //
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 // Changelog
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 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
181 changelogBuilder.branch(branch == null ? DEFAULT_BRANCH_NAME : branch);
586
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
182 changelogBuilder.user(String.valueOf(user));
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 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
184 RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getChangelogStream());
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 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
186 // 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
187 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
188 FNCacheFile fncache = new FNCacheFile(repo);
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
189 for (Path p : newlyAddedFiles) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
190 fncache.add(p);
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
191 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
192 try {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
193 fncache.write();
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
194 } catch (IOException ex) {
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
195 // see comment above for fnchache.read()
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 repo.getLog().dump(getClass(), Error, ex, "Failed to write fncache, 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
197 }
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
198 }
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
199 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
200 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
201 if (!oldBranchValue.equals(newBranchValue)) {
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 File branchFile = repo.getRepositoryFile(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
203 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
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 fos = new FileOutputStream(branchFile);
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.write(newBranchValue.getBytes(EncodingHelper.getUTF8()));
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 fos.flush();
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, "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
210 } 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
211 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
212 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
213 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
214 }
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
215 } 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
216 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
217 }
539
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
218 }
9edfd5a223b8 Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
219 }
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
220 // 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
221 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
222 dirstateBuilder.fillFrom(new DirstateReader(repo, new Path.SimpleSource()));
588
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
223 for (Path p : removals) {
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
224 dirstateBuilder.recordRemoved(p);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
225 }
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
226 for (Path p : touchInDirstate) {
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
227 dirstateBuilder.recordUncertain(p);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
228 }
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
229 dirstateBuilder.parents(changesetRev, Nodeid.NULL);
41218d84842a Update dirstate after commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 586
diff changeset
230 dirstateBuilder.serialize();
605
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
231 // update bookmarks
c56edf42be64 Commit: update active bookmark with new revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 591
diff changeset
232 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
233 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
234 }
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
235 // 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
236 // e.g. cached branch, tags and so on, not to rely on file change detection methods?
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
237 // The same notificaion might come useful once Pull is implemented
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238 return changesetRev;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 /*
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 private Pair<Integer, Integer> getManifestParents() {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 return new Pair<Integer, Integer>(extractManifestRevisionIndex(p1Commit), extractManifestRevisionIndex(p2Commit));
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
245 private int extractManifestRevisionIndex(int clogRevIndex) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
246 if (clogRevIndex == NO_REVISION) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
247 return NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
248 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249 RawChangeset commitObject = repo.getChangelog().range(clogRevIndex, clogRevIndex).get(0);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 Nodeid manifestRev = commitObject.manifest();
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
251 if (manifestRev.isNull()) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 return NO_REVISION;
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
253 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 return repo.getManifest().getRevisionIndex(manifestRev);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
255 }
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 */
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 // unlike DataAccess (which provides structured access), this one
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259 // 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
260 // FIXME java.nio.ReadableByteChannel or ByteStream/ByteSequence(read, length, reset)
73c20c648c1f HgCommitCommand initial support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
261 // 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
262 // and a wrap for ByteVector
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
263 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
264 // 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
265 int read(ByteBuffer buf);
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
266 }
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 public interface ByteDataConsumer {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269 void write(ByteBuffer buf);
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 }