Browse Source

DaemonService: Open Repository in try-with-resource

Change-Id: I8deec91d91e82c7cb186cfa9507eb443dd87aad3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-4.11
David Pursehouse 7 years ago committed by Matthias Sohn
parent
commit
a73f6c6009
  1. 16
      org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java

16
org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java

@ -150,23 +150,15 @@ public abstract class DaemonService {
throws IOException, ServiceNotEnabledException,
ServiceNotAuthorizedException {
final String name = commandLine.substring(command.length() + 1);
Repository db;
try {
db = client.getDaemon().openRepository(client, name);
try (Repository db = client.getDaemon().openRepository(client, name)) {
if (isEnabledFor(db)) {
execute(client, db);
}
} catch (ServiceMayNotContinueException e) {
// An error when opening the repo means the client is expecting a ref
// advertisement, so use that style of error.
PacketLineOut pktOut = new PacketLineOut(client.getOutputStream());
pktOut.writeString("ERR " + e.getMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
db = null;
}
if (db == null)
return;
try {
if (isEnabledFor(db))
execute(client, db);
} finally {
db.close();
}
}

Loading…
Cancel
Save