Skip to contentSkip to conversation

Support triangular workflows

PATCH Superseded Ramkumar Ramachandra 4 participants 16 messages Jun 15, 2016 Documentation

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Support triangular workflows

Hi,

This series follows up a previous discussion with Junio and Jeff [1]. It attempts to support the triangular workflow, where the remote you're fetching from is not the same as the remote you're pushing to. remote.<name>.pushurl has already been discussed, and deemed as a poor solution to the problem [2].

[1/4] is a minor cleanup patch to make other patches consistent with the existing style.

[2/4] introduces the infrastructure needed to allow [3/4] and [4/4] to be simple configuration-adding patches.

[3/4] and [4/4] add the proposed configuration options. They're very simple patches, but the documentation is not so simple: I've documented all the side-effects of the other configuration option in each configuration option, to give the reader a comprehensive picture when reading one configuration option.

I've put off implementing remote.default corresponding to remote.pushdefault, as Jeff suggested in [1], because it's currently not an itch; apart from the obvious symmetry, I don't know what purpose it serves: why would anyone want to fetch from a remote other than origin by default? Why wouldn't they simply swap that remote's name with "origin"? However, it's a nice thing to have for symmetry, and it should be trivial to implement: any interested person is welcome to pick it up.

The series works as expected, and all tests pass.

Thanks for reading.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/215763
[2]: http://thread.gmane.org/gmane.comp.version-control.git/215702/focus=215717

Ramkumar Ramachandra (4):
remote.c: simply a bit of code using git_config_string() remote.c: introduce a way to have different remotes for fetch/ push remote.c: introduce remote.pushdefault
remote.c: introduce branch.<name>.pushremote

 Documentation/config.txt | 23 ++++++++++++++++---
 builtin/push.c           |  2 +-
 remote.c                 | 60 +++++++++++++++++++++++++++++++++++-------------
 remote.h                 |  1 +
 4 files changed, 66 insertions(+), 20 deletions(-)
Signature · 1 line
1.8.2
#1 lore raw

PATCH 1/4 remote.c: simply a bit of code using git_config_string()

A small segment where handle_config() parses the branch.remote configuration variable can be simplified using git_config_string().

---
 remote.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
remote.c +1 -3
index e53a6eb..45b69d6 100644
@@ -356,9 +356,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 			return 0;
 		branch = make_branch(name, subkey - name);
 		if (!strcmp(subkey, ".remote")) {
-			if (!value)
-				return config_error_nonbool(key);
-			branch->remote_name = xstrdup(value);
+			git_config_string(&branch->remote_name, key, value);
 			if (branch == current_branch) {
 				default_remote_name = branch->remote_name;
 				explicit_default_remote_name = 1;
Signature · 1 line
1.8.2
#3 lore raw

PATCH 2/4 remote.c: introduce a way to have different remotes for fetch/ push

In reply to Ramkumar Ramachandra

Currently, do_push() in push.c calls remote_get(), which gets the configured remote for fetching and pushing. Replace this call with a call to pushremote_get() instead, a new function that will return the remote configured specifically for pushing. This function tries to work with the string pushremote_name, before falling back to the codepath of remote_get(). This patch has no visible impact, but serves to enable future patches to introduce configuration variables to set this variable.

---
 builtin/push.c |  2 +-
 remote.c       | 49 ++++++++++++++++++++++++++++++++++++-------------
 remote.h       |  1 +
 3 files changed, 38 insertions(+), 14 deletions(-)
builtin/push.c +1 -1
index 42b129d..d447a80 100644
@@ -322,7 +322,7 @@ static int push_with_options(struct transport *transport, int flags)
 static int do_push(const char *repo, int flags)
 {
 	int i, errs;
-	struct remote *remote = remote_get(repo);
+	struct remote *remote = pushremote_get(repo);
 	const char **url;
 	int url_nr;
 
remote.c +36 -13

68 lines not on this page · raw message

remote.h +1 -0
index 251d8fd..99a437f 100644
@@ -51,6 +51,7 @@ struct remote {
 };
 
 struct remote *remote_get(const char *name);
+struct remote *pushremote_get(const char *name);
 int remote_is_configured(const char *name);
 
 typedef int each_remote_fn(struct remote *remote, void *priv);
Signature · 1 line
1.8.2
#4 lore raw

Re: [PATCH 2/4] remote.c: introduce a way to have different remotes for fetch/ push

Quoted 22 lines · Ramkumar Ramachandra
remote.c +22 -0
+struct remote *remote_get(const char *name)
+{
+	int name_given = 0;
+
+	read_config();
+	if (name)
+		name_given = 1;
+	else {
+		name = default_remote_name;
+		name_given = explicit_default_remote_name;
+	}
+	return remote_get_1(name, name_given);
+}
+
+struct remote *pushremote_get(const char *name)
+{
+	int name_given = 0;
+
+	read_config();
+	if (name)
+		name_given = 1;
+	else {

remote.c struct remote *remote_get(const char *name) · line 722

Quoted 10 lines
remote.c +10 -0
+		if (pushremote_name) {
+			name = pushremote_name;
+			name_given = 1;
+		} else {
+			name = default_remote_name;
+			name_given = explicit_default_remote_name;
+		}
+	}
+	return remote_get_1(name, name_given);
+}

Can we get rid of this duplication by having remote_get_1 take a service-specific default argument? And then each service calls it like:

  struct remote *remote_get(const char *name)
  {
          read_config();
          return remote_get_1(name, NULL);
  }

  struct remote *pushremote_get(const char *name)
  {
          read_config();
          return remote_get_1(name, pushremote_name);
  }

and all of the name_given junk can stay in remote_get_1. And adding "remote.default" would just be a matter of changing that NULL in remote_get.

-Peff

#5 lore raw

Re: [PATCH 2/4] remote.c: introduce a way to have different remotes for fetch/ push

Quoted 38 lines · Jeff King
Quoted 22 lines · Ramkumar Ramachandra
remote.c +22 -0
+struct remote *remote_get(const char *name)
+{
+     int name_given = 0;
+
+     read_config();
+     if (name)
+             name_given = 1;
+     else {
+             name = default_remote_name;
+             name_given = explicit_default_remote_name;
+     }
+     return remote_get_1(name, name_given);
+}
+
+struct remote *pushremote_get(const char *name)
+{
+     int name_given = 0;
+
+     read_config();
+     if (name)
+             name_given = 1;
+     else {

remote.c struct remote *remote_get(const char *name) · line 722

Quoted 10 lines
remote.c +10 -0
+             if (pushremote_name) {
+                     name = pushremote_name;
+                     name_given = 1;
+             } else {
+                     name = default_remote_name;
+                     name_given = explicit_default_remote_name;
+             }
+     }
+     return remote_get_1(name, name_given);
+}

Can we get rid of this duplication by having remote_get_1 take a service-specific default argument? And then each service calls it like:

Quoted 11 lines
  struct remote *remote_get(const char *name)
  {
          read_config();
          return remote_get_1(name, NULL);
  }

  struct remote *pushremote_get(const char *name)
  {
          read_config();
          return remote_get_1(name, pushremote_name);
  }

Thanks for the dose of sanity. While at it, why not move read_config() to remote_get_1() as well?

#6 lore raw

Re: [PATCH 2/4] remote.c: introduce a way to have different remotes for fetch/ push

Quoted 9 lines · Ramkumar Ramachandra
Quoted 9 lines

Can we get rid of this duplication by having remote_get_1 take a service-specific default argument? And then each service calls it like:

  struct remote *remote_get(const char *name)
  {
          read_config();
          return remote_get_1(name, NULL);
  }
Quoted 8 lines
Quoted 5 lines
  struct remote *pushremote_get(const char *name)
  {
          read_config();
          return remote_get_1(name, pushremote_name);
  }

Thanks for the dose of sanity. While at it, why not move read_config() to remote_get_1() as well?

Because it sets pushremote_name, and therefore you would just be passing NULL if read_config has not been run yet. But if you made it:

  return remote_get_1(name, &pushremote_name);

that would work.

-Peff

#8 lore raw

PATCH 3/4 remote.c: introduce remote.pushdefault

In reply to Ramkumar Ramachandra

This new configuration variable defines the default remote to push to, and overrides branch.<name>.remote for all branches. It is useful in the typical triangular-workflow setup, where the remote you're fetching from is different from the remote you're pushing to.

---
 Documentation/config.txt | 13 ++++++++++---
 remote.c                 |  4 ++++
 2 files changed, 14 insertions(+), 3 deletions(-)
Documentation/config.txt +10 -3
index bbba728..8ddd0fd 100644
@@ -723,9 +723,12 @@ branch.autosetuprebase::
 	This option defaults to never.
 
 branch.<name>.remote::
-	When in branch <name>, it tells 'git fetch' and 'git push' which
-	remote to fetch from/push to.  It defaults to `origin` if no remote is
-	configured. `origin` is also used if you are not on any branch.
+	When on branch <name>, it tells 'git fetch' and 'git push'
+	which remote to fetch from/push to.  The remote to push to
+	may be overriden with `remote.pushdefault` (for all branches).
+	If no remote is configured, or if you are not on any branch,
+	it defaults to `origin` for fetching and `remote.pushdefault`
+	for pushing.
 
 branch.<name>.merge::
 	Defines, together with branch.<name>.remote, the upstream branch
@@ -1894,6 +1897,10 @@ receive.updateserverinfo::
 	If set to true, git-receive-pack will run git-update-server-info
 	after receiving data from git-push and updating refs.
 
+remote.pushdefault::
+	The remote to push to by default.  Overrides
+	`branch.<name>.remote` for all branches.
+
 remote.<name>.url::
 	The URL of a remote repository.  See linkgit:git-fetch[1] or
 	linkgit:git-push[1].
remote.c +4 -0
index 4704404..987edc4 100644
@@ -350,6 +350,10 @@ static int handle_config(const char *key, const char *value, void *cb)
 	const char *subkey;
 	struct remote *remote;
 	struct branch *branch;
+	if (!prefixcmp(key, "remote.")) {
+		if (!strcmp(key + 7, "pushdefault"))
+			git_config_string(&pushremote_name, key, value);
+	}
 	if (!prefixcmp(key, "branch.")) {
 		name = key + 7;
 		subkey = strrchr(name, '.');
Signature · 1 line
1.8.2
#10 lore raw

PATCH 4/4 remote.c: introduce branch.<name>.pushremote

In reply to Ramkumar Ramachandra

This new configuration variable overrides remote.pushdefault and branch.<name>.remote for pushes. In a typical triangular-workflow setup, you would want to set remote.pushdefault to specify the remote to push to for all branches, and use this option to override it for a specific branch.

---
 Documentation/config.txt | 18 ++++++++++++++----
 remote.c                 |  3 +++
 2 files changed, 17 insertions(+), 4 deletions(-)
Documentation/config.txt +14 -4
index 8ddd0fd..d0e36e9 100644
@@ -726,9 +726,18 @@ branch.<name>.remote::
 	When on branch <name>, it tells 'git fetch' and 'git push'
 	which remote to fetch from/push to.  The remote to push to
 	may be overriden with `remote.pushdefault` (for all branches).
-	If no remote is configured, or if you are not on any branch,
-	it defaults to `origin` for fetching and `remote.pushdefault`
-	for pushing.
+	The remote to push to, for the current branch, may be further
+	overriden by `branch.<name>.pushremote`.  If no remote is
+	configured, or if you are not on any branch, it defaults to
+	`origin` for fetching and `remote.pushdefault` for pushing.
+
+branch.<name>.pushremote::
+	When on branch <name>, it overrides `branch.<name>.remote`
+	when pushing.  It also overrides `remote.pushdefault` when
+	pushing from branch <name>.  In a typical triangular-workflow
+	setup, you would want to set `remote.pushdefault` to specify
+	the remote to push to for all branches, and use this option to
+	override it for a specific branch.
 
 branch.<name>.merge::
 	Defines, together with branch.<name>.remote, the upstream branch
@@ -1899,7 +1908,8 @@ receive.updateserverinfo::
 
 remote.pushdefault::
 	The remote to push to by default.  Overrides
-	`branch.<name>.remote` for all branches.
+	`branch.<name>.remote` for all branches, and is overriden by
+	`branch.<name>.pushremote` for specific branches.
 
 remote.<name>.url::
 	The URL of a remote repository.  See linkgit:git-fetch[1] or
remote.c +3 -0
index 987edc4..a4d3d22 100644
@@ -366,6 +366,9 @@ static int handle_config(const char *key, const char *value, void *cb)
 				default_remote_name = branch->remote_name;
 				explicit_default_remote_name = 1;
 			}
+		} else if (!strcmp(subkey, ".pushremote")) {
+			if (branch == current_branch)
+				git_config_string(&pushremote_name, key, value);
 		} else if (!strcmp(subkey, ".merge")) {
 			if (!value)
 				return config_error_nonbool(key);
Signature · 1 line
1.8.2
#12 lore raw
In reply to Ramkumar Ramachandra
Quoted 8 lines · Ramkumar Ramachandra

I've put off implementing remote.default corresponding to remote.pushdefault, as Jeff suggested in [1], because it's currently not an itch; apart from the obvious symmetry, I don't know what purpose it serves: why would anyone want to fetch from a remote other than origin by default? Why wouldn't they simply swap that remote's name with "origin"? However, it's a nice thing to have for symmetry, and it should be trivial to implement: any interested person is welcome to pick it up.

Yeah, I agree that it does not have much point, aside from people who have an unreasonable aversion to using the word "origin". There was a series posted last summer to add remote.default:

http://article.gmane.org/gmane.comp.version-control.git/201065

It ended up stalled and never got merged. I think the main impetus was that "git clone -o foo" should leave "foo" in remote.default (of course, that still leaves unanswered why anyone would really want to use "-o foo" in the first place).

I think the symmetry makes some sense, but I also think it can come later if somebody wants it.

Quoted 5 lines
 Documentation/config.txt | 23 ++++++++++++++++---
 builtin/push.c           |  2 +-
 remote.c                 | 60 +++++++++++++++++++++++++++++++++++-------------
 remote.h                 |  1 +
 4 files changed, 66 insertions(+), 20 deletions(-)

No new tests?

-Peff

#13 lore raw
Quoted 8 lines · Jeff King
Quoted 5 lines · Ramkumar Ramachandra
 Documentation/config.txt | 23 ++++++++++++++++---
 builtin/push.c           |  2 +-
 remote.c                 | 60 +++++++++++++++++++++++++++++++++++-------------
 remote.h                 |  1 +
 4 files changed, 66 insertions(+), 20 deletions(-)

No new tests?

Honestly, it slipped my mind. Will write it now.

Thanks for the reminder.

#14 lore raw
Quoted 8 lines · Ramkumar Ramachandra
Quoted 7 lines · Jeff King
Quoted 5 lines · Ramkumar Ramachandra
 Documentation/config.txt | 23 ++++++++++++++++---
 builtin/push.c           |  2 +-
 remote.c                 | 60 +++++++++++++++++++++++++++++++++++-------------
 remote.h                 |  1 +
 4 files changed, 66 insertions(+), 20 deletions(-)
Quoted 5 lines
Quoted 1 line

No new tests?

Honestly, it slipped my mind. Will write it now.

Thanks for the reminder.

Thanks. Other than the suggestion I made on 2/4, I do not see anything wrong with the series.

-Peff

#7 lore raw

Re: [PATCH 2/4] remote.c: introduce a way to have different remotes for fetch/ push

In reply to Ramkumar Ramachandra
Quoted 1 line · Ramkumar Ramachandra

remote.c: introduce a way to have different remotes for fetch/ push

s/ push/push/

Quoted 10 lines

Currently, do_push() in push.c calls remote_get(), which gets the configured remote for fetching and pushing. Replace this call with a call to pushremote_get() instead, a new function that will return the remote configured specifically for pushing. This function tries to work with the string pushremote_name, before falling back to the codepath of remote_get(). This patch has no visible impact, but serves to enable future patches to introduce configuration variables to set this variable.

#9 lore raw

Re: [PATCH 3/4] remote.c: introduce remote.pushdefault

In reply to Ramkumar Ramachandra

Documentation/config.txt branch.autosetuprebase:: · line 728

Quoted 7 lines · Ramkumar Ramachandra

branch.<name>.remote::

Documentation/config.txt +3 -3
-       When in branch <name>, it tells 'git fetch' and 'git push' which
-       remote to fetch from/push to.  It defaults to `origin` if no remote is
-       configured. `origin` is also used if you are not on any branch.
+       When on branch <name>, it tells 'git fetch' and 'git push'
+       which remote to fetch from/push to.  The remote to push to
+       may be overriden with `remote.pushdefault` (for all branches).

s/overriden/overridden/

Quoted 3 lines
Documentation/config.txt +3 -0
+       If no remote is configured, or if you are not on any branch,
+       it defaults to `origin` for fetching and `remote.pushdefault`
+       for pushing.
#11 lore raw

Re: [PATCH 4/4] remote.c: introduce branch.<name>.pushremote

In reply to Ramkumar Ramachandra

Documentation/config.txt branch.<name>.remote:: · line 730

Quoted 5 lines · Ramkumar Ramachandra
Documentation/config.txt +2 -3
-       If no remote is configured, or if you are not on any branch,
-       it defaults to `origin` for fetching and `remote.pushdefault`
-       for pushing.
+       The remote to push to, for the current branch, may be further
+       overriden by `branch.<name>.pushremote`.  If no remote is

s/overriden/overridden/

Documentation/config.txt receive.updateserverinfo:: · line 1911

Quoted 7 lines
Documentation/config.txt +4 -1
+       configured, or if you are not on any branch, it defaults to
+       `origin` for fetching and `remote.pushdefault` for pushing.
+
 remote.pushdefault::
        The remote to push to by default.  Overrides
-       `branch.<name>.remote` for all branches.
+       `branch.<name>.remote` for all branches, and is overriden by

Ditto: s/overriden/overridden/

Quoted 1 line

+ branch.<name>.pushremote for specific branches.

#15 lore raw
In reply to Jeff King
Quoted 15 lines · Jeff King
Quoted 8 lines · Ramkumar Ramachandra

I've put off implementing remote.default corresponding to remote.pushdefault, as Jeff suggested in [1], because it's currently not an itch; apart from the obvious symmetry, I don't know what purpose it serves: why would anyone want to fetch from a remote other than origin by default? Why wouldn't they simply swap that remote's name with "origin"? However, it's a nice thing to have for symmetry, and it should be trivial to implement: any interested person is welcome to pick it up.

Yeah, I agree that it does not have much point, aside from people who have an unreasonable aversion to using the word "origin". There was a series posted last summer to add remote.default:

Quoted 6 lines

http://article.gmane.org/gmane.comp.version-control.git/201065

It ended up stalled and never got merged. I think the main impetus was that "git clone -o foo" should leave "foo" in remote.default (of course, that still leaves unanswered why anyone would really want to use "-o foo" in the first place).

I'm the guy who dropped the ball on that series. I still intend to pick it up (honest!) but I just haven't had the time.

The impetus was originally getting relative submodule paths to work on detached HEADs [1]. My patch for that doesn't work when someone does "clone -o", because various parts of git assume there's a remote named "origin". The discussion led to the idea of using the remote name specified during the initial clone, and implementing that as a remote.default config value.

As for why "clone -o" exists, it was added in v1.1.0:

commit e6c310fd0d7384973efc6b1d5999a5e8a5b2f3bd
Author: Johannes Schindelin <[email protected]>
Date: Thu Dec 22 23:37:24 2005 +0100

git-clone: Support changing the origin branch with -o

Earlier, git-clone stored upstream's master in the branch named 'origin', possibly overwriting an existing such branch.

Now you can change it by calling git-clone with '-o <other_name>'.

[jc: added ref format check, subdirectory safety, documentation
and usage string.]

It sounds like the original need for the -o option is no longer pertinent. OTOH, for folks who deal with several remotes it's nice to name them, and "origin" isn't necessarily a useful or intuitive name.

		M.

[1] http://thread.gmane.org/gmane.comp.version-control.git/200145