Top Description Fields Constructors Methods
org.eclipse.jgit.util

public Class ChangeIdUtil

extends Object
Class Inheritance
Imports
java.util.regex.Pattern, org.eclipse.jgit.lib.Constants, .ObjectId, .ObjectInserter, .PersonIdent

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.

Field Summary

Modifier and TypeField and Description
pack-priv static final String
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static String
public static ObjectId

Returns:

the change id SHA1 string (without the 'I') or null if the message is not complete enough
computeChangeId
(final ObjectId
The id of the tree that would be committed
treeId
,
final ObjectId
parent id of previous commit or null
firstParentId
,
final PersonIdent
the org.eclipse.jgit.lib.PersonIdent for the presumed author and time
author
,
final PersonIdent
the org.eclipse.jgit.lib.PersonIdent for the presumed committer and time
committer
,
final String
The commit message
message
)

Compute a Change-Id.

public static int

Returns:

the index of the ChangeId footer in the message, or -1 if no ChangeId footer available
indexOfChangeId
(String
a message.
message
,
String
the line delimiter, like "\n" or "\r\n", needed to find the footer
delimiter
)

Return the index in the String message where the Change-Id entry in the footer begins.

public static int

Returns:

the index of the first line of the footer paragraph, or lines.length if no footer is available
indexOfFirstFooterLine
(String[]
the commit message split into lines and the line delimiters stripped off
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

public static String

Returns:

a commit message with an inserted Change-Id line
insertId
(String
a message.
message
,
ObjectId
a Change-Id.
changeId
)

Find the right place to insert a Change-Id and return it.

public static String

Returns:

a commit message with an inserted Change-Id line
insertId
(String
a message.
message
,
ObjectId
a Change-Id.
changeId
,
boolean
a boolean.
replaceExisting
)

Find the right place to insert a Change-Id and return it.

private static boolean
private static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHANGE_IDback to summary
pack-priv static final String CHANGE_ID
changeIdPatternback to summary
private static final Pattern changeIdPattern
footerPatternback to summary
private static final Pattern footerPattern
includeInFooterPatternback to summary
private static final Pattern includeInFooterPattern
signedOffByPatternback to summary
private static final Pattern signedOffByPattern
trailingWhitespaceback to summary
private static final Pattern trailingWhitespace

Constructor Detail

ChangeIdUtilback to summary
public ChangeIdUtil()

Method Detail

cleanback to summary
pack-priv static String clean(String msg)
Annotations
@SuppressWarnings:nls
computeChangeIdback to summary
public static ObjectId computeChangeId(final ObjectId treeId, final ObjectId firstParentId, final PersonIdent author, final PersonIdent committer, final String message)

Compute a Change-Id.

Parameters
treeId:ObjectId

The id of the tree that would be committed

firstParentId:ObjectId

parent id of previous commit or null

author:PersonIdent

the org.eclipse.jgit.lib.PersonIdent for the presumed author and time

committer:PersonIdent

the org.eclipse.jgit.lib.PersonIdent for the presumed committer and time

message:String

The commit message

Returns:ObjectId

the change id SHA1 string (without the 'I') or null if the message is not complete enough

indexOfChangeIdback to summary
public static int indexOfChangeId(String message, String delimiter)

Return the index in the String 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.

Parameters
message:String

a message.

delimiter:String

the line delimiter, like "\n" or "\r\n", needed to find the footer

Returns:int

the index of the ChangeId footer in the message, or -1 if no ChangeId footer available

indexOfFirstFooterLineback to summary
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:String[]

the commit message split into lines and the line delimiters stripped off

Returns:int

the index of the first line of the footer paragraph, or lines.length if no footer is available

insertIdback to summary
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:String

a message.

changeId:ObjectId

a Change-Id.

Returns:String

a commit message with an inserted Change-Id line

insertIdback to summary
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:String

a message.

changeId:ObjectId

a Change-Id.

replaceExisting:boolean

a boolean.

Returns:String

a commit message with an inserted Change-Id line

isEmptyLineback to summary
private static boolean isEmptyLine(String line)
trimRightback to summary
private static String trimRight(String s)