public class ChangeIdUtil
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
(package private) static java.lang.String |
CHANGE_ID |
private static java.util.regex.Pattern |
changeIdPattern |
private static java.util.regex.Pattern |
footerPattern |
private static java.util.regex.Pattern |
includeInFooterPattern |
private static java.util.regex.Pattern |
issuePattern |
private static java.util.regex.Pattern |
trailingWhitespace |
Constructor and Description |
---|
ChangeIdUtil() |
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.String |
clean(java.lang.String msg) |
static ObjectId |
computeChangeId(ObjectId treeId,
ObjectId firstParentId,
PersonIdent author,
PersonIdent committer,
java.lang.String message)
Compute a Change-Id.
|
static int |
indexOfChangeId(java.lang.String message,
java.lang.String delimiter)
Return the index in the String
message where the Change-Id entry
in the footer begins. |
static int |
indexOfFirstFooterLine(java.lang.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
|
static java.lang.String |
insertId(java.lang.String message,
ObjectId changeId)
Find the right place to insert a Change-Id and return it.
|
static java.lang.String |
insertId(java.lang.String message,
ObjectId changeId,
boolean replaceExisting)
Find the right place to insert a Change-Id and return it.
|
private static boolean |
isEmptyLine(java.lang.String line) |
private static java.lang.String |
trimRight(java.lang.String s) |
static final java.lang.String CHANGE_ID
private static final java.util.regex.Pattern issuePattern
private static final java.util.regex.Pattern footerPattern
private static final java.util.regex.Pattern changeIdPattern
private static final java.util.regex.Pattern includeInFooterPattern
private static final java.util.regex.Pattern trailingWhitespace
static java.lang.String clean(java.lang.String msg)
public static ObjectId computeChangeId(ObjectId treeId, ObjectId firstParentId, PersonIdent author, PersonIdent committer, java.lang.String message)
treeId
- The id of the tree that would be committedfirstParentId
- parent id of previous commit or nullauthor
- the PersonIdent
for the presumed
author and timecommitter
- the PersonIdent
for the presumed
committer and timemessage
- The commit messagepublic static java.lang.String insertId(java.lang.String message, ObjectId changeId)
The Change-Id is inserted before the first footer line but after a Bug line.
message
- a message.changeId
- a Change-Id.public static java.lang.String insertId(java.lang.String message, ObjectId changeId, boolean replaceExisting)
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
.
message
- a message.changeId
- a Change-Id.replaceExisting
- a boolean.public static int indexOfChangeId(java.lang.String message, java.lang.String delimiter)
message
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 matching footerPattern
.message
- a message.delimiter
- the line delimiter, like "\n" or "\r\n", needed to find the
footerprivate static boolean isEmptyLine(java.lang.String line)
private static java.lang.String trimRight(java.lang.String s)
public static int indexOfFirstFooterLine(java.lang.String[] lines)
lines
- the commit message split into lines and the line delimiters
stripped off