annotate src/org/tmatesoft/hg/core/HgInitCommand.java @ 652:cd77bf51b562

Push: tests. Commit respects phases.new-commit setting. Fix outgoing when changes are not children of common (Issue 47)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 02 Jul 2013 23:21:16 +0200
parents 4a0bab2c6da1
children
rev   line source
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.tmatesoft.hg.internal.RequiresFile.*;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import org.tmatesoft.hg.internal.RepoInitializer;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.repo.HgLookup;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.repo.HgRepository;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.util.CancelledException;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 /**
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 * Initialize empty local repository.
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 * <p>
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 * Two predefined alternatives are available, {@link #revlogV0() old} and {@link #revlogV1() new} mercurial format respectively.
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * <p>
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * Specific requirements may be turned off/on as needed if you know what you're doing.
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 *
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @see http://mercurial.selenic.com/wiki/RequiresFile
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author Artem Tikhomirov
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author TMate Software Ltd.
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 */
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 public class HgInitCommand extends HgAbstractCommand<HgInitCommand> {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private static final int V1_DEFAULT = REVLOGV1 | STORE | FNCACHE | DOTENCODE;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 private final HgLookup hgLookup;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private File location;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 private int requiresFlags;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public HgInitCommand() {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 this(null);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public HgInitCommand(HgLookup lookupEnv) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 hgLookup = lookupEnv;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 requiresFlags = V1_DEFAULT;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public HgInitCommand location(File repoLoc) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 location = repoLoc;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 return this;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 public HgInitCommand revlogV0() {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 requiresFlags = REVLOGV0;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 return this;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public HgInitCommand revlogV1() {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 requiresFlags = V1_DEFAULT;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 return this;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 public HgInitCommand store(boolean enable) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 return switchFlag(STORE, enable);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 public HgInitCommand fncache(boolean enable) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 return switchFlag(FNCACHE, enable);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 public HgInitCommand dotencode(boolean enable) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 return switchFlag(DOTENCODE, enable);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 public HgRepository execute() throws HgRepositoryNotFoundException, HgException, CancelledException {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 if (location == null) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 throw new IllegalArgumentException();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 File repoDir;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 if (".hg".equals(location.getName())) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 repoDir = location;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 } else {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 repoDir = new File(location, ".hg");
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 new RepoInitializer().setRequires(requiresFlags).initEmptyRepository(repoDir);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 return getNewRepository();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 public HgRepository getNewRepository() throws HgRepositoryNotFoundException {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 HgLookup l = hgLookup == null ? new HgLookup() : hgLookup;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 return l.detect(location);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 private HgInitCommand switchFlag(int flag, boolean enable) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 if (enable) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 requiresFlags |= flag;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 } else {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 requiresFlags &= ~flag;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 return this;
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }