Mercurial > jhg
annotate src/org/tmatesoft/hg/core/HgStatus.java @ 657:6334b0267103
ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 20:27:45 +0200 |
parents | 6526d8adbc0f |
children |
rev | line source |
---|---|
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
2 * Copyright (c) 2011-2013 TMate Software Ltd |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.core; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
247
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
19 import java.io.File; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
20 import java.util.Date; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
21 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
22 import org.tmatesoft.hg.internal.ChangelogHelper; |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
143
diff
changeset
|
23 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgRuntimeException; |
133
4a948ec83980
core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
131
diff
changeset
|
25 import org.tmatesoft.hg.util.Path; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
26 |
131
aa1629f36482
Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
27 /** |
aa1629f36482
Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
28 * Repository file status and extra handy information. |
aa1629f36482
Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
29 * |
aa1629f36482
Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
30 * @author Artem Tikhomirov |
aa1629f36482
Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
31 * @author TMate Software Ltd. |
aa1629f36482
Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
32 */ |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 public class HgStatus { |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 public enum Kind { |
143
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
140
diff
changeset
|
36 Modified, Added, Removed, Missing, Unknown, Clean, Ignored |
b9700740553a
Command line tools parse and respect most of command-line arguments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
140
diff
changeset
|
37 // I'd refrain from changing order of these constants, just in case someone (erroneously, of course ;), uses .ordinal() |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 }; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 private final HgStatus.Kind kind; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 private final Path path; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 private final Path origin; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
43 private final ChangelogHelper logHelper; |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
45 HgStatus(HgStatus.Kind kind, Path path, ChangelogHelper changelogHelper) { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
46 this(kind, path, null, changelogHelper); |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
49 HgStatus(HgStatus.Kind kind, Path path, Path copyOrigin, ChangelogHelper changelogHelper) { |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 this.kind = kind; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 this.path = path; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 origin = copyOrigin; |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
53 logHelper = changelogHelper; |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 public HgStatus.Kind getKind() { |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 return kind; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 } |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 public Path getPath() { |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 return path; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 public Path getOriginalPath() { |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 return origin; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 public boolean isCopy() { |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 return origin != null; |
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 } |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
71 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
72 /** |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
73 * @return <code>null</code> if author for the change can't be deduced (e.g. for clean files it's senseless) |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
74 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
75 */ |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
76 public String getModificationAuthor() throws HgRuntimeException { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
143
diff
changeset
|
77 RawChangeset cset = logHelper.findLatestChangeWith(path); |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
78 if (cset == null) { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
79 if (kind == Kind.Modified || kind == Kind.Added || kind == Kind.Removed /*&& RightBoundary is TIP*/) { |
140
1c1891ad1c73
Slight optimization
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
133
diff
changeset
|
80 // perhaps, also for Kind.Missing? |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
81 return logHelper.getNextCommitUsername(); |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
82 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
83 } else { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
84 return cset.user(); |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
85 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
86 return null; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
87 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
88 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
89 /** |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
90 * @return date when the file was last modified, never <code>null</code>. Either date of changeset the file was modified at |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
91 * or timestamp of local file, if present |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
92 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
93 */ |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
94 public Date getModificationDate() throws HgRuntimeException { |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
143
diff
changeset
|
95 RawChangeset cset = logHelper.findLatestChangeWith(path); |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
96 if (cset == null) { |
247
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
97 File localFile = new File(logHelper.getRepo().getWorkingDir(), path.toString()); |
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
98 if (localFile.canRead()) { |
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
99 return new Date(localFile.lastModified()); |
f052f40839ec
Issue 9: NPE in getModificationDate for files with status 'Unknown'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
154
diff
changeset
|
100 } |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
101 // TODO post-1.1 find out what to do in this case, perhaps, throw an exception? |
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
102 // perhaps check dirstate and for timestamp |
418
528b6780a8bd
A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
103 return new Date(); // what's correct? |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
104 } else { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
105 return cset.date(); |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
106 } |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
127
diff
changeset
|
107 } |
127
2e395db595e2
Moved HgStatus to toplevel
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 } |