diff options
Diffstat (limited to 'org.eclipse.jgit')
7 files changed, 77 insertions, 37 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java index fa00581d07..a88dd2a7e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java @@ -59,6 +59,7 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; @@ -156,10 +157,11 @@ public class DeleteBranchCommand extends GitCommand<List<String>> { String shortenedName = fullName .substring(Constants.R_HEADS.length()); // remove upstream configuration if any - repo.getConfig().unsetSection( + final StoredConfig cfg = repo.getConfig(); + cfg.unsetSection( ConfigConstants.CONFIG_BRANCH_SECTION, shortenedName); - repo.getConfig().save(); + cfg.save(); } } else throw new JGitInternalException(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java index 4fe050b2a3..adcea90f56 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java @@ -186,7 +186,7 @@ public class PullCommand extends GitCommand<PullResult> { String remoteUri; FetchResult fetchRes; if (isRemote) { - remoteUri = repo.getConfig().getString("remote", remote, + remoteUri = repoConfig.getString("remote", remote, ConfigConstants.CONFIG_KEY_URL); if (remoteUri == null) { String missingKey = ConfigConstants.CONFIG_REMOTE_SECTION + DOT diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java index 4654981329..04b7791d66 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java @@ -58,6 +58,7 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.lib.RefUpdate.Result; /** @@ -144,27 +145,28 @@ public class RenameBranchCommand extends GitCommand<Ref> { // move the upstream configuration over to the new branch String shortOldName = fullOldName .substring(Constants.R_HEADS.length()); - String oldRemote = repo.getConfig().getString( + final StoredConfig repoConfig = repo.getConfig(); + String oldRemote = repoConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, shortOldName, ConfigConstants.CONFIG_KEY_REMOTE); if (oldRemote != null) { - repo.getConfig().setString( + repoConfig.setString( ConfigConstants.CONFIG_BRANCH_SECTION, newName, ConfigConstants.CONFIG_KEY_REMOTE, oldRemote); } - String oldMerge = repo.getConfig().getString( + String oldMerge = repoConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, shortOldName, ConfigConstants.CONFIG_KEY_MERGE); if (oldMerge != null) { - repo.getConfig().setString( + repoConfig.setString( ConfigConstants.CONFIG_BRANCH_SECTION, newName, ConfigConstants.CONFIG_KEY_MERGE, oldMerge); } - repo.getConfig() + repoConfig .unsetSection( ConfigConstants.CONFIG_BRANCH_SECTION, shortOldName); - repo.getConfig().save(); + repoConfig.save(); } } else diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteParser.java index d916e351bc..11ef10ae70 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteParser.java @@ -91,7 +91,7 @@ final class NoteParser extends CanonicalTreeParser { return new NoteParser(prefix, reader, treeId).parse(); } - private final AbbreviatedObjectId prefix; + private final int prefixLen; private final int pathPadding; @@ -99,16 +99,16 @@ final class NoteParser extends CanonicalTreeParser { private NonNoteEntry lastNonNote; - private NoteParser(AbbreviatedObjectId p, ObjectReader r, ObjectId t) + private NoteParser(AbbreviatedObjectId prefix, ObjectReader r, ObjectId t) throws IncorrectObjectTypeException, IOException { - super(encodeASCII(p.name()), r, t); - prefix = p; + super(encodeASCII(prefix.name()), r, t); + prefixLen = prefix.length(); // Our path buffer has a '/' that we don't want after the prefix. // Drop it by shifting the path down one position. - pathPadding = 0 < prefix.length() ? 1 : 0; + pathPadding = 0 < prefixLen ? 1 : 0; if (0 < pathPadding) - System.arraycopy(path, 0, path, pathPadding, prefix.length()); + System.arraycopy(path, 0, path, pathPadding, prefixLen); } private InMemoryNoteBucket parse() { @@ -130,11 +130,11 @@ final class NoteParser extends CanonicalTreeParser { } // If we cannot determine the style used, assume its a leaf. - return new LeafBucket(prefix.length()); + return new LeafBucket(prefixLen); } private LeafBucket parseLeafTree() { - final LeafBucket leaf = new LeafBucket(prefix.length()); + final LeafBucket leaf = new LeafBucket(prefixLen); final MutableObjectId idBuf = new MutableObjectId(); for (; !eof(); next(1)) { @@ -160,7 +160,7 @@ final class NoteParser extends CanonicalTreeParser { } private FanoutBucket parseFanoutTree() { - final FanoutBucket fanout = new FanoutBucket(prefix.length()); + final FanoutBucket fanout = new FanoutBucket(prefixLen); for (; !eof(); next(1)) { final int cell = parseFanoutCell(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java index a145e7725c..417fa4b53e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java @@ -160,7 +160,7 @@ public class FileRepository extends Repository { loadUserConfig(); loadRepoConfig(); - getConfig().addChangeListener(new ConfigChangedListener() { + repoConfig.addChangeListener(new ConfigChangedListener() { public void onConfigChanged(ConfigChangedEvent event) { fireEvent(event); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java index 926661667e..d9673f74e8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java @@ -49,10 +49,12 @@ import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; +import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Random; @@ -216,35 +218,50 @@ abstract class HttpAuthMethod { @SuppressWarnings("boxing") @Override void configureRequest(final HttpURLConnection conn) throws IOException { - final Map<String, String> p = new HashMap<String, String>(params); - p.put("username", user); + final Map<String, String> r = new LinkedHashMap<String, String>(); - final String realm = p.get("realm"); - final String nonce = p.get("nonce"); - final String uri = p.get("uri"); - final String qop = p.get("qop"); + final String realm = params.get("realm"); + final String nonce = params.get("nonce"); + final String cnonce = params.get("cnonce"); + final String uri = uri(conn.getURL()); + final String qop = params.get("qop"); final String method = conn.getRequestMethod(); final String A1 = user + ":" + realm + ":" + pass; final String A2 = method + ":" + uri; - final String expect; + r.put("username", user); + r.put("realm", realm); + r.put("nonce", nonce); + r.put("uri", uri); + + final String response, nc; if ("auth".equals(qop)) { - final String c = p.get("cnonce"); - final String nc = String.format("%08x", ++requestCount); - p.put("nc", nc); - expect = KD(H(A1), nonce + ":" + nc + ":" + c + ":" + qop + ":" + nc = String.format("%08x", ++requestCount); + response = KD(H(A1), nonce + ":" + nc + ":" + cnonce + ":" + + qop + + ":" + H(A2)); } else { - expect = KD(H(A1), nonce + ":" + H(A2)); + nc = null; + response = KD(H(A1), nonce + ":" + H(A2)); } - p.put("response", expect); + r.put("response", response); + if (params.containsKey("algorithm")) + r.put("algorithm", "MD5"); + if (cnonce != null && qop != null) + r.put("cnonce", cnonce); + if (params.containsKey("opaque")) + r.put("opaque", params.get("opaque")); + if (qop != null) + r.put("qop", qop); + if (nc != null) + r.put("nc", nc); StringBuilder v = new StringBuilder(); - for (Map.Entry<String, String> e : p.entrySet()) { - if (v.length() > 0) { + for (Map.Entry<String, String> e : r.entrySet()) { + if (v.length() > 0) v.append(", "); - } v.append(e.getKey()); v.append('='); v.append('"'); @@ -254,6 +271,25 @@ abstract class HttpAuthMethod { conn.setRequestProperty(HDR_AUTHORIZATION, NAME + " " + v); } + private static String uri(URL u) { + StringBuilder r = new StringBuilder(); + r.append(u.getProtocol()); + r.append("://"); + r.append(u.getHost()); + if (0 < u.getPort()) { + if (u.getPort() == 80 && "http".equals(u.getProtocol())) + /* nothing */; + else if (u.getPort() == 443 && "https".equals(u.getProtocol())) + /* nothing */; + else + r.append(':').append(u.getPort()); + } + r.append(u.getPath()); + if (u.getQuery() != null) + r.append('?').append(u.getQuery()); + return r.toString(); + } + private static String H(String data) { try { MessageDigest md = newMD5(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java index 8132ac3c39..e6609e6719 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java @@ -308,8 +308,8 @@ public class TransportGitSsh extends SshTransport implements PackTransport { List<String> args = new ArrayList<String>(); args.add(ssh); - if (putty) - args.add("--batch"); + if (putty && !ssh.toLowerCase().contains("tortoiseplink")) + args.add("-batch"); if (0 < getURI().getPort()) { args.add(putty ? "-P" : "-p"); args.add(String.valueOf(getURI().getPort())); |