Browse Source

Return 'this' from setters in commands

To avoid breaking ABI, take the opportunity to give these setters
(hopefully sometimes better) names and deprecate their old names.

Change-Id: Ib45011678c3d941f8ecc1a1e0fdf4c09cdc337e3
Signed-off-by: Mario Molina <mmolimar@gmail.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
stable-5.3
Mario Molina 6 years ago committed by Jonathan Nieder
parent
commit
6c8240a751
  1. 23
      org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteRemoveCommand.java
  2. 86
      org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteSetUrlCommand.java
  3. 42
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java

23
org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteRemoveCommand.java

@ -65,7 +65,7 @@ import org.eclipse.jgit.transport.RemoteConfig;
*/ */
public class RemoteRemoveCommand extends GitCommand<RemoteConfig> { public class RemoteRemoveCommand extends GitCommand<RemoteConfig> {
private String name; private String remoteName;
/** /**
* <p> * <p>
@ -84,9 +84,24 @@ public class RemoteRemoveCommand extends GitCommand<RemoteConfig> {
* *
* @param name * @param name
* a remote name * a remote name
* @deprecated use {@link #setRemoteName} instead
*/ */
@Deprecated
public void setName(String name) { public void setName(String name) {
this.name = name; this.remoteName = name;
}
/**
* The name of the remote to remove.
*
* @param remoteName
* a remote name
* @return {@code this}
* @since 5.3
*/
public RemoteRemoveCommand setRemoteName(String remoteName) {
this.remoteName = remoteName;
return this;
} }
/** /**
@ -101,8 +116,8 @@ public class RemoteRemoveCommand extends GitCommand<RemoteConfig> {
try { try {
StoredConfig config = repo.getConfig(); StoredConfig config = repo.getConfig();
RemoteConfig remote = new RemoteConfig(config, name); RemoteConfig remote = new RemoteConfig(config, remoteName);
config.unsetSection(ConfigConstants.CONFIG_KEY_REMOTE, name); config.unsetSection(ConfigConstants.CONFIG_KEY_REMOTE, remoteName);
config.save(); config.save();
return remote; return remote;
} catch (IOException | URISyntaxException e) { } catch (IOException | URISyntaxException e) {

86
org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteSetUrlCommand.java

@ -66,11 +66,28 @@ import org.eclipse.jgit.transport.URIish;
*/ */
public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> { public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
private String name; /**
* The available URI types for the remote.
*
* @since 5.3
*/
public enum UriType {
/**
* Fetch URL for the remote.
*/
FETCH,
/**
* Push URL for the remote.
*/
PUSH
}
private URIish uri;
private boolean push; private String remoteName;
private URIish remoteUri;
private UriType type;
/** /**
* <p> * <p>
@ -89,9 +106,24 @@ public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
* *
* @param name * @param name
* a remote name * a remote name
* @deprecated use {@link #setRemoteName} instead
*/ */
@Deprecated
public void setName(String name) { public void setName(String name) {
this.name = name; this.remoteName = name;
}
/**
* The name of the remote to change the URL for.
*
* @param remoteName
* a remote remoteName
* @return {@code this}
* @since 5.3
*/
public RemoteSetUrlCommand setRemoteName(String remoteName) {
this.remoteName = remoteName;
return this;
} }
/** /**
@ -99,9 +131,24 @@ public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
* *
* @param uri * @param uri
* an URL for the remote * an URL for the remote
* @deprecated use {@link #setRemoteUri} instead
*/ */
@Deprecated
public void setUri(URIish uri) { public void setUri(URIish uri) {
this.uri = uri; this.remoteUri = uri;
}
/**
* The new URL for the remote.
*
* @param remoteUri
* an URL for the remote
* @return {@code this}
* @since 5.3
*/
public RemoteSetUrlCommand setRemoteUri(URIish remoteUri) {
this.remoteUri = remoteUri;
return this;
} }
/** /**
@ -110,9 +157,28 @@ public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
* @param push * @param push
* <code>true</code> to set the push url, <code>false</code> to * <code>true</code> to set the push url, <code>false</code> to
* set the fetch url * set the fetch url
* @deprecated use {@link #setUriType} instead
*/ */
@Deprecated
public void setPush(boolean push) { public void setPush(boolean push) {
this.push = push; if (push) {
setUriType(UriType.PUSH);
} else {
setUriType(UriType.FETCH);
}
}
/**
* Whether to change the push URL of the remote instead of the fetch URL.
*
* @param type
* the <code>UriType</code> value to set
* @return {@code this}
* @since 5.3
*/
public RemoteSetUrlCommand setUriType(UriType type) {
this.type = type;
return this;
} }
/** /**
@ -127,8 +193,8 @@ public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
try { try {
StoredConfig config = repo.getConfig(); StoredConfig config = repo.getConfig();
RemoteConfig remote = new RemoteConfig(config, name); RemoteConfig remote = new RemoteConfig(config, remoteName);
if (push) { if (type == UriType.PUSH) {
List<URIish> uris = remote.getPushURIs(); List<URIish> uris = remote.getPushURIs();
if (uris.size() > 1) { if (uris.size() > 1) {
throw new JGitInternalException( throw new JGitInternalException(
@ -136,7 +202,7 @@ public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
} else if (uris.size() == 1) { } else if (uris.size() == 1) {
remote.removePushURI(uris.get(0)); remote.removePushURI(uris.get(0));
} }
remote.addPushURI(uri); remote.addPushURI(remoteUri);
} else { } else {
List<URIish> uris = remote.getURIs(); List<URIish> uris = remote.getURIs();
if (uris.size() > 1) { if (uris.size() > 1) {
@ -145,7 +211,7 @@ public class RemoteSetUrlCommand extends GitCommand<RemoteConfig> {
} else if (uris.size() == 1) { } else if (uris.size() == 1) {
remote.removeURI(uris.get(0)); remote.removeURI(uris.get(0));
} }
remote.addURI(uri); remote.addURI(remoteUri);
} }
remote.update(config); remote.update(config);

42
org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java

@ -96,9 +96,9 @@ public class StashApplyCommand extends GitCommand<ObjectId> {
private String stashRef; private String stashRef;
private boolean applyIndex = true; private boolean restoreIndex = true;
private boolean applyUntracked = true; private boolean restoreUntracked = true;
private boolean ignoreRepositoryState; private boolean ignoreRepositoryState;
@ -196,7 +196,7 @@ public class StashApplyCommand extends GitCommand<ObjectId> {
.getParent(1)); .getParent(1));
ObjectId stashHeadCommit = stashCommit.getParent(0); ObjectId stashHeadCommit = stashCommit.getParent(0);
ObjectId untrackedCommit = null; ObjectId untrackedCommit = null;
if (applyUntracked && stashCommit.getParentCount() == 3) if (restoreUntracked && stashCommit.getParentCount() == 3)
untrackedCommit = revWalk.parseCommit(stashCommit.getParent(2)); untrackedCommit = revWalk.parseCommit(stashCommit.getParent(2));
ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo); ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);
@ -216,7 +216,7 @@ public class StashApplyCommand extends GitCommand<ObjectId> {
dc, merger.getResultTreeId()); dc, merger.getResultTreeId());
dco.setFailOnConflict(true); dco.setFailOnConflict(true);
dco.checkout(); // Ignoring failed deletes.... dco.checkout(); // Ignoring failed deletes....
if (applyIndex) { if (restoreIndex) {
ResolveMerger ixMerger = (ResolveMerger) strategy ResolveMerger ixMerger = (ResolveMerger) strategy
.newMerger(repo, true); .newMerger(repo, true);
ixMerger.setCommitNames(new String[] { "stashed HEAD", //$NON-NLS-1$ ixMerger.setCommitNames(new String[] { "stashed HEAD", //$NON-NLS-1$
@ -277,9 +277,24 @@ public class StashApplyCommand extends GitCommand<ObjectId> {
* *
* @param applyIndex * @param applyIndex
* true (default) if the command should restore the index state * true (default) if the command should restore the index state
* @deprecated use {@link #setRestoreIndex} instead
*/ */
@Deprecated
public void setApplyIndex(boolean applyIndex) { public void setApplyIndex(boolean applyIndex) {
this.applyIndex = applyIndex; this.restoreIndex = applyIndex;
}
/**
* Whether to restore the index state
*
* @param restoreIndex
* true (default) if the command should restore the index state
* @return {@code this}
* @since 5.3
*/
public StashApplyCommand setRestoreIndex(boolean restoreIndex) {
this.restoreIndex = restoreIndex;
return this;
} }
/** /**
@ -302,9 +317,24 @@ public class StashApplyCommand extends GitCommand<ObjectId> {
* @param applyUntracked * @param applyUntracked
* true (default) if the command should restore untracked files * true (default) if the command should restore untracked files
* @since 3.4 * @since 3.4
* @deprecated use {@link #setRestoreUntracked} instead
*/ */
@Deprecated
public void setApplyUntracked(boolean applyUntracked) { public void setApplyUntracked(boolean applyUntracked) {
this.applyUntracked = applyUntracked; this.restoreUntracked = applyUntracked;
}
/**
* Whether the command should restore untracked files
*
* @param restoreUntracked
* true (default) if the command should restore untracked files
* @return {@code this}
* @since 5.3
*/
public StashApplyCommand setRestoreUntracked(boolean restoreUntracked) {
this.restoreUntracked = restoreUntracked;
return this;
} }
private void resetIndex(RevTree tree) throws IOException { private void resetIndex(RevTree tree) throws IOException {

Loading…
Cancel
Save