Skip to content

Commit

Permalink
[FIXED JENKINS-14350] Adds branch information to the change set log
Browse files Browse the repository at this point in the history
In the ChangeSetList screen (${BUILD_URL}/changes), if a branch was
discovered in the SCM changelog, display the branch name in the changeset
detail.
  • Loading branch information
Joe Hansche committed Jul 8, 2012
1 parent 3b1ad20 commit 305eb61
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/main/java/hudson/plugins/git/GitChangeSet.java
Expand Up @@ -32,6 +32,8 @@ public class GitChangeSet extends ChangeLogSet.Entry {
private static final String PREFIX_AUTHOR = "author ";
private static final String PREFIX_COMMITTER = "committer ";
private static final String IDENTITY = "(.*)<(.*)> (.*) (.*)";
private static final String PREFIX_BRANCH = "Changes in branch ";
private static final String BRANCH_PATTERN = "([-_a-zA-Z0-9/]*),";


private static final Pattern FILE_LOG_ENTRY = Pattern.compile("^:[0-9]{6} [0-9]{6} ([0-9a-f]{40}) ([0-9a-f]{40}) ([ACDMRTUX])(?>[0-9]+)?\t(.*)$");
Expand All @@ -40,8 +42,11 @@ public class GitChangeSet extends ChangeLogSet.Entry {
private static final Pattern COMMITTER_ENTRY = Pattern.compile("^"
+ PREFIX_COMMITTER + IDENTITY + "$");
private static final Pattern RENAME_SPLIT = Pattern.compile("^(.*?)\t(.*)$");
private static final Pattern BRANCH_ENTRY = Pattern.compile("^"
+ PREFIX_BRANCH + BRANCH_PATTERN + " .*$");

private static final String NULL_HASH = "0000000000000000000000000000000000000000";
private String branch;
private String committer;
private String committerEmail;
private String committerTime;
Expand Down Expand Up @@ -82,6 +87,12 @@ private void parseCommit(List<String> lines) {
} else if (line.startsWith("tree ")) {
} else if (line.startsWith("parent ")) {
this.parentCommit = line.split(" ")[1];
} else if (line.startsWith(PREFIX_BRANCH)) {
Matcher branchMatcher = BRANCH_ENTRY.matcher(line);
if (branchMatcher.matches()
&& branchMatcher.groupCount() >= 1) {
this.branch = branchMatcher.group(1).trim();
}
} else if (line.startsWith(PREFIX_COMMITTER)) {
Matcher committerMatcher = COMMITTER_ENTRY.matcher(line);
if (committerMatcher.matches()
Expand Down Expand Up @@ -312,6 +323,10 @@ public String getCommentAnnotated() {
return markup.toString(false);
}

public String getBranch() {
return this.branch;
}

@ExportedBean(defaultVisibility=999)
public static class Path implements AffectedFile {

Expand Down
Expand Up @@ -27,6 +27,9 @@
</j:if>
by <a href="${rootURL}/${cs.author.url}/">${cs.author}</a>
</b>
<j:if test="${cs.branch!=null}">
<j:whitespace trim="false"> in ${cs.branch}</j:whitespace>
</j:if>
<pre>${cs.commentAnnotated}</pre>
</div>
</td>
Expand All @@ -46,4 +49,4 @@
</j:forEach>
</j:forEach>
</table>
</j:jelly>
</j:jelly>

0 comments on commit 305eb61

Please sign in to comment.