git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 4/6] Add the remote.name.mirror flag to RemoteConfig

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 12, 2009, 23:54 UTC
Message-ID
<1234482880-1316-5-git-send-email-spearce@spearce.org>
In-Reply-To
<1234482880-1316-4-git-send-email-spearce@spearce.org>

This flag is currently only honored by "git push" to delete remote refs if they are also gone on the source side. It also causes the default push spec to be "+refs/*:refs/*" if the user hasn't given us any other push specs.

This change only implements the config file parsing for the mirror flag, as there's still a chunk of code needed on the transport to actually honor it.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../org/spearce/jgit/transport/RemoteConfig.java   |   40 +++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
index 5bbf664..519a8a5 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
@@ -68,6 +68,10 @@
 
 	private static final String KEY_TAGOPT = "tagopt";
 
+	private static final String KEY_MIRROR = "mirror";
+
+	private static final boolean DEFAULT_MIRROR = false;
+
 	/** Default value for {@link #getUploadPack()} if not specified. */
 	public static final String DEFAULT_UPLOAD_PACK = "git-upload-pack";
 
@@ -114,6 +118,8 @@
 
 	private TagOpt tagopt;
 
+	private boolean mirror;
+
 	/**
 	 * Parse a remote block from an existing configuration file.
 	 * <p>
@@ -163,6 +169,7 @@ public RemoteConfig(final RepositoryConfig rc, final String remoteName)
 
 		val = rc.getString(SECTION, name, KEY_TAGOPT);
 		tagopt = TagOpt.fromOption(val);
+		mirror = rc.getBoolean(SECTION, name, KEY_MIRROR, DEFAULT_MIRROR);
 	}
 
 	/**
@@ -192,16 +199,29 @@ public void update(final RepositoryConfig rc) {
 		set(rc, KEY_UPLOADPACK, getUploadPack(), DEFAULT_UPLOAD_PACK);
 		set(rc, KEY_RECEIVEPACK, getReceivePack(), DEFAULT_RECEIVE_PACK);
 		set(rc, KEY_TAGOPT, getTagOpt().option(), TagOpt.AUTO_FOLLOW.option());
+		set(rc, KEY_MIRROR, mirror, DEFAULT_MIRROR);
 	}
 
 	private void set(final RepositoryConfig rc, final String key,
 			final String currentValue, final String defaultValue) {
 		if (defaultValue.equals(currentValue))
-			rc.unsetString(SECTION, getName(), key);
+			unset(rc, key);
 		else
 			rc.setString(SECTION, getName(), key, currentValue);
 	}
 
+	private void set(final RepositoryConfig rc, final String key,
+			final boolean currentValue, final boolean defaultValue) {
+		if (defaultValue == currentValue)
+			unset(rc, key);
+		else
+			rc.setBoolean(SECTION, getName(), key, currentValue);
+	}
+
+	private void unset(final RepositoryConfig rc, final String key) {
+		rc.unsetString(SECTION, getName(), key);
+	}
+
 	/**
 	 * Get the local name this remote configuration is recognized as.
 	 * 
@@ -382,4 +402,22 @@ public TagOpt getTagOpt() {
 	public void setTagOpt(final TagOpt option) {
 		tagopt = option != null ? option : TagOpt.AUTO_FOLLOW;
 	}
+
+	/**
+	 * @return true if pushing to the remote automatically deletes remote refs
+	 *         which don't exist on the source side.
+	 */
+	public boolean isMirror() {
+		return mirror;
+	}
+
+	/**
+	 * Set the mirror flag to automatically delete remote refs.
+	 *
+	 * @param m
+	 *            true to automatically delete remote refs during push.
+	 */
+	public void setMirror(final boolean m) {
+		mirror = m;
+	}
 }
-- 
1.6.2.rc0.226.gf08f
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 5 of 10 in “Add prune of stale tracking branches to fetch”
  1. 0/6 Add prune of stale tracking branches to fetchShawn O. Pearce, Feb 12, 2009
  2. 1/6 Fix RefUpdate.delete to update the result statusShawn O. Pearce, Feb 12, 2009
  3. 2/6 Add setBoolean, setInt to RepositoryConfigShawn O. Pearce, Feb 12, 2009
  4. 3/6 Add RefSpec.expandFromDestination for reverse mappingsShawn O. Pearce, Feb 12, 2009
  5. 4/6 Add the remote.name.mirror flag to RemoteConfigShawn O. Pearce, Feb 12, 2009
  6. 5/6 Don't pass TagOpt to FetchProcess, get it from the TransportShawn O. Pearce, Feb 12, 2009
  7. 6/6 Teach fetch to prune stale tracking branchesShawn O. Pearce, Feb 12, 2009
  8. Junio C HamanoFeb 13, 2009
  9. Shawn O. PearceFeb 13, 2009
  10. Junio C HamanoFeb 13, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.