@@ -1,5 +1,6 @@
#include "cache.h"
#include "config.h"
+#include "connect.h"
#include "remote.h"
#include "refs.h"
#include "refspec.h"
@@ -2311,3 +2312,30 @@ void apply_push_cas(struct push_cas_option *cas,
for (ref = remote_refs; ref; ref = ref->next)
apply_cas(cas, remote, ref);
}
+
+void update_ref_from_remote_status(struct ref *ref)
+{
+ char *val;
+ char c;
+ int len;
+
+ if (!ref->remote_status)
+ return;
+
+ val = (char *)parse_feature_value(ref->remote_status, "old-oid", &len);
+ if (val && len) {
+ c = *(val+len);
+ *(val+len) = '\0';
+ get_oid_hex(val, &ref->old_oid);
+ *(val+len) = c;
+ }
+ val = (char *)parse_feature_value(ref->remote_status, "new-oid", &len);
+ if (val && len) {
+ c = *(val+len);
+ *(val+len) = '\0';
+ get_oid_hex(val, &ref->new_oid);
+ *(val+len) = c;
+ }
+ if (parse_feature_request(ref->remote_status, "forced-update"))
+ ref->forced_update = 1;
+}
@@ -345,4 +345,7 @@ int parseopt_push_cas_option(const struct option *, const char *arg, int unset);
int is_empty_cas(const struct push_cas_option *);
void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *);
+/* Parse key-value pairs of remote_status and update the reference accordingly */
+void update_ref_from_remote_status(struct ref *ref);
+
#endif
@@ -159,6 +159,9 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
while (1) {
const char *refname;
char *msg;
+ char *extended_status = NULL;
+ int len;
+
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;
if (!starts_with(reader->line, "ok ") && !starts_with(reader->line, "ng ")) {
@@ -167,10 +170,13 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
break;
}
+ len = strlen(reader->line);
refname = reader->line + 3;
msg = strchr(refname, ' ');
if (msg)
*msg++ = '\0';
+ if (reader->pktlen > len)
+ extended_status = (char *)reader->line + len + 1;
/* first try searching at our hint, falling back to all refs */
if (hint)
@@ -194,7 +200,12 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
hint->status = REF_STATUS_REMOTE_REJECT;
ret = -1;
}
- hint->remote_status = xstrdup_or_null(msg);
+ if (msg) {
+ hint->remote_status = xstrdup(msg);
+ } else if (extended_status) {
+ hint->remote_status = xstrdup(extended_status);
+ update_ref_from_remote_status(hint);
+ }
/* start our next search from the next ref */
hint = hint->next;
}
@@ -673,9 +673,9 @@ test_expect_success "report update of all special refs" '
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/review/a/b/c/topic
remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git>
- * [new reference] HEAD -> refs/for/next/topic
+ * [new reference] HEAD -> refs/pull/123/head
* [new reference] HEAD -> refs/review/a/b/c/topic
- * [new reference] HEAD -> refs/for/master/topic
+ + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
@@ -738,7 +738,7 @@ test_expect_success "report mixed refs update" '
* [new branch] HEAD -> baz
* [new reference] HEAD -> refs/for/next/topic
* [new branch] HEAD -> foo
- * [new reference] HEAD -> refs/for/master/topic
+ <OID-A>..<OID-B> HEAD -> refs/for/master/topic
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
@@ -812,8 +812,8 @@ test_expect_success "report test: fallthrough" '
<OID-A>..<OID-B> <COMMIT-B> -> bar
- [deleted] foo
+ <OID-B>...<OID-A> HEAD -> master (forced update)
- * [new reference] HEAD -> refs/for/master/topic
- * [new reference] HEAD -> refs/for/next/topic
+ <OID-A>..<OID-B> HEAD -> refs/pull/123/head
+ + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
@@ -747,37 +747,39 @@ static int push_update_ref_status(struct strbuf *buf,
msg = xstrdup(msg);
strbuf_release(&msg_buf);
- if (!strcmp(msg, "no match")) {
- status = REF_STATUS_NONE;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "up to date")) {
- status = REF_STATUS_UPTODATE;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "non-fast forward")) {
- status = REF_STATUS_REJECT_NONFASTFORWARD;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "already exists")) {
- status = REF_STATUS_REJECT_ALREADY_EXISTS;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "fetch first")) {
- status = REF_STATUS_REJECT_FETCH_FIRST;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "needs force")) {
- status = REF_STATUS_REJECT_NEEDS_FORCE;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "stale info")) {
- status = REF_STATUS_REJECT_STALE;
- FREE_AND_NULL(msg);
- }
- else if (!strcmp(msg, "forced update")) {
- forced = 1;
- FREE_AND_NULL(msg);
+ if (status != REF_STATUS_OK) {
+ if (!strcmp(msg, "no match")) {
+ status = REF_STATUS_NONE;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "up to date")) {
+ status = REF_STATUS_UPTODATE;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "non-fast forward")) {
+ status = REF_STATUS_REJECT_NONFASTFORWARD;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "already exists")) {
+ status = REF_STATUS_REJECT_ALREADY_EXISTS;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "fetch first")) {
+ status = REF_STATUS_REJECT_FETCH_FIRST;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "needs force")) {
+ status = REF_STATUS_REJECT_NEEDS_FORCE;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "stale info")) {
+ status = REF_STATUS_REJECT_STALE;
+ FREE_AND_NULL(msg);
+ }
+ else if (!strcmp(msg, "forced update")) {
+ forced = 1;
+ FREE_AND_NULL(msg);
+ }
}
}
@@ -802,6 +804,8 @@ static int push_update_ref_status(struct strbuf *buf,
(*ref)->status = status;
(*ref)->forced_update |= forced;
(*ref)->remote_status = msg;
+ if (status == REF_STATUS_OK && (*ref)->remote_status)
+ update_ref_from_remote_status(*ref);
return !(status == REF_STATUS_OK);
}
@@ -463,11 +463,30 @@ static void print_ref_status(char flag, const char *summary,
struct ref *to, struct ref *from, const char *msg,
int porcelain, int summary_width)
{
+ char *from_name = NULL;
+ char *to_name = NULL;
+ const char *val;
+ int len;
+
+ if (from && from->remote_status) {
+ val = parse_feature_value(from->remote_status, "ref", &len);
+ if (val && len)
+ from_name = xmemdupz(val, len);
+ }
+ if (to && to->remote_status) {
+ val = parse_feature_value(to->remote_status, "ref", &len);
+ if (val && len)
+ to_name = xmemdupz(val, len);
+ }
+
if (porcelain) {
if (from)
- fprintf(stdout, "%c\t%s:%s\t", flag, from->name, to->name);
+ fprintf(stdout, "%c\t%s:%s\t", flag,
+ from_name ? from_name : from->name,
+ to_name ? to_name: to->name);
else
- fprintf(stdout, "%c\t:%s\t", flag, to->name);
+ fprintf(stdout, "%c\t:%s\t", flag,
+ to_name ? to_name: to->name);
if (msg)
fprintf(stdout, "%s (%s)\n", summary, msg);
else
@@ -481,9 +500,11 @@ static void print_ref_status(char flag, const char *summary,
fprintf(stderr, " %s%c %-*s%s ", red, flag, summary_width,
summary, reset);
if (from)
- fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
+ fprintf(stderr, "%s -> %s",
+ prettify_refname(from_name ? from_name : from->name),
+ prettify_refname(to_name ? to_name : to->name));
else
- fputs(prettify_refname(to->name), stderr);
+ fputs(prettify_refname(to_name ? to_name : to->name), stderr);
if (msg) {
fputs(" (", stderr);
fputs(msg, stderr);
@@ -491,6 +512,10 @@ static void print_ref_status(char flag, const char *summary,
}
fputc('\n', stderr);
}
+ if (from_name)
+ free(from_name);
+ if (to_name)
+ free(to_name);
}
static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_width)