Skip to content

Commit fda44a4

Browse files
committed
Add RefDatabase#getReflogReader methods
to fix broken abstraction in FileRepository#getReflogReader(String). How to get a ReflogReader depends on the chosen RefDatabase implementation, hence the #getReflogReader methods should be there. This also fixes a bug in FileRepository#getReflogReader(Ref) which didn't work if FileReftableDatabase was used as RefDatabase since it always returned the implementation only suitable for RefDirectory. Change-Id: I0859990f9390ab96596b6c344966c687dfbbf167
1 parent d22f306 commit fda44a4

File tree

8 files changed

+86
-33
lines changed

8 files changed

+86
-33
lines changed

Diff for: org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefDatabaseConflictingNamesTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public List<Ref> getAdditionalRefs() throws IOException {
7070
return null;
7171
}
7272

73+
@Override
74+
public ReflogReader getReflogReader(Ref ref) throws IOException {
75+
return null;
76+
}
77+
7378
@Override
7479
public void create() throws IOException {
7580
// Not needed

Diff for: org.eclipse.jgit/.settings/.api_filters

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<component id="org.eclipse.jgit" version="2">
3+
<resource path="src/org/eclipse/jgit/lib/RefDatabase.java" type="org.eclipse.jgit.lib.RefDatabase">
4+
<filter id="336695337">
5+
<message_arguments>
6+
<message_argument value="org.eclipse.jgit.lib.RefDatabase"/>
7+
<message_argument value="getReflogReader(Ref)"/>
8+
</message_arguments>
9+
</filter>
10+
<filter id="336695337">
11+
<message_arguments>
12+
<message_argument value="org.eclipse.jgit.lib.RefDatabase"/>
13+
<message_argument value="getReflogReader(String)"/>
14+
</message_arguments>
15+
</filter>
16+
</resource>
17+
</component>

Diff for: org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.jgit.lib.NullProgressMonitor;
2929
import org.eclipse.jgit.lib.ObjectId;
3030
import org.eclipse.jgit.lib.Ref;
31+
import org.eclipse.jgit.lib.ReflogReader;
3132
import org.eclipse.jgit.revwalk.RevWalk;
3233
import org.eclipse.jgit.transport.ReceiveCommand;
3334
import org.eclipse.jgit.util.RefList;
@@ -176,6 +177,11 @@ public List<Ref> getRefsByPrefixWithExclusions(String include, Set<String> exclu
176177
return reftableDatabase.getRefsByPrefixWithExclusions(include, excludes);
177178
}
178179

180+
@Override
181+
public ReflogReader getReflogReader(Ref ref) throws IOException {
182+
return reftableDatabase.getReflogReader(ref.getName());
183+
}
184+
179185
@Override
180186
public Set<Ref> getTipsWithSha1(ObjectId id) throws IOException {
181187
if (!getReftableConfig().isIndexObjects()) {

Diff for: org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableDatabase.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ public MergedReftable openMergedReftable() throws IOException {
9090
};
9191
}
9292

93-
ReflogReader getReflogReader(String refname) throws IOException {
93+
@Override
94+
public ReflogReader getReflogReader(Ref ref) throws IOException {
95+
return reftableDatabase.getReflogReader(ref.getName());
96+
}
97+
98+
@Override
99+
public ReflogReader getReflogReader(String refname) throws IOException {
94100
return reftableDatabase.getReflogReader(refname);
95101
}
96102

Diff for: org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java

+2-26
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Objects;
3232
import java.util.Set;
3333

34-
import org.eclipse.jgit.annotations.NonNull;
3534
import org.eclipse.jgit.annotations.Nullable;
3635
import org.eclipse.jgit.api.errors.GitAPIException;
3736
import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -542,29 +541,6 @@ public void notifyIndexChanged(boolean internal) {
542541
fireEvent(new IndexChangedEvent(internal));
543542
}
544543

545-
@Override
546-
public ReflogReader getReflogReader(String refName) throws IOException {
547-
if (refs instanceof FileReftableDatabase) {
548-
// Cannot use findRef: reftable stores log data for deleted or renamed
549-
// branches.
550-
return ((FileReftableDatabase)refs).getReflogReader(refName);
551-
}
552-
553-
// TODO: use exactRef here, which offers more predictable and therefore preferable
554-
// behavior.
555-
Ref ref = findRef(refName);
556-
if (ref == null) {
557-
return null;
558-
}
559-
return new ReflogReaderImpl(this, ref.getName());
560-
}
561-
562-
@Override
563-
public @NonNull ReflogReader getReflogReader(@NonNull Ref ref)
564-
throws IOException {
565-
return new ReflogReaderImpl(this, ref.getName());
566-
}
567-
568544
@Override
569545
public AttributesNodeProvider createAttributesNodeProvider() {
570546
return new AttributesNodeProviderImpl(this);
@@ -697,8 +673,8 @@ void convertToPackedRefs(boolean writeLogs, boolean backup) throws IOException {
697673
}
698674

699675
if (writeLogs) {
700-
List<ReflogEntry> logs = oldDb.getReflogReader(r.getName())
701-
.getReverseEntries();
676+
ReflogReader reflogReader = oldDb.getReflogReader(r);
677+
List<ReflogEntry> logs = reflogReader.getReverseEntries();
702678
Collections.reverse(logs);
703679
for (ReflogEntry e : logs) {
704680
logWriter.log(r.getName(), e);

Diff for: org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.eclipse.jgit.lib.RefDatabase;
7777
import org.eclipse.jgit.lib.RefUpdate;
7878
import org.eclipse.jgit.lib.RefWriter;
79+
import org.eclipse.jgit.lib.ReflogReader;
7980
import org.eclipse.jgit.lib.Repository;
8081
import org.eclipse.jgit.lib.SymbolicRef;
8182
import org.eclipse.jgit.revwalk.RevObject;
@@ -456,6 +457,11 @@ public List<Ref> getAdditionalRefs() throws IOException {
456457
return ret;
457458
}
458459

460+
@Override
461+
public ReflogReader getReflogReader(Ref ref) throws IOException {
462+
return new ReflogReaderImpl(getRepository(), ref.getName());
463+
}
464+
459465
@SuppressWarnings("unchecked")
460466
private RefList<Ref> upcast(RefList<? extends Ref> loose) {
461467
return (RefList<Ref>) loose;

Diff for: org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java

+36
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,42 @@ public List<Ref> getRefs() throws IOException {
355355
return getRefsByPrefix(ALL);
356356
}
357357

358+
/**
359+
* Get the reflog reader
360+
*
361+
* @param refName
362+
* a {@link java.lang.String} object.
363+
* @return a {@link org.eclipse.jgit.lib.ReflogReader} for the supplied
364+
* refname, or {@code null} if the named ref does not exist.
365+
* @throws java.io.IOException
366+
* the ref could not be accessed.
367+
* @since 7.2
368+
*/
369+
@Nullable
370+
public ReflogReader getReflogReader(String refName) throws IOException {
371+
// TODO: use exactRef here, which offers more predictable and therefore
372+
// preferable behavior.
373+
Ref ref = findRef(refName);
374+
if (ref == null) {
375+
return null;
376+
}
377+
return getReflogReader(ref);
378+
}
379+
380+
/**
381+
* Get the reflog reader.
382+
*
383+
* @param ref
384+
* a Ref
385+
* @return a {@link org.eclipse.jgit.lib.ReflogReader} for the supplied ref.
386+
* @throws IOException
387+
* if an IO error occurred
388+
* @since 7.2
389+
*/
390+
@NonNull
391+
public abstract ReflogReader getReflogReader(@NonNull Ref ref)
392+
throws IOException;
393+
358394
/**
359395
* Get a section of the reference namespace.
360396
*

Diff for: org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1694,24 +1694,25 @@ public void setGitwebDescription(@Nullable String description)
16941694
* @since 3.0
16951695
*/
16961696
@Nullable
1697-
public abstract ReflogReader getReflogReader(String refName)
1698-
throws IOException;
1697+
public ReflogReader getReflogReader(String refName) throws IOException {
1698+
return getRefDatabase().getReflogReader(refName);
1699+
}
16991700

17001701
/**
17011702
* Get the reflog reader. Subclasses should override this method and provide
17021703
* a more efficient implementation.
17031704
*
17041705
* @param ref
17051706
* a Ref
1706-
* @return a {@link org.eclipse.jgit.lib.ReflogReader} for the supplied ref,
1707-
* or {@code null} if the ref does not exist.
1707+
* @return a {@link org.eclipse.jgit.lib.ReflogReader} for the supplied ref.
17081708
* @throws IOException
17091709
* if an IO error occurred
17101710
* @since 5.13.2
17111711
*/
1712-
public @Nullable ReflogReader getReflogReader(@NonNull Ref ref)
1712+
@NonNull
1713+
public ReflogReader getReflogReader(@NonNull Ref ref)
17131714
throws IOException {
1714-
return getReflogReader(ref.getName());
1715+
return getRefDatabase().getReflogReader(ref);
17151716
}
17161717

17171718
/**

0 commit comments

Comments
 (0)