Skip to content

Commit

Permalink
Fixed nullpointer on pushing to an empty repository (issue 69)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitblit committed Feb 24, 2012
1 parent 18d398e commit 4fea450
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/04_releases.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Push requests to these repositories will be rejected.

#### fixes

- Fixed (harmless) nullpointer on pushing to an empty repository (issue 69)
- Fixed possible nullpointer from the servlet container on startup (issue 67)
- Fixed UTF-8 encoding bug on diff page (issue 66)
- Fixed timezone bug on the activity page (issue 54)
Expand Down
2 changes: 1 addition & 1 deletion src/com/gitblit/GitBlit.java
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ public RepositoryModel getRepositoryModel(String repositoryName) {
RepositoryModel model = new RepositoryModel();
model.name = repositoryName;
model.hasCommits = JGitUtils.hasCommits(r);
model.lastChange = JGitUtils.getLastChange(r, null);
model.lastChange = JGitUtils.getLastChange(r);
model.isBare = r.isBare();
StoredConfig config = JGitUtils.readConfig(r);
if (config != null) {
Expand Down
36 changes: 16 additions & 20 deletions src/com/gitblit/utils/JGitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,9 @@ public static boolean hasCommits(Repository repository) {
* last modified date of the repository folder is returned.
*
* @param repository
* @param branch
* if unspecified, all branches are checked.
* @return
*/
public static Date getLastChange(Repository repository, String branch) {
public static Date getLastChange(Repository repository) {
if (!hasCommits(repository)) {
// null repository
if (repository == null) {
Expand All @@ -436,26 +434,21 @@ public static Date getLastChange(Repository repository, String branch) {
// fresh repository
return new Date(repository.getDirectory().lastModified());
}
if (StringUtils.isEmpty(branch)) {
List<RefModel> branchModels = getLocalBranches(repository, true, -1);
if (branchModels.size() > 0) {
// find most recent branch update
Date lastChange = new Date(0);
for (RefModel branchModel : branchModels) {
if (branchModel.getDate().after(lastChange)) {
lastChange = branchModel.getDate();
}

List<RefModel> branchModels = getLocalBranches(repository, true, -1);
if (branchModels.size() > 0) {
// find most recent branch update
Date lastChange = new Date(0);
for (RefModel branchModel : branchModels) {
if (branchModel.getDate().after(lastChange)) {
lastChange = branchModel.getDate();
}
return lastChange;
} else {
// try to find head
branch = Constants.HEAD;
}
return lastChange;
}

// lookup specified branch
RevCommit commit = getCommit(repository, branch);
return getCommitDate(commit);

// default to the repository folder modification date
return new Date(repository.getDirectory().lastModified());
}

/**
Expand Down Expand Up @@ -962,6 +955,9 @@ public static List<RevCommit> getRevLog(Repository repository, String objectId,
} else {
branchObject = repository.resolve(objectId);
}
if (branchObject == null) {
return list;
}

RevWalk rw = new RevWalk(repository);
rw.markStart(rw.parseCommit(branchObject));
Expand Down
2 changes: 1 addition & 1 deletion src/com/gitblit/wicket/pages/SummaryPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public SummaryPage(PageParameters params) {
add(new Label("repositoryOwner", getRepositoryModel().owner));

add(WicketUtils.createTimestampLabel("repositoryLastChange",
JGitUtils.getLastChange(r, null), getTimeZone()));
JGitUtils.getLastChange(r), getTimeZone()));
if (metricsTotal == null) {
add(new Label("branchStats", ""));
} else {
Expand Down
6 changes: 3 additions & 3 deletions tests/com/gitblit/tests/JGitUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public void testFirstCommit() throws Exception {

@Test
public void testLastCommit() throws Exception {
assertEquals(new Date(0), JGitUtils.getLastChange(null, null));
assertEquals(new Date(0), JGitUtils.getLastChange(null));

Repository repository = GitBlitSuite.getHelloworldRepository();
assertTrue(JGitUtils.getCommit(repository, null) != null);
Date date = JGitUtils.getLastChange(repository, null);
Date date = JGitUtils.getLastChange(repository);
repository.close();
assertNotNull("Could not get last repository change date!", date);
}
Expand All @@ -119,7 +119,7 @@ public void testCreateRepository() throws Exception {
assertNull(JGitUtils.getFirstCommit(repository, null));
assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
.getTime());
assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository, null).getTime());
assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
assertNull(JGitUtils.getCommit(repository, null));
repository.close();
assertTrue(GitBlit.self().deleteRepository(repositoryName));
Expand Down

0 comments on commit 4fea450

Please sign in to comment.