Merge "Don't allow null name or e-mail in PersonIdent"
This commit is contained in:
commit
cd61e85fa1
|
@ -73,4 +73,14 @@ public void test002_NewIdent() {
|
||||||
assertEquals("A U Thor <author@example.com> 1142878501 +0230",
|
assertEquals("A U Thor <author@example.com> 1142878501 +0230",
|
||||||
p.toExternalString());
|
p.toExternalString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void nullForNameShouldThrowIllegalArgumentException() {
|
||||||
|
new PersonIdent(null, "author@example.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void nullForEmailShouldThrowIllegalArgumentException() {
|
||||||
|
new PersonIdent("A U Thor", null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -548,9 +548,8 @@ public CommitCommand setCommitter(PersonIdent committer) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the committer for this {@code commit}. If no committer is explicitly
|
* Sets the committer for this {@code commit}. If no committer is explicitly
|
||||||
* specified because this method is never called or called with {@code null}
|
* specified because this method is never called then the committer will be
|
||||||
* value then the committer will be deduced from config info in repository,
|
* deduced from config info in repository, with current time.
|
||||||
* with current time.
|
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* the name of the committer used for the {@code commit}
|
* the name of the committer used for the {@code commit}
|
||||||
|
@ -591,9 +590,8 @@ public CommitCommand setAuthor(PersonIdent author) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the author for this {@code commit}. If no author is explicitly
|
* Sets the author for this {@code commit}. If no author is explicitly
|
||||||
* specified because this method is never called or called with {@code null}
|
* specified because this method is never called then the author will be set
|
||||||
* value then the author will be set to the committer or to the original
|
* to the committer or to the original author when amending.
|
||||||
* author when amending.
|
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* the name of the author used for the {@code commit}
|
* the name of the author used for the {@code commit}
|
||||||
|
|
|
@ -78,11 +78,7 @@ public class PersonIdent implements Serializable {
|
||||||
* @param repo
|
* @param repo
|
||||||
*/
|
*/
|
||||||
public PersonIdent(final Repository repo) {
|
public PersonIdent(final Repository repo) {
|
||||||
final UserConfig config = repo.getConfig().get(UserConfig.KEY);
|
this(repo.getConfig().get(UserConfig.KEY));
|
||||||
name = config.getCommitterName();
|
|
||||||
emailAddress = config.getCommitterEmail();
|
|
||||||
when = SystemReader.getInstance().getCurrentTime();
|
|
||||||
tzOffset = SystemReader.getInstance().getTimezone(when);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,10 +98,7 @@ public PersonIdent(final PersonIdent pi) {
|
||||||
* @param aEmailAddress
|
* @param aEmailAddress
|
||||||
*/
|
*/
|
||||||
public PersonIdent(final String aName, final String aEmailAddress) {
|
public PersonIdent(final String aName, final String aEmailAddress) {
|
||||||
name = aName;
|
this(aName, aEmailAddress, SystemReader.getInstance().getCurrentTime());
|
||||||
emailAddress = aEmailAddress;
|
|
||||||
when = SystemReader.getInstance().getCurrentTime();
|
|
||||||
tzOffset = SystemReader.getInstance().getTimezone(when);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,10 +124,7 @@ public PersonIdent(final PersonIdent pi, final Date when, final TimeZone tz) {
|
||||||
* local time
|
* local time
|
||||||
*/
|
*/
|
||||||
public PersonIdent(final PersonIdent pi, final Date aWhen) {
|
public PersonIdent(final PersonIdent pi, final Date aWhen) {
|
||||||
name = pi.getName();
|
this(pi.getName(), pi.getEmailAddress(), aWhen.getTime(), pi.tzOffset);
|
||||||
emailAddress = pi.getEmailAddress();
|
|
||||||
when = aWhen.getTime();
|
|
||||||
tzOffset = pi.tzOffset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,10 +139,32 @@ public PersonIdent(final PersonIdent pi, final Date aWhen) {
|
||||||
*/
|
*/
|
||||||
public PersonIdent(final String aName, final String aEmailAddress,
|
public PersonIdent(final String aName, final String aEmailAddress,
|
||||||
final Date aWhen, final TimeZone aTZ) {
|
final Date aWhen, final TimeZone aTZ) {
|
||||||
name = aName;
|
this(aName, aEmailAddress, aWhen.getTime(), aTZ.getOffset(aWhen
|
||||||
emailAddress = aEmailAddress;
|
.getTime()) / (60 * 1000));
|
||||||
when = aWhen.getTime();
|
}
|
||||||
tzOffset = aTZ.getOffset(when) / (60 * 1000);
|
|
||||||
|
/**
|
||||||
|
* Copy a PersonIdent, but alter the clone's time stamp
|
||||||
|
*
|
||||||
|
* @param pi
|
||||||
|
* original {@link PersonIdent}
|
||||||
|
* @param aWhen
|
||||||
|
* local time stamp
|
||||||
|
* @param aTZ
|
||||||
|
* time zone
|
||||||
|
*/
|
||||||
|
public PersonIdent(final PersonIdent pi, final long aWhen, final int aTZ) {
|
||||||
|
this(pi.getName(), pi.getEmailAddress(), aWhen, aTZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PersonIdent(final String aName, final String aEmailAddress,
|
||||||
|
long when) {
|
||||||
|
this(aName, aEmailAddress, when, SystemReader.getInstance()
|
||||||
|
.getTimezone(when));
|
||||||
|
}
|
||||||
|
|
||||||
|
private PersonIdent(final UserConfig config) {
|
||||||
|
this(config.getCommitterName(), config.getCommitterEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,29 +179,18 @@ public PersonIdent(final String aName, final String aEmailAddress,
|
||||||
*/
|
*/
|
||||||
public PersonIdent(final String aName, final String aEmailAddress,
|
public PersonIdent(final String aName, final String aEmailAddress,
|
||||||
final long aWhen, final int aTZ) {
|
final long aWhen, final int aTZ) {
|
||||||
|
if (aName == null)
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Name of PersonIdent must not be null.");
|
||||||
|
if (aEmailAddress == null)
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"E-mail address of PersonIdent must not be null.");
|
||||||
name = aName;
|
name = aName;
|
||||||
emailAddress = aEmailAddress;
|
emailAddress = aEmailAddress;
|
||||||
when = aWhen;
|
when = aWhen;
|
||||||
tzOffset = aTZ;
|
tzOffset = aTZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy a PersonIdent, but alter the clone's time stamp
|
|
||||||
*
|
|
||||||
* @param pi
|
|
||||||
* original {@link PersonIdent}
|
|
||||||
* @param aWhen
|
|
||||||
* local time stamp
|
|
||||||
* @param aTZ
|
|
||||||
* time zone
|
|
||||||
*/
|
|
||||||
public PersonIdent(final PersonIdent pi, final long aWhen, final int aTZ) {
|
|
||||||
name = pi.getName();
|
|
||||||
emailAddress = pi.getEmailAddress();
|
|
||||||
when = aWhen;
|
|
||||||
tzOffset = aTZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Name of person
|
* @return Name of person
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue