annotate src/org/tmatesoft/hg/repo/HgInternals.java @ 707:42b88709e41d

Merge: support 'unresolved' resolution with MergeStateBuilder
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Aug 2013 19:22:59 +0200
parents 545b1d4cc11d
children
rev   line source
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 493
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 96
diff changeset
15 * contact TMate Software at support@hg4j.com
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
17 package org.tmatesoft.hg.repo;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
18
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.*;
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
20
269
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
21 import java.io.BufferedReader;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
22 import java.io.File;
269
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
23 import java.io.IOException;
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
24 import java.io.Reader;
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
25 import java.net.InetAddress;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
26 import java.net.UnknownHostException;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
27
442
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
28 import org.tmatesoft.hg.core.Nodeid;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
29 import org.tmatesoft.hg.internal.Experimental;
409
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
30 import org.tmatesoft.hg.internal.Internals;
673
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
31 import org.tmatesoft.hg.internal.Patch;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
32 import org.tmatesoft.hg.internal.RelativePathRewrite;
409
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
33 import org.tmatesoft.hg.internal.WinToNixPathRewrite;
673
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
34 import org.tmatesoft.hg.repo.HgBundle.GroupElement;
442
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
35 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
36 import org.tmatesoft.hg.util.FileIterator;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
37 import org.tmatesoft.hg.util.FileWalker;
142
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 128
diff changeset
38 import org.tmatesoft.hg.util.Path;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
39 import org.tmatesoft.hg.util.PathRewrite;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
40
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 /**
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * DO NOT USE THIS CLASS, INTENDED FOR TESTING PURPOSES.
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 *
442
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
45 * <p>This class is not part of the public API and may change or vanish any moment.
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
46 *
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
47 * <p>This class gives access to repository internals, and holds methods that I'm not confident have to be widely accessible
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 * Debug helper, to access otherwise restricted (package-local) methods
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
50 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
51 * @author TMate Software Ltd.
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 */
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
53 @Experimental(reason="Perhaps, shall split methods with debug purpose from methods that are experimental API")
96
ace7042a5ce6 Internals to HgInternals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
54 public class HgInternals {
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 private final HgRepository repo;
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
96
ace7042a5ce6 Internals to HgInternals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
58 public HgInternals(HgRepository hgRepo) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 59
diff changeset
59 repo = hgRepo;
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
62 public HgDirstate getDirstate() throws HgInvalidControlFileException {
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
63 return repo.loadDirstate(new Path.SimpleSource());
296
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
64 }
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
65
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
66 // tests
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
67 public HgDirstate createDirstate(boolean caseSensitiveFileSystem) throws HgInvalidControlFileException {
296
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
68 PathRewrite canonicalPath = null;
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
69 if (!caseSensitiveFileSystem) {
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
70 canonicalPath = new PathRewrite() {
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
71
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
72 public CharSequence rewrite(CharSequence path) {
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
73 return path.toString().toLowerCase();
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
74 }
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
75 };
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
76 }
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
77 HgDirstate ds = new HgDirstate(repo.getImplHelper(), new Path.SimpleSource(), canonicalPath);
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
78 ds.read();
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 347
diff changeset
79 return ds;
296
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
80 }
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
81
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
82 public Path[] checkKnown(HgDirstate dirstate, Path[] toCheck) {
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
83 Path[] rv = new Path[toCheck.length];
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
84 for (int i = 0; i < toCheck.length; i++) {
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
85 rv[i] = dirstate.known(toCheck[i]);
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
86 }
02f2963c70fa Issue 13: Tests for mixed-cased filenames in case-insensitive FS
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
87 return rv;
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
442
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
89
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
90 public HgSubrepoLocation newSubrepo(Path loc, String src, Kind kind, Nodeid rev) {
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
91 return new HgSubrepoLocation(repo, loc, src, kind, rev);
6865eb742883 Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
92 }
493
ba36f66c32b4 Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
93
ba36f66c32b4 Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
94 public static Internals getImplementationRepo(HgRepository hgRepo) {
ba36f66c32b4 Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
95 return hgRepo.getImplHelper();
ba36f66c32b4 Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
96 }
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97
409
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
98 /**
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
99 * @param source where to read definitions from
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
100 * @param globPathRewrite <code>null</code> to use default, or pass an instance to override defaults
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
101 * @return
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
102 * @throws IOException
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
103 */
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
104 public static HgIgnore newHgIgnore(Reader source, PathRewrite globPathRewrite) throws IOException {
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
105 if (globPathRewrite == null) {
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
106 // shall match that of HgRepository#getIgnore() (Internals#buildNormalizePathRewrite())
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
107 if (Internals.runningOnWindows()) {
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
108 globPathRewrite = new WinToNixPathRewrite();
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
109 } else {
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
110 globPathRewrite = new PathRewrite.Empty();
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
111 }
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
112 }
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
113 HgIgnore hgIgnore = new HgIgnore(globPathRewrite);
269
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
114 BufferedReader br = source instanceof BufferedReader ? (BufferedReader) source : new BufferedReader(source);
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
115 hgIgnore.read(br);
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
116 br.close();
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
117 return hgIgnore;
7af843ecc378 Respect glob pattern with alternatives {a,b}
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 237
diff changeset
118 }
673
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
119
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
120 // XXX just to access package local method. Perhaps, GroupElement shall be redesigned
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
121 // to allow classes from .internal to access its details?
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
122 // or Patch may become public?
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
123 public static Patch patchFromData(GroupElement ge) throws IOException {
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
124 return ge.patch();
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
125 }
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
126
673
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
127 public static File getBundleFile(HgBundle bundle) {
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
128 return bundle.bundleFile;
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
129 }
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
130
545b1d4cc11d Refactor HgBundle.GroupElement (clear experimental mark), resolve few technical debt issues
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
131 // TODO in fact, need a setter for this anyway, shall move to internal.Internals perhaps?
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
132 public String getNextCommitUsername() {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
133 String hgUser = System.getenv("HGUSER");
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
134 if (hgUser != null && hgUser.trim().length() > 0) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
135 return hgUser.trim();
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
136 }
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 300
diff changeset
137 String configValue = repo.getConfiguration().getStringValue("ui", "username", null);
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
138 if (configValue != null) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
139 return configValue;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
140 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
141 String email = System.getenv("EMAIL");
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
142 if (email != null && email.trim().length() > 0) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
143 return email;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
144 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
145 String username = System.getProperty("user.name");
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
146 try {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
147 String hostname = InetAddress.getLocalHost().getHostName();
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
148 return username + '@' + hostname;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
149 } catch (UnknownHostException ex) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
150 return username;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
151 }
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
152 }
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
153
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
154 /*package-local*/ FileIterator createWorkingDirWalker(Path.Matcher workindDirScope) {
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 229
diff changeset
155 File repoRoot = repo.getWorkingDir();
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
156 Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(repoRoot), repo.getToRepoPathHelper()));
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
157 // Impl note: simple source is enough as files in the working dir are all unique
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
158 // even if they might get reused (i.e. after FileIterator#reset() and walking once again),
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
159 // path caching is better to be done in the code which knows that path are being reused
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 493
diff changeset
160 return new FileWalker(repo, repoRoot, pathSrc, workindDirScope);
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
161 }
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
162
368
8107b95f4280 Update Javadoc with 'revision index'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
163 // Convenient check of revision index for validity (not all negative values are wrong as long as we use negative constants)
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
164 public static boolean wrongRevisionIndex(int rev) {
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
165 // TODO Another method to check,throw and expand TIP at once (check[Revision|Revlog]Index()
405
866fc3b597a0 Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
166 return rev < 0 && rev != TIP && rev != WORKING_COPY && rev != BAD_REVISION && rev != NO_REVISION;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
167 }
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
168
347
8da7ade36c57 Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
169 // throws HgInvalidRevisionException or IllegalArgumentException if [start..end] range is not a subrange of [0..lastRevision]
8da7ade36c57 Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
170 public static void checkRevlogRange(int start, int end, int lastRevision) throws HgInvalidRevisionException {
300
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
171 if (start < 0 || start > lastRevision) {
347
8da7ade36c57 Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
172 final String m = String.format("Bad left range boundary %d in [0..%d]", start, lastRevision);
8da7ade36c57 Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
173 throw new HgInvalidRevisionException(m, null, start).setRevisionIndex(start, 0, lastRevision);
300
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
174 }
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
175 if (end < 0 || end > lastRevision) {
347
8da7ade36c57 Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
176 final String m = String.format("Bad right range boundary %d in [0..%d]", end, lastRevision);
8da7ade36c57 Add specific IAE subclass to handle wrong (e.g. outdated after rollback) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 339
diff changeset
177 throw new HgInvalidRevisionException(m, null, end).setRevisionIndex(end, 0, lastRevision);
300
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
178 }
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
179 if (end < start) {
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
180 throw new IllegalArgumentException(String.format("Bad range [%d..%d]", start, end));
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
181 }
650b45d290b1 Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 296
diff changeset
182 }
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 }