summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJiang Xin <zhiyou.jx@alibaba-inc.com>2020-08-27 15:45:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-27 19:48:47 (GMT)
commit1702ae6f61412fa7d858701a7724a5cbf4aeea3e (patch)
tree39e0c2db52ba6e299bc84a1e57cd8e0856f26d76 /transport.c
parentc6a6a01c4acae1ed4b8a61176e3346e90b298ddd (diff)
downloadgit-1702ae6f61412fa7d858701a7724a5cbf4aeea3e.zip
git-1702ae6f61412fa7d858701a7724a5cbf4aeea3e.tar.gz
git-1702ae6f61412fa7d858701a7724a5cbf4aeea3e.tar.bz2
transport: parse report options for tracking refs
When pushing a pseudo reference (such as "refs/for/master/topic"), may create or update one or more references. The real names of the references will be stored in the report options. Parse report options to create or update remote-tracking branches properly. Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/transport.c b/transport.c
index e146de6..a69f2cf 100644
--- a/transport.c
+++ b/transport.c
@@ -437,28 +437,49 @@ int transport_refs_pushed(struct ref *ref)
return 0;
}
-void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+static void update_one_tracking_ref(struct remote *remote, char *refname,
+ struct object_id *new_oid, int deletion,
+ int verbose)
{
struct refspec_item rs;
- if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
- return;
-
- rs.src = ref->name;
+ rs.src = refname;
rs.dst = NULL;
if (!remote_find_tracking(remote, &rs)) {
if (verbose)
fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
- if (ref->deletion) {
+ if (deletion)
delete_ref(NULL, rs.dst, NULL, 0);
- } else
- update_ref("update by push", rs.dst, &ref->new_oid,
+ else
+ update_ref("update by push", rs.dst, new_oid,
NULL, 0, 0);
free(rs.dst);
}
}
+void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+{
+ char *refname;
+ struct object_id *new_oid;
+ struct ref_push_report *report;
+
+ if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
+ return;
+
+ report = ref->report;
+ if (!report)
+ update_one_tracking_ref(remote, ref->name, &ref->new_oid,
+ ref->deletion, verbose);
+ else
+ for (; report; report = report->next) {
+ refname = report->ref_name ? (char *)report->ref_name : ref->name;
+ new_oid = report->new_oid ? report->new_oid : &ref->new_oid;
+ update_one_tracking_ref(remote, refname, new_oid,
+ is_null_oid(new_oid), verbose);
+ }
+}
+
static void print_ref_status(char flag, const char *summary,
struct ref *to, struct ref *from, const char *msg,
struct ref_push_report *report,