When a caller uses branch_get() to retrieve a "struct branch", they get
the per-branch remote name and a pointer to the remote struct. However,
they have no way of knowing about the per-branch pushremote from this
interface. So, let's expose that information via fields similar to
"remote" and "remote_name"; "pushremote" and "pushremote_name".

Helped-by: Jeff King <p...@peff.net>
Signed-off-by: Ramkumar Ramachandra <artag...@gmail.com>
---
 remote.c | 15 ++++++++++++---
 remote.h |  3 +++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/remote.c b/remote.c
index a89efab..286cdce 100644
--- a/remote.c
+++ b/remote.c
@@ -351,9 +351,10 @@ static int handle_config(const char *key, const char 
*value, void *cb)
                                explicit_default_remote_name = 1;
                        }
                } else if (!strcmp(subkey, ".pushremote")) {
+                       if (git_config_string(&branch->pushremote_name, key, 
value))
+                               return -1;
                        if (branch == current_branch)
-                               if (git_config_string(&pushremote_name, key, 
value))
-                                       return -1;
+                               pushremote_name = branch->pushremote_name;
                } else if (!strcmp(subkey, ".merge")) {
                        if (!value)
                                return config_error_nonbool(key);
@@ -1543,7 +1544,9 @@ struct branch *branch_get(const char *name)
                ret = current_branch;
        else
                ret = make_branch(name, 0);
-       if (ret && ret->remote_name) {
+       if (!ret)
+               return ret;
+       if (ret->remote_name) {
                ret->remote = remote_get(ret->remote_name);
                if (ret->merge_nr) {
                        int i;
@@ -1557,6 +1560,12 @@ struct branch *branch_get(const char *name)
                        }
                }
        }
+       if (ret->pushremote_name)
+               ret->pushremote = remote_get(ret->pushremote_name);
+       else if (pushremote_name)
+               ret->pushremote = remote_get(pushremote_name);
+       else
+               ret->pushremote = ret->remote;
        return ret;
 }
 
diff --git a/remote.h b/remote.h
index 00c6a76..ac5aadc 100644
--- a/remote.h
+++ b/remote.h
@@ -201,6 +201,9 @@ struct branch {
        const char *remote_name;
        struct remote *remote;
 
+       const char *pushremote_name;
+       struct remote *pushremote;
+
        const char **merge_name;
        struct refspec **merge;
        int merge_nr;
-- 
1.8.5.2.313.g5abf4c0.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to