61
62
static struct string_list push_options_config = STRING_LIST_INIT_DUP;
63
64
-static const char *map_refspec(const char *ref,
65
- struct remote *remote, struct ref *local_refs)
64
+static void refspec_append_mapped(struct refspec *refspec, const char *ref,
65
+ struct remote *remote, struct ref *local_refs)
66
{
67
const char *branch_name;
68
struct ref *matched = NULL;
69
70
/* Does "ref" uniquely name our ref? */
71
- if (count_refspec_match(ref, local_refs, &matched) != 1)
72
- return ref;
71
+ if (count_refspec_match(ref, local_refs, &matched) != 1) {
72
+ refspec_append(refspec, ref);
73
+ return;
74
+ }
75
76
if (remote->push.nr) {
77
struct refspec_item query;
82
strbuf_addf(&buf, "%s%s:%s",
83
query.force ? "+" : "",
84
query.src, query.dst);
83
- return strbuf_detach(&buf, NULL);
85
+ refspec_append(refspec, buf.buf);
86
+ strbuf_release(&buf);
87
+ return;
88
}
89
}
90
95
struct strbuf buf = STRBUF_INIT;
96
strbuf_addf(&buf, "%s:%s",
97
ref, branch->merge[0]->src);
94
- return strbuf_detach(&buf, NULL);
98
+ refspec_append(refspec, buf.buf);
99
+ strbuf_release(&buf);
100
+ return;
101
}
102
}
103
98
- return ref;
104
+ refspec_append(refspec, ref);
105
}
106
107
static void set_refspecs(const char **refs, int nr, const char *repo)
121
strbuf_addf(&tagref, ":refs/tags/%s", ref);
122
else
123
strbuf_addf(&tagref, "refs/tags/%s", ref);
118
- ref = strbuf_detach(&tagref, NULL);
124
+ refspec_append(&rs, tagref.buf);
125
+ strbuf_release(&tagref);
126
} else if (deleterefs) {
127
struct strbuf delref = STRBUF_INIT;
128
if (strchr(ref, ':'))
129
die(_("--delete only accepts plain target ref names"));
130
strbuf_addf(&delref, ":%s", ref);
124
- ref = strbuf_detach(&delref, NULL);
131
+ refspec_append(&rs, delref.buf);
132
+ strbuf_release(&delref);
133
} else if (!strchr(ref, ':')) {
134
if (!remote) {
135
/* lazily grab remote and local_refs */
136
remote = remote_get(repo);
137
local_refs = get_local_heads();
138
}
131
- ref = map_refspec(ref, remote, local_refs);
132
- }
133
- refspec_append(&rs, ref);
139
+ refspec_append_mapped(&rs, ref, remote, local_refs);
140
+ } else
141
+ refspec_append(&rs, ref);
142
}
143
}
144
229
230
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
231
refspec_append(&rs, refspec.buf);
232
+ strbuf_release(&refspec);
233
}
234
235
static void setup_push_current(struct remote *remote, struct branch *branch)
240
die(_(message_detached_head_die), remote->name);
241
strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
242
refspec_append(&rs, refspec.buf);
243
+ strbuf_release(&refspec);
244
}
245
246
static int is_workflow_triangular(struct remote *remote)