[SCM-914] Introduce properly typed last modified date (#193) · apache/maven-scm@a297237 (original) (raw)
`@@ -18,12 +18,18 @@
`
18
18
` */
`
19
19
`package org.apache.maven.scm.provider.git.gitexe.command.info;
`
20
20
``
``
21
`+
import java.io.File;
`
``
22
`+
import java.util.Collections;
`
``
23
`+
import java.util.LinkedList;
`
``
24
`+
import java.util.List;
`
``
25
+
21
26
`import org.apache.maven.scm.CommandParameter;
`
22
27
`import org.apache.maven.scm.CommandParameters;
`
23
28
`import org.apache.maven.scm.ScmException;
`
24
29
`import org.apache.maven.scm.ScmFileSet;
`
25
30
`import org.apache.maven.scm.ScmResult;
`
26
31
`import org.apache.maven.scm.command.AbstractCommand;
`
``
32
`+
import org.apache.maven.scm.command.info.InfoItem;
`
27
33
`import org.apache.maven.scm.command.info.InfoScmResult;
`
28
34
`import org.apache.maven.scm.provider.ScmProviderRepository;
`
29
35
`import org.apache.maven.scm.provider.git.command.GitCommand;
`
`@@ -32,6 +38,7 @@
`
32
38
`import org.codehaus.plexus.util.cli.Commandline;
`
33
39
``
34
40
`/**
`
``
41
`+
- Uses {@code git log} command to retrieve info about the most recent commits related to specific files.
`
35
42
` * @author Olivier Lamy
`
36
43
` * @since 1.5
`
37
44
` */
`
`@@ -43,31 +50,39 @@ public class GitInfoCommand extends AbstractCommand implements GitCommand {
`
43
50
`protected ScmResult executeCommand(
`
44
51
`ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
`
45
52
``
46
``
`-
GitInfoConsumer consumer = new GitInfoConsumer(fileSet);
`
47
``
`-
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
`
48
``
-
49
``
`-
Commandline cli = createCommandLine(repository, fileSet, parameters);
`
``
53
`+
Commandline baseCli = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "log");
`
``
54
`+
baseCli.createArg().setValue("-1"); // only most recent commit matters
`
``
55
`+
baseCli.createArg().setValue("--no-merges"); // skip merge commits
`
``
56
`+
baseCli.addArg(GitInfoConsumer.getFormatArgument());
`
50
57
``
51
``
`-
int exitCode = GitCommandLineUtils.execute(cli, consumer, stderr);
`
52
``
`-
if (exitCode != 0) {
`
53
``
`-
return new InfoScmResult(cli.toString(), "The git rev-parse command failed.", stderr.getOutput(), false);
`
``
58
`+
List infoItems = new LinkedList<>();
`
``
59
`+
if (fileSet.getFileList().isEmpty()) {
`
``
60
`+
infoItems.add(executeInfoCommand(baseCli, parameters, fileSet.getBasedir()));
`
``
61
`+
} else {
`
``
62
`+
// iterate over files
`
``
63
`+
for (File scmFile : fileSet.getFileList()) {
`
``
64
`+
baseCli = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "log");
`
``
65
`+
baseCli.createArg().setValue("-1"); // only most recent commit matters
`
``
66
`+
baseCli.createArg().setValue("--no-merges"); // skip merge commits
`
``
67
`+
baseCli.addArg(GitInfoConsumer.getFormatArgument());
`
``
68
`+
// Insert a separator to make sure that files aren't interpreted as part of the version spec
`
``
69
`+
baseCli.createArg().setValue("--");
`
``
70
`+
GitCommandLineUtils.addTarget(baseCli, Collections.singletonList(scmFile));
`
``
71
`+
infoItems.add(executeInfoCommand(baseCli, parameters, scmFile));
`
``
72
`+
}
`
54
73
` }
`
55
``
`-
return new InfoScmResult(cli.toString(), consumer.getInfoItems());
`
``
74
`+
return new InfoScmResult(baseCli.toString(), infoItems);
`
56
75
` }
`
57
76
``
58
``
`-
public static Commandline createCommandLine(
`
59
``
`-
ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
`
60
``
`-
Commandline cli = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "rev-parse");
`
61
``
`-
cli.createArg().setValue("--verify");
`
62
``
`-
final int revLength = getRevisionLength(parameters);
`
63
``
`-
if (revLength > NO_REVISION_LENGTH) // set the --short key only if revision length parameter is passed and
`
64
``
`-
// different from -1
`
65
``
`-
{
`
66
``
`-
cli.createArg().setValue("--short=" + revLength);
`
``
77
`+
protected InfoItem executeInfoCommand(Commandline cli, CommandParameters parameters, File scmFile)
`
``
78
`+
throws ScmException {
`
``
79
`+
GitInfoConsumer consumer = new GitInfoConsumer(scmFile.toPath(), getRevisionLength(parameters));
`
``
80
`+
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
`
``
81
`+
int exitCode = GitCommandLineUtils.execute(cli, consumer, stderr);
`
``
82
`+
if (exitCode != 0) {
`
``
83
`+
throw new ScmException("The git log command failed: " + cli.toString() + " returned " + stderr.getOutput());
`
67
84
` }
`
68
``
`-
cli.createArg().setValue("HEAD");
`
69
``
-
70
``
`-
return cli;
`
``
85
`+
return consumer.getInfoItem();
`
71
86
` }
`
72
87
``
73
88
`/**
`