|
39 | 39 | import java.nio.charset.StandardCharsets;
|
40 | 40 | import java.nio.file.Paths;
|
41 | 41 | import java.security.InvalidParameterException;
|
| 42 | +import java.text.ParseException; |
42 | 43 | import java.util.ArrayList;
|
43 | 44 | import java.util.Arrays;
|
44 | 45 | import java.util.Collections;
|
@@ -1346,31 +1347,39 @@ private String getLastRevFromHistory() {
|
1346 | 1347 |
|
1347 | 1348 | /**
|
1348 | 1349 | * Retrieve last revision from the document matching the resource file (if any).
|
1349 |
| - * @return last revision or {@code null} if the document cannot be found or is out of sync |
1350 |
| - * w.r.t. last modified time of the file. |
| 1350 | + * @return last revision or {@code null} if the document cannot be found, is out of sync |
| 1351 | + * w.r.t. last modified time of the file or the last commit ID is not stored in the document. |
1351 | 1352 | */
|
1352 | 1353 | @Nullable
|
1353 | 1354 | private String getLastRevFromIndex() {
|
1354 | 1355 | Document doc = null;
|
1355 | 1356 | try {
|
1356 | 1357 | doc = IndexDatabase.getDocument(getResourceFile());
|
1357 |
| - if (doc != null) { |
1358 |
| - Date docDate = DateTools.stringToDate(doc.get(QueryBuilder.DATE)); |
| 1358 | + } catch (Exception e) { |
| 1359 | + LOGGER.log(Level.WARNING, String.format("cannot get document for %s", path), e); |
| 1360 | + } |
| 1361 | + |
| 1362 | + String lastRev = null; |
| 1363 | + if (doc != null) { |
| 1364 | + // There is no point of checking the date if the LASTREV field is not present. |
| 1365 | + lastRev = doc.get(QueryBuilder.LASTREV); |
| 1366 | + if (lastRev != null) { |
| 1367 | + Date docDate; |
| 1368 | + try { |
| 1369 | + docDate = DateTools.stringToDate(doc.get(QueryBuilder.DATE)); |
| 1370 | + } catch (ParseException e) { |
| 1371 | + LOGGER.log(Level.WARNING, String.format("cannot get date from the document %s", doc), e); |
| 1372 | + return null; |
| 1373 | + } |
1359 | 1374 | Date fileDate = new Date(getResourceFile().lastModified());
|
1360 | 1375 | if (docDate.compareTo(fileDate) < 0) {
|
1361 | 1376 | LOGGER.log(Level.FINER, "document for '{0}' is out of sync", getResourceFile());
|
1362 | 1377 | return null;
|
1363 | 1378 | }
|
1364 | 1379 | }
|
1365 |
| - } catch (Exception e) { |
1366 |
| - LOGGER.log(Level.WARNING, String.format("cannot get document for %s", path), e); |
1367 | 1380 | }
|
1368 | 1381 |
|
1369 |
| - if (doc != null) { |
1370 |
| - return doc.get(QueryBuilder.LASTREV); |
1371 |
| - } |
1372 |
| - |
1373 |
| - return null; |
| 1382 | + return lastRev; |
1374 | 1383 | }
|
1375 | 1384 |
|
1376 | 1385 | /**
|
|
0 commit comments