ObjectWalk: close ObjectReader on close() if needed

If the walk is created via ObjectWalk(Repository), it creates a new
ObjectReader. This reader was closed only on dispose(). If such an
ObjectWalk was used in a try-with-resource statement the reader might
not get closed.

Bug: 578458
Change-Id: I1be31829dc466530f23006a53c29b657fd5fb410
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2022-01-30 22:15:14 +01:00
parent d4d30bc716
commit 4bb87a957f
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at * terms of the Eclipse Distribution License v. 1.0 which is available at
@ -139,7 +139,7 @@ public void visited(RevObject o) {
* the repository the walker will obtain data from. * the repository the walker will obtain data from.
*/ */
public ObjectWalk(Repository repo) { public ObjectWalk(Repository repo) {
this(repo.newObjectReader()); this(repo.newObjectReader(), true);
} }
/** /**
@ -151,7 +151,11 @@ public ObjectWalk(Repository repo) {
* required. * required.
*/ */
public ObjectWalk(ObjectReader or) { public ObjectWalk(ObjectReader or) {
super(or); this(or, false);
}
private ObjectWalk(ObjectReader or, boolean closeReader) {
super(or, closeReader);
setRetainBody(false); setRetainBody(false);
rootObjects = new ArrayList<>(); rootObjects = new ArrayList<>();
pendingObjects = new BlockObjQueue(); pendingObjects = new BlockObjQueue();

View File

@ -215,7 +215,7 @@ public RevWalk(ObjectReader or) {
this(or, false); this(or, false);
} }
private RevWalk(ObjectReader or, boolean closeReader) { RevWalk(ObjectReader or, boolean closeReader) {
reader = or; reader = or;
idBuffer = new MutableObjectId(); idBuffer = new MutableObjectId();
objects = new ObjectIdOwnerMap<>(); objects = new ObjectIdOwnerMap<>();