Skip to content

Commit 5c5b7a8

Browse files
committed
Set author as tooltip of "last change" on repositories page (issue-238)
1 parent d9d4677 commit 5c5b7a8

File tree

8 files changed

+45
-18
lines changed

8 files changed

+45
-18
lines changed

releases.moxie

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ r17: {
6060
- Support header color customizations (issue 209)
6161
- Support username substitution in web.otherUrls (issue 213)
6262
- Option to force client-side basic authentication instead of form-based authentication if web.authenticateViewPages=true (issue 222)
63+
- Set author as tooltip of last change column in the repositories panel (issue-238)
6364
- Setting to automatically create an user account based on an authenticated user principal from the servlet container (issue-246)
6465
- Added WindowsUserService to authenticate users against Windows accounts (issue-250)
6566
- Global and per-repository setting to exclude authors from metrics (issue-251)

src/main/java/com/gitblit/GitBlit.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import com.gitblit.utils.FederationUtils;
122122
import com.gitblit.utils.HttpUtils;
123123
import com.gitblit.utils.JGitUtils;
124+
import com.gitblit.utils.JGitUtils.LastChange;
124125
import com.gitblit.utils.JsonUtils;
125126
import com.gitblit.utils.MetricUtils;
126127
import com.gitblit.utils.ObjectCache;
@@ -1669,7 +1670,9 @@ public RepositoryModel getRepositoryModel(String repositoryName) {
16691670
model.hasCommits = JGitUtils.hasCommits(r);
16701671
}
16711672

1672-
model.lastChange = JGitUtils.getLastChange(r);
1673+
LastChange lc = JGitUtils.getLastChange(r);
1674+
model.lastChange = lc.when;
1675+
model.lastChangeAuthor = lc.who;
16731676
if (!model.skipSizeCalculation) {
16741677
ByteFormat byteFormat = new ByteFormat();
16751678
model.size = byteFormat.format(calculateSize(model));
@@ -1973,7 +1976,9 @@ private RepositoryModel loadRepositoryModel(String repositoryName) {
19731976
model.name = repositoryName;
19741977
}
19751978
model.hasCommits = JGitUtils.hasCommits(r);
1976-
model.lastChange = JGitUtils.getLastChange(r);
1979+
LastChange lc = JGitUtils.getLastChange(r);
1980+
model.lastChange = lc.when;
1981+
model.lastChangeAuthor = lc.who;
19771982
model.projectPath = StringUtils.getFirstPathElement(repositoryName);
19781983

19791984
StoredConfig config = r.getConfig();

src/main/java/com/gitblit/models/RepositoryModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel
4646
public String description;
4747
public List<String> owners;
4848
public Date lastChange;
49+
public String lastChangeAuthor;
4950
public boolean hasCommits;
5051
public boolean showRemoteBranches;
5152
public boolean useTickets;

src/main/java/com/gitblit/utils/JGitUtils.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,39 +439,56 @@ public static boolean hasCommits(Repository repository) {
439439
}
440440
return false;
441441
}
442+
443+
/**
444+
* Encapsulates the result of cloning or pulling from a repository.
445+
*/
446+
public static class LastChange {
447+
public Date when;
448+
public String who;
449+
450+
LastChange() {
451+
when = new Date(0);
452+
}
453+
454+
LastChange(long lastModified) {
455+
this.when = new Date(lastModified);
456+
}
457+
}
442458

443459
/**
444-
* Returns the date of the most recent commit on a branch. If the repository
445-
* does not exist Date(0) is returned. If it does exist but is empty, the
446-
* last modified date of the repository folder is returned.
460+
* Returns the date and author of the most recent commit on a branch. If the
461+
* repository does not exist Date(0) is returned. If it does exist but is
462+
* empty, the last modified date of the repository folder is returned.
447463
*
448464
* @param repository
449-
* @return
465+
* @return a LastChange object
450466
*/
451-
public static Date getLastChange(Repository repository) {
467+
public static LastChange getLastChange(Repository repository) {
452468
if (!hasCommits(repository)) {
453469
// null repository
454470
if (repository == null) {
455-
return new Date(0);
471+
return new LastChange();
456472
}
457473
// fresh repository
458-
return new Date(repository.getDirectory().lastModified());
474+
return new LastChange(repository.getDirectory().lastModified());
459475
}
460476

461477
List<RefModel> branchModels = getLocalBranches(repository, true, -1);
462478
if (branchModels.size() > 0) {
463479
// find most recent branch update
464-
Date lastChange = new Date(0);
480+
LastChange lastChange = new LastChange();
465481
for (RefModel branchModel : branchModels) {
466-
if (branchModel.getDate().after(lastChange)) {
467-
lastChange = branchModel.getDate();
482+
if (branchModel.getDate().after(lastChange.when)) {
483+
lastChange.when = branchModel.getDate();
484+
lastChange.who = branchModel.getAuthorIdent().getName();
468485
}
469486
}
470487
return lastChange;
471488
}
472489

473490
// default to the repository folder modification date
474-
return new Date(repository.getDirectory().lastModified());
491+
return new LastChange(repository.getDirectory().lastModified());
475492
}
476493

477494
/**

src/main/java/com/gitblit/wicket/pages/OverviewPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void populateItem(final Item<String> item) {
9898
add(ownersView);
9999

100100
add(WicketUtils.createTimestampLabel("repositoryLastChange",
101-
JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
101+
JGitUtils.getLastChange(r).when, getTimeZone(), getTimeUtils()));
102102
add(new Label("repositorySize", model.size));
103103

104104
if (metricsTotal == null) {

src/main/java/com/gitblit/wicket/pages/SummaryPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void populateItem(final Item<String> item) {
116116
add(ownersView);
117117

118118
add(WicketUtils.createTimestampLabel("repositoryLastChange",
119-
JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
119+
JGitUtils.getLastChange(r).when, getTimeZone(), getTimeUtils()));
120120
add(new Label("repositorySize", getRepositoryModel().size));
121121
if (metricsTotal == null) {
122122
add(new Label("branchStats", ""));

src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ public void populateItem(final Item<RepositoryModel> item) {
322322
Label lastChangeLabel = new Label("repositoryLastChange", lastChange);
323323
row.add(lastChangeLabel);
324324
WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
325+
if (!StringUtils.isEmpty(entry.lastChangeAuthor)) {
326+
WicketUtils.setHtmlTooltip(lastChangeLabel, getString("gb.author") + ": " + entry.lastChangeAuthor);
327+
}
325328

326329
boolean showOwner = user != null && entry.isOwner(user.username);
327330
boolean myPersonalRepository = showOwner && entry.isUsersPersonalRepository(user.username);

src/test/java/com/gitblit/tests/JGitUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ public void testFirstCommit() throws Exception {
118118

119119
@Test
120120
public void testLastCommit() throws Exception {
121-
assertEquals(new Date(0), JGitUtils.getLastChange(null));
121+
assertEquals(new Date(0), JGitUtils.getLastChange(null).when);
122122

123123
Repository repository = GitBlitSuite.getHelloworldRepository();
124124
assertTrue(JGitUtils.getCommit(repository, null) != null);
125-
Date date = JGitUtils.getLastChange(repository);
125+
Date date = JGitUtils.getLastChange(repository).when;
126126
repository.close();
127127
assertNotNull("Could not get last repository change date!", date);
128128
}
@@ -140,7 +140,7 @@ public void testCreateRepository() throws Exception {
140140
assertNull(JGitUtils.getFirstCommit(repository, null));
141141
assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
142142
.getTime());
143-
assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
143+
assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).when.getTime());
144144
assertNull(JGitUtils.getCommit(repository, null));
145145
repository.close();
146146
RepositoryCache.close(repository);

0 commit comments

Comments
 (0)