Skip to content

Commit 31a8348

Browse files
authored
Merge pull request #1700 from vladak/git_datefix_redux
determineCurrentVersion() in git repository needs to use iso-strict too
2 parents f3a9554 + 27782bc commit 31a8348

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/org/opensolaris/opengrok/history/GitRepository.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public class GitRepository extends Repository {
7878
private static final String ABBREV_LOG = "--abbrev=" + CSET_LEN;
7979
private static final String ABBREV_BLAME = "--abbrev=" + (CSET_LEN - 1);
8080

81+
/**
82+
* All git commands that emit date that needs to be parsed by
83+
* {@code getDateFormat()} should use this option.
84+
*/
85+
private static final String GIT_DATE_OPT = "--date=iso8601-strict";
86+
8187
/**
8288
* Pattern used to extract author/revision from git blame.
8389
*/
@@ -123,7 +129,7 @@ Executor getHistoryLogExecutor(final File file, String sinceRevision)
123129
cmd.add(ABBREV_LOG);
124130
cmd.add("--name-only");
125131
cmd.add("--pretty=fuller");
126-
cmd.add("--date=iso8601-strict");
132+
cmd.add(GIT_DATE_OPT);
127133

128134
if (file.isFile() && RuntimeEnvironment.getInstance().isHandleHistoryOfRenamedFiles()) {
129135
cmd.add("--follow");
@@ -704,20 +710,25 @@ String determineBranch() throws IOException {
704710
String determineCurrentVersion() throws IOException {
705711
File directory = new File(directoryName);
706712
List<String> cmd = new ArrayList<>();
713+
// The delimiter must not be contained in the date format emitted by
714+
// {@code GIT_DATE_OPT}.
715+
String delim = "#";
716+
707717
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
718+
708719
cmd.add(RepoCommand);
709720
cmd.add("log");
710721
cmd.add("-1");
711-
cmd.add("--pretty=%cd: %h %an %s");
712-
cmd.add("--date=rfc");
722+
cmd.add("--pretty=%cd" + delim + "%h %an %s");
723+
cmd.add(GIT_DATE_OPT);
713724

714725
Executor executor = new Executor(cmd, directory);
715726
if (executor.exec(false) != 0) {
716727
throw new IOException(executor.getErrorString());
717728
}
718729

719730
String output = executor.getOutputString().trim();
720-
int indexOf = StringUtils.nthIndexOf(output, ":", 3);
731+
int indexOf = StringUtils.nthIndexOf(output, delim, 1);
721732
if (indexOf < 0) {
722733
throw new IOException(
723734
String.format("Couldn't extract date from \"%s\".",

test/org/opensolaris/opengrok/history/GitRepositoryTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public void tearDown() {
7777
instance = null;
7878
}
7979

80+
@Test
81+
public void testDetermineCurrentVersion() throws Exception {
82+
File root = new File(repository.getSourceRoot(), "git");
83+
GitRepository gitrepo
84+
= (GitRepository) RepositoryFactory.getRepository(root);
85+
String ver = gitrepo.determineCurrentVersion();
86+
Assert.assertNotNull(ver);
87+
}
88+
8089
/**
8190
* Test of parseAnnotation method, of class GitRepository.
8291
* @throws java.lang.Exception

0 commit comments

Comments
 (0)