Package org.eclipse.jgit.util
Class ChangeIdUtil
- java.lang.Object
-
- org.eclipse.jgit.util.ChangeIdUtil
-
public class ChangeIdUtil extends Object
Utilities for creating and working with Change-Id's, like the one used by Gerrit Code Review.A Change-Id is a SHA-1 computed from the content of a commit, in a similar fashion to how the commit id is computed. Unlike the commit id a Change-Id is retained in the commit and subsequent revised commits in the footer of the commit text.
-
-
Constructor Summary
Constructors Constructor Description ChangeIdUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectId
computeChangeId(ObjectId treeId, ObjectId firstParentId, PersonIdent author, PersonIdent committer, String message)
Compute a Change-Id.static int
indexOfChangeId(String message, String delimiter)
Return the index in the Stringmessage
where the Change-Id entry in the footer begins.static int
indexOfFirstFooterLine(String[] lines)
Find the index of the first line of the footer paragraph in an array of the lines, or lines.length if no footer is availablestatic String
insertId(String message, ObjectId changeId)
Find the right place to insert a Change-Id and return it.static String
insertId(String message, ObjectId changeId, boolean replaceExisting)
Find the right place to insert a Change-Id and return it.
-
-
-
Method Detail
-
computeChangeId
public static ObjectId computeChangeId(ObjectId treeId, ObjectId firstParentId, PersonIdent author, PersonIdent committer, String message)
Compute a Change-Id.- Parameters:
treeId
- The id of the tree that would be committedfirstParentId
- parent id of previous commit or nullauthor
- thePersonIdent
for the presumed author and timecommitter
- thePersonIdent
for the presumed committer and timemessage
- The commit message- Returns:
- the change id SHA1 string (without the 'I') or null if the message is not complete enough
-
insertId
public static String insertId(String message, ObjectId changeId)
Find the right place to insert a Change-Id and return it.The Change-Id is inserted before the first footer line but after a Bug line.
- Parameters:
message
- a message.changeId
- a Change-Id.- Returns:
- a commit message with an inserted Change-Id line
-
insertId
public static String insertId(String message, ObjectId changeId, boolean replaceExisting)
Find the right place to insert a Change-Id and return it.If no Change-Id is found the Change-Id is inserted before the first footer line but after a Bug line. If Change-Id is found and replaceExisting is set to false, the message is unchanged. If Change-Id is found and replaceExisting is set to true, the Change-Id is replaced with
changeId
.- Parameters:
message
- a message.changeId
- a Change-Id.replaceExisting
- a boolean.- Returns:
- a commit message with an inserted Change-Id line
-
indexOfChangeId
public static int indexOfChangeId(String message, String delimiter)
Return the index in the Stringmessage
where the Change-Id entry in the footer begins. If there are more than one entries matching the pattern, return the index of the last one in the last section. Because of Bug: 400818 we release the constraint here that a footer must contain only lines matchingfooterPattern
.- Parameters:
message
- a message.delimiter
- the line delimiter, like "\n" or "\r\n", needed to find the footer- Returns:
- the index of the ChangeId footer in the message, or -1 if no ChangeId footer available
-
indexOfFirstFooterLine
public static int indexOfFirstFooterLine(String[] lines)
Find the index of the first line of the footer paragraph in an array of the lines, or lines.length if no footer is available- Parameters:
lines
- the commit message split into lines and the line delimiters stripped off- Returns:
- the index of the first line of the footer paragraph, or lines.length if no footer is available
-
-