Skip to content

Commit

Permalink
patch: Use simpler delegate for system reader
Browse files Browse the repository at this point in the history
As suggested by @xenoterracide in #407, JGit now has a
SystemReader.Delegate which is an easier way to manage implementing
SystemReader. This protects us from new methods being added to
SystemReader, which otherwise would have caused a compile error.

Fixes #407
  • Loading branch information
ajoberstar committed Oct 5, 2024
1 parent 1acb536 commit 692bba7
Showing 1 changed file with 6 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,126 +4,35 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;
import org.eclipse.jgit.util.time.MonotonicClock;

public class GrgitSystemReader extends SystemReader {
public class GrgitSystemReader extends SystemReader.Delegate {
private static final Pattern PATH_SPLITTER = Pattern.compile(Pattern.quote(File.pathSeparator));
private final SystemReader delegate;
private final String gitSsh;

public GrgitSystemReader(SystemReader delegate, String gitSsh) {
this.delegate = delegate;
super(delegate);
this.gitSsh = gitSsh;
}

@Override
public String getHostname() {
return delegate.getHostname();
}

@Override
public String getenv(String variable) {
String value = delegate.getenv(variable);
String value = super.getenv(variable);
if ("GIT_SSH".equals(variable) && value == null) {
return gitSsh;
} else {
return value;
}
}

@Override
public String getProperty(String key) {
return delegate.getProperty(key);
}

@Override
public FileBasedConfig openJGitConfig(Config parent, FS fs) {
return delegate.openJGitConfig(parent, fs);
}

@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
return delegate.openUserConfig(parent, fs);
}

@Override
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
return delegate.openSystemConfig(parent, fs);
}

@Override
public long getCurrentTime() {
return delegate.getCurrentTime();
}

@Override
public MonotonicClock getClock() {
return delegate.getClock();
}

@Override
public int getTimezone(long when) {
return delegate.getTimezone(when);
}

@Override
public TimeZone getTimeZone() {
return delegate.getTimeZone();
}

@Override
public Locale getLocale() {
return delegate.getLocale();
}

@Override
public SimpleDateFormat getSimpleDateFormat(String pattern) {
return delegate.getSimpleDateFormat(pattern);
}

@Override
public SimpleDateFormat getSimpleDateFormat(String pattern, Locale locale) {
return delegate.getSimpleDateFormat(pattern, locale);
}

@Override
public DateFormat getDateTimeInstance(int dateStyle, int timeStyle) {
return delegate.getDateTimeInstance(dateStyle, timeStyle);
}

@Override
public boolean isWindows() {
return delegate.isWindows();
}

@Override
public boolean isMacOS() {
return delegate.isWindows();
}

@Override
public void checkPath(String path) throws CorruptObjectException {
delegate.checkPath(path);
}

@Override
public void checkPath(byte[] path) throws CorruptObjectException {
delegate.checkPath(path);
}

public static void install() {
SystemReader current = SystemReader.getInstance();

Expand Down

0 comments on commit 692bba7

Please sign in to comment.