33
33
import java .util .HashMap ;
34
34
import java .util .List ;
35
35
import java .util .TreeSet ;
36
+ import java .util .function .Consumer ;
36
37
import java .util .function .Supplier ;
37
38
import java .util .logging .Level ;
38
39
import java .util .logging .Logger ;
50
51
* Access to a Mercurial repository.
51
52
*
52
53
*/
53
- public class MercurialRepository extends Repository {
54
+ public class MercurialRepository extends RepositoryWithPerPartesHistory {
54
55
55
56
private static final Logger LOGGER = LoggerFactory .getLogger (MercurialRepository .class );
56
57
@@ -81,6 +82,7 @@ public class MercurialRepository extends Repository {
81
82
static final String END_OF_ENTRY
82
83
= "mercurial_history_end_of_entry" ;
83
84
85
+ private static final String TEMPLATE_REVS = "{rev}\\ n" ;
84
86
private static final String TEMPLATE_STUB
85
87
= CHANGESET + "{rev}:{node|short}\\ n"
86
88
+ USER + "{author}\\ n" + DATE + "{date|isodate}\\ n"
@@ -151,12 +153,14 @@ String determineBranch(CommandTimeoutType cmdType) throws IOException {
151
153
* @param sinceRevision the oldest changeset to return from the executor, or
152
154
* {@code null} if all changesets should be returned.
153
155
* For files this does not apply and full history is returned.
156
+ * @param tillRevision end revision
157
+ * @param revisionsOnly get only revision numbers
154
158
* @return An Executor ready to be started
155
159
*/
156
- Executor getHistoryLogExecutor (File file , String sinceRevision )
160
+ Executor getHistoryLogExecutor (File file , String sinceRevision , String tillRevision , boolean revisionsOnly )
157
161
throws HistoryException , IOException {
162
+
158
163
String filename = getRepoRelativePath (file );
159
- RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
160
164
161
165
List <String > cmd = new ArrayList <>();
162
166
ensureCommand (CMD_PROPERTY_KEY , CMD_FALLBACK );
@@ -166,15 +170,14 @@ Executor getHistoryLogExecutor(File file, String sinceRevision)
166
170
if (file .isDirectory ()) {
167
171
// If this is non-default branch we would like to get the changesets
168
172
// on that branch and also follow any changesets from the parent branch.
173
+ // TODO tillRevision
169
174
if (sinceRevision != null ) {
170
175
cmd .add ("-r" );
171
176
String [] parts = sinceRevision .split (":" );
172
177
if (parts .length == 2 ) {
173
178
cmd .add ("reverse(" + parts [0 ] + "::'" + getBranch () + "')" );
174
179
} else {
175
- throw new HistoryException (
176
- "Don't know how to parse changeset identifier: "
177
- + sinceRevision );
180
+ throw new HistoryException ("Don't know how to parse changeset identifier: " + sinceRevision );
178
181
}
179
182
} else {
180
183
cmd .add ("-r" );
@@ -197,10 +200,14 @@ Executor getHistoryLogExecutor(File file, String sinceRevision)
197
200
}
198
201
199
202
cmd .add ("--template" );
200
- if (file . isDirectory () ) {
201
- cmd .add (this . isHandleRenamedFiles () ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE );
203
+ if (revisionsOnly ) {
204
+ cmd .add (TEMPLATE_REVS );
202
205
} else {
203
- cmd .add (FILE_TEMPLATE );
206
+ if (file .isDirectory ()) {
207
+ cmd .add (this .isHandleRenamedFiles () ? DIR_TEMPLATE_RENAMED : DIR_TEMPLATE );
208
+ } else {
209
+ cmd .add (FILE_TEMPLATE );
210
+ }
204
211
}
205
212
206
213
if (!filename .isEmpty ()) {
@@ -259,7 +266,7 @@ private HistoryRevResult getHistoryRev(
259
266
* @param fullpath file path
260
267
* @param full_rev_to_find revision number (in the form of
261
268
* {rev}:{node|short})
262
- * @returns original filename
269
+ * @return original filename
263
270
*/
264
271
private String findOriginalName (String fullpath , String full_rev_to_find )
265
272
throws IOException {
@@ -511,9 +518,17 @@ History getHistory(File file) throws HistoryException {
511
518
return getHistory (file , null );
512
519
}
513
520
521
+ public void accept (String sinceRevision , Consumer <String > visitor ) throws HistoryException {
522
+ new MercurialHistoryParserRevisionsOnly (this , visitor ).
523
+ parse (new File (getDirectoryName ()), sinceRevision );
524
+ }
525
+
526
+ History getHistory (File file , String sinceRevision ) throws HistoryException {
527
+ return getHistory (file , sinceRevision , null );
528
+ }
529
+
514
530
@ Override
515
- History getHistory (File file , String sinceRevision )
516
- throws HistoryException {
531
+ History getHistory (File file , String sinceRevision , String tillRevision ) throws HistoryException {
517
532
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
518
533
// Note that the filtering of revisions based on sinceRevision is done
519
534
// in the history log executor by passing appropriate options to
@@ -522,8 +537,7 @@ History getHistory(File file, String sinceRevision)
522
537
// for file, the file is renamed and its complete history is fetched
523
538
// so no sinceRevision filter is needed.
524
539
// See findOriginalName() code for more details.
525
- History result = new MercurialHistoryParser (this ).parse (file ,
526
- sinceRevision );
540
+ History result = new MercurialHistoryParser (this ).parse (file , sinceRevision , tillRevision );
527
541
528
542
// Assign tags to changesets they represent.
529
543
// We don't need to check if this repository supports tags,
0 commit comments