Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/CommitAnalysisInfrastructur…
Browse files Browse the repository at this point in the history
…e/SvnCommitExtractor (fork update)
  • Loading branch information
mspark committed Mar 19, 2019
2 parents 56bfe50 + c3a24ef commit faa5da4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ Default value: 1
Related parameters: none
extraction.svn_extractor.max_attempts = <Number>
```

*Single commit extraction:*

The ComAnI infrastructure offers the single commit extraction as one of three different extraction variants (read the [ComAnI Guide](https://github.com/CommitAnalysisInfrastructure/ComAnI/blob/master/guide/ComAnI_Guide.pdf) for more information). When using the SvnCommitExtractor, the required format of the string representing the single commit must be as illustrated by the following example:

```
r3
Index: readme.txt
===================================================================
--- readme.txt (nonexistent)
+++ readme.txt (revision 2)
@@ -0,0 +1,5 @@
+This repository hosts some files to check whether the GitCommitExtractor works as expected.
+These files neither represent a particular software nor do they have any relations.
+These files are only used for testing correct extraction of commits.
+
+This line was introduced on a new branch.
!q!
```

The first line in the example above is optional and defines the commit (revision) number of the commit. It must be defined exactly as illustrated: `r<NUMBER>`. If this line is not available, the commit extractor will use the default id `<no_id>` as commit id.

The following lines represent the content of the actual commit as provided by the SVN command `svn diff –x –U100000 –c –r<NUMBER>`, where `<NUMBER>` identifies the respective revision. Note that there is no further information, like the commit message. This content starts directly with the first changed file `Index: ...`. The commit extractor expects this either as the first line (if the optional revision above is not available) or as the second line.

The last line terminates the commit string as required by the infrastructure. This line must only contain `!q!`. All lines after this termination-string will be ignored.

## License
This project is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,27 @@ public boolean extract(File repository, List<String> commitList) {
public boolean extract(String commit) {
logger.log(ID, "Extraction (parsing) of single commit", null, MessageType.DEBUG);
boolean extractionSuccessful = false;
Commit commitObject = createCommit("<no_id>", "<no_date>", new String[0], commit);
// Get the commit id from the first line of the given commit string (if available)
String commitId = "<no_id>";
if (commit.startsWith("r")) {
int indexOfFirstLineBreak = commit.indexOf("\n");
if (indexOfFirstLineBreak > -1) {
try {
int revisionNumber = Integer.parseInt(commit.substring(1, indexOfFirstLineBreak));
// If this line is reached, the substring is a number, which defines the revision
commitId = "r" + revisionNumber;
} catch (NumberFormatException e) {
// First line does not contain "r<NUMBER>" representing the revision number of the given commit
logger.log(ID, "Identifying the commit id failed", "The first line of the given string does not "
+ "exclusively contain \"r<REVISION>\"; using \"<no_id>\" as commit id",
MessageType.WARNING);
}
}
// Exclude the first line indicating the revision number (or any non "Index: ..."-string)
commit = commit.substring(indexOfFirstLineBreak + 1);
}
// Create the commit object
Commit commitObject = createCommit(commitId, "<no_date>", new String[0], commit);
if (commitObject != null) {
while (!commitQueue.addCommit(commitObject)) {
logger.log(ID, "Waiting to add commit to queue", null, MessageType.DEBUG);
Expand Down

0 comments on commit faa5da4

Please sign in to comment.