Skip to content

Commit d290153

Browse files
harrisricvladak
authored andcommitted
Add display revision property to history entry and ensure it is passed around.
1 parent d1b4ed4 commit d290153

File tree

6 files changed

+59
-40
lines changed

6 files changed

+59
-40
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/DirectoryHistoryReader.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class DirectoryHistoryReader {
6868
private static final Logger LOGGER = LoggerFactory.getLogger(DirectoryHistoryReader.class);
6969

7070
// This is a giant hash constructed in this class.
71-
// It maps date -> author -> (comment, revision) -> [ list of files ]
71+
// It maps date -> author -> (comment, revision, displayRevision) -> [ list of files ]
7272
private final Map<Date, Map<String, Map<List<String>, SortedSet<String>>>> hash
7373
= new LinkedHashMap<>(); // set in put()
7474
Iterator<Date> diter;
@@ -142,7 +142,7 @@ public DirectoryHistoryReader(String path) throws IOException {
142142
String.format("An error occurred while getting history reader for '%s'", f), e);
143143
}
144144
if (hist == null) {
145-
put(cdate, "", "-", "", rpath);
145+
put(cdate, "", null, "-", "", rpath);
146146
} else {
147147
// Put all history entries for this file into the giant hash.
148148
readFromHistory(hist, rpath);
@@ -177,9 +177,9 @@ public History getHistory() {
177177
}
178178

179179
// Fill the giant hash with some data from one history entry.
180-
private void put(Date date, String revision, String author, String comment, String path) {
180+
private void put(Date date, String revision, String displayRevision, String author, String comment, String path) {
181181
long time = date.getTime();
182-
date.setTime(time - (time % 3600000L));
182+
date.setTime(time - time % 3600000L);
183183

184184
Map<String, Map<List<String>, SortedSet<String>>> ac = hash.computeIfAbsent(date, k -> new HashMap<>());
185185

@@ -189,6 +189,7 @@ private void put(Date date, String revision, String author, String comment, Stri
189189
List<String> cr = new ArrayList<>();
190190
cr.add(comment);
191191
cr.add(revision);
192+
cr.add(displayRevision);
192193
SortedSet<String> fls = cf.computeIfAbsent(cr, k -> new TreeSet<>());
193194

194195
fls.add(path);
@@ -219,8 +220,8 @@ private boolean next() {
219220

220221
icomment = citer.next();
221222

222-
currentEntry = new HistoryEntry(icomment.get(1), idate, iauthor, icomment.get(0), true);
223-
currentEntry.setFiles(hash.get(idate).get(iauthor).get(icomment));
223+
currentEntry = new HistoryEntry(icomment.get(1), icomment.get(2), idate, iauthor, icomment.get(0), true,
224+
hash.get(idate).get(iauthor).get(icomment));
224225

225226
return true;
226227
}
@@ -239,7 +240,8 @@ private void readFromHistory(History hist, String rpath) {
239240
String cauthor = entry.getAuthor();
240241
Date cdate = entry.getDate();
241242
String revision = entry.getRevision();
242-
put(cdate, revision, cauthor, comment, rpath);
243+
String displayRevision = entry.getDisplayRevision();
244+
put(cdate, revision, displayRevision, cauthor, comment, rpath);
243245
break;
244246
}
245247
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ String findOriginalName(String fullpath, String changeset) throws IOException {
278278
continue;
279279
}
280280

281-
if (commit.getId().getName().startsWith(changeset)) {
281+
if (commit.getId().getName().startsWith(changeset)) { // suspicious? - should be an exact match on revision Id
282282
break;
283283
}
284284

@@ -503,6 +503,7 @@ public void traverseHistory(File file, String sinceRevision, String tillRevision
503503
int num = 0;
504504
for (RevCommit commit : walk) {
505505
CommitInfo commitInfo = new CommitInfo(commit.getId().name(),
506+
commit.getId().abbreviate(GIT_ABBREV_LEN).name(),
506507
commit.getAuthorIdent().getWhen(), commit.getAuthorIdent().getName(),
507508
commit.getAuthorIdent().getEmailAddress(), commit.getFullMessage());
508509

opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryCollector.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class HistoryCollector extends ChangesetVisitor {
3939
renamedFiles = new HashSet<>();
4040
}
4141

42+
@Override
4243
public void accept(RepositoryWithHistoryTraversal.ChangesetInfo changesetInfo) {
4344
RepositoryWithHistoryTraversal.CommitInfo commit = changesetInfo.commit;
4445

@@ -61,17 +62,13 @@ public void accept(RepositoryWithHistoryTraversal.ChangesetInfo changesetInfo) {
6162
author = commit.authorName;
6263
}
6364

64-
HistoryEntry historyEntry = new HistoryEntry(commit.revision,
65+
HistoryEntry historyEntry = new HistoryEntry(
66+
commit.revision, commit.displayRevision,
6567
commit.date, author,
66-
commit.message, true);
68+
commit.message, true, changesetInfo.files);
6769

6870
if (changesetInfo.renamedFiles != null) {
6971
renamedFiles.addAll(changesetInfo.renamedFiles);
70-
}
71-
if (changesetInfo.files != null) {
72-
historyEntry.setFiles(changesetInfo.files);
73-
}
74-
if (changesetInfo.renamedFiles != null) {
7572
// TODO: hack
7673
historyEntry.getFiles().addAll(changesetInfo.renamedFiles);
7774
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryEntry.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class HistoryEntry implements Serializable {
4747
private static final Logger LOGGER = LoggerFactory.getLogger(HistoryEntry.class);
4848

4949
private String revision;
50+
private String displayRevision;
5051
private Date date;
5152
private String author;
5253

@@ -67,27 +68,29 @@ public HistoryEntry() {
6768
* @param that HistoryEntry object
6869
*/
6970
public HistoryEntry(HistoryEntry that) {
70-
this.revision = that.revision;
71-
this.date = that.date;
72-
this.author = that.author;
73-
this.message = that.message;
74-
this.active = that.active;
75-
this.files = that.files;
71+
this(that.revision, that.displayRevision, that.date, that.author, that.message.toString(), that.active, that.files);
7672
}
7773

78-
public HistoryEntry(String revision, Date date, String author, String message, boolean active) {
74+
public HistoryEntry(String revision, String displayRevision, Date date, String author, String message, boolean active, Collection<String> files) {
7975
this.revision = revision;
76+
this.displayRevision = displayRevision;
8077
setDate(date);
8178
this.author = author;
8279
this.message = new StringBuffer(message);
8380
this.active = active;
8481
this.files = new TreeSet<>();
82+
if (files != null) {
83+
this.files.addAll(files);
84+
}
85+
}
86+
87+
public HistoryEntry(String revision, Date date, String author, String message, boolean active) {
88+
this(revision, null, date, author, message, active, null);
8589
}
8690

8791
public HistoryEntry(String revision, Date date, String author,
8892
String message, boolean active, Collection<String> files) {
89-
this(revision, date, author, message, active);
90-
this.files.addAll(files);
93+
this(revision, null, date, author, message, active, files);
9194
}
9295

9396
@VisibleForTesting
@@ -103,11 +106,12 @@ public String getLine() {
103106

104107
public void dump() {
105108

106-
LOGGER.log(Level.FINE, "HistoryEntry : revision = {0}", revision);
107-
LOGGER.log(Level.FINE, "HistoryEntry : date = {0}", date);
108-
LOGGER.log(Level.FINE, "HistoryEntry : author = {0}", author);
109-
LOGGER.log(Level.FINE, "HistoryEntry : active = {0}", (active ?
110-
"True" : "False"));
109+
LOGGER.log(Level.FINE, "HistoryEntry : revision = {0}", revision);
110+
LOGGER.log(Level.FINE, "HistoryEntry : displayRevision = {0}", displayRevision);
111+
LOGGER.log(Level.FINE, "HistoryEntry : date = {0}", date);
112+
LOGGER.log(Level.FINE, "HistoryEntry : author = {0}", author);
113+
LOGGER.log(Level.FINE, "HistoryEntry : active = {0}", active ?
114+
"True" : "False");
111115
String[] lines = message.toString().split("\n");
112116
String separator = "=";
113117
for (String line : lines) {
@@ -128,7 +132,7 @@ public String getAuthor() {
128132
}
129133

130134
public Date getDate() {
131-
return (date == null) ? null : (Date) date.clone();
135+
return date == null ? null : (Date) date.clone();
132136
}
133137

134138
public String getMessage() {
@@ -139,6 +143,10 @@ public String getRevision() {
139143
return revision;
140144
}
141145

146+
public String getDisplayRevision() {
147+
return displayRevision == null ? revision : displayRevision;
148+
}
149+
142150
public void setAuthor(String author) {
143151
this.author = author;
144152
}
@@ -228,13 +236,14 @@ public boolean equals(Object o) {
228236

229237
return Objects.equals(this.getAuthor(), that.getAuthor()) &&
230238
Objects.equals(this.getRevision(), that.getRevision()) &&
239+
Objects.equals(this.getDisplayRevision(), that.getDisplayRevision()) &&
231240
Objects.equals(this.getDate(), that.getDate()) &&
232241
Objects.equals(this.getMessage(), that.getMessage()) &&
233242
Objects.equals(this.getFiles(), that.getFiles());
234243
}
235244

236245
@Override
237246
public int hashCode() {
238-
return Objects.hash(getAuthor(), getRevision(), getDate(), getMessage(), getFiles());
247+
return Objects.hash(getAuthor(), getRevision(), getDisplayRevision(), getDate(), getMessage(), getFiles());
239248
}
240249
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryWithHistoryTraversal.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class RepositoryWithHistoryTraversal extends RepositoryWithPerPa
4848

4949
public static class CommitInfo {
5050
String revision;
51+
String displayRevision;
5152
Date date;
5253
String authorName;
5354
String authorEmail;
@@ -56,8 +57,9 @@ public static class CommitInfo {
5657
CommitInfo() {
5758
}
5859

59-
CommitInfo(String revision, Date date, String authorName, String authorEmail, String message) {
60+
CommitInfo(String revision, String displayRevision, Date date, String authorName, String authorEmail, String message) {
6061
this.revision = revision;
62+
this.displayRevision = displayRevision;
6163
this.date = date;
6264
this.authorName = authorName;
6365
this.authorEmail = authorEmail;

opengrok-indexer/src/test/java/org/opengrok/indexer/history/GitRepositoryTest.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ public class GitRepositoryTest {
8282
private static final String HASH_1086EAF5 = "1086eaf5bca6d5a056097aa76017a8ab0eade20f";
8383
private static final String HASH_67DFBE26 = "67dfbe2648c94a8825671b0f2c132828d0d43079";
8484
private static final String HASH_84599B3C = "84599b3cccb3eeb5aa9aec64771678d6526bcecb";
85+
private static final String ABRV_HASH_84821564 = HASH_84821564.substring(0, 8);
86+
private static final String ABRV_HASH_AA35C258 = HASH_AA35C258.substring(0, 8);
87+
private static final String ABRV_HASH_BB74B7E8 = HASH_BB74B7E8.substring(0, 8);
88+
private static final String ABRV_HASH_CE4C98EC = HASH_CE4C98EC.substring(0, 8);
89+
private static final String ABRV_HASH_B6413947 = HASH_B6413947.substring(0, 8);
90+
private static final String ABRV_HASH_1086EAF5 = HASH_1086EAF5.substring(0, 8);
91+
private static final String ABRV_HASH_67DFBE26 = HASH_67DFBE26.substring(0, 8);
92+
private static final String ABRV_HASH_84599B3C = HASH_84599B3C.substring(0, 8);
8593
private static TestRepository repository = new TestRepository();
8694
private GitRepository instance;
8795

@@ -535,37 +543,37 @@ void testHistory(boolean renamedHandling) throws Exception {
535543
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
536544

537545
List<HistoryEntry> entries = List.of(
538-
new HistoryEntry(HASH_84599B3C, new Date(1485438707000L),
546+
new HistoryEntry(HASH_84599B3C, ABRV_HASH_84599B3C, new Date(1485438707000L),
539547
"Kryštof Tulinger <[email protected]>",
540548
" renaming directories\n\n", true,
541549
Set.of(File.separator + Paths.get("git", "moved2", "renamed2.c"))),
542-
new HistoryEntry(HASH_67DFBE26, new Date(1485263397000L),
550+
new HistoryEntry(HASH_67DFBE26, ABRV_HASH_67DFBE26, new Date(1485263397000L),
543551
"Kryštof Tulinger <[email protected]>",
544552
" renaming renamed -> renamed2\n\n", true,
545553
Set.of(File.separator + Paths.get("git", "moved", "renamed2.c"))),
546-
new HistoryEntry(HASH_1086EAF5, new Date(1485263368000L),
554+
new HistoryEntry(HASH_1086EAF5, ABRV_HASH_1086EAF5, new Date(1485263368000L),
547555
"Kryštof Tulinger <[email protected]>",
548556
" adding some lines into renamed.c\n\n", true,
549557
Set.of(File.separator + Paths.get("git", "moved", "renamed.c"))),
550-
new HistoryEntry(HASH_B6413947, new Date(1485263264000L),
558+
new HistoryEntry(HASH_B6413947, ABRV_HASH_B6413947, new Date(1485263264000L),
551559
"Kryštof Tulinger <[email protected]>",
552560
" moved renamed.c to new location\n\n", true,
553561
Set.of(File.separator + Paths.get("git", "moved", "renamed.c"))),
554-
new HistoryEntry(HASH_CE4C98EC, new Date(1485263232000L), // start in the sub-test below
562+
new HistoryEntry(HASH_CE4C98EC, ABRV_HASH_CE4C98EC, new Date(1485263232000L), // start in the sub-test below
555563
"Kryštof Tulinger <[email protected]>",
556564
" adding simple file for renamed file testing\n\n", true,
557565
Set.of(File.separator + Paths.get("git", "renamed.c"))),
558-
new HistoryEntry(HASH_AA35C258, new Date(1218571965000L),
566+
new HistoryEntry(HASH_AA35C258, ABRV_HASH_AA35C258, new Date(1218571965000L),
559567
"Trond Norbye <[email protected]>",
560568
" Add lint make target and fix lint warnings\n\n", true,
561569
Set.of(File.separator + Paths.get("git", "Makefile"),
562570
File.separator + Paths.get("git", "main.c"))),
563-
new HistoryEntry(HASH_84821564, new Date(1218571643000L),
571+
new HistoryEntry(HASH_84821564, ABRV_HASH_84821564, new Date(1218571643000L),
564572
"Trond Norbye <[email protected]>",
565573
" Add the result of a make on Solaris x86\n\n", true,
566574
Set.of(File.separator + Paths.get("git", "main.o"),
567575
File.separator + Paths.get("git", "testsprog"))),
568-
new HistoryEntry(HASH_BB74B7E8, new Date(1218571573000L),
576+
new HistoryEntry(HASH_BB74B7E8, ABRV_HASH_BB74B7E8, new Date(1218571573000L),
569577
"Trond Norbye <[email protected]>",
570578
" Added a small test program\n\n", true,
571579
Set.of(File.separator + Paths.get("git", "Makefile"),

0 commit comments

Comments
 (0)