summaryrefslogtreecommitdiff
path: root/src/push.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-04-19 00:55:00 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-04-19 01:02:29 +0200
commitefc2fec50e3bb725b2b244fdeacfb2dfad6ee78e (patch)
tree996e1ba559244e36596d98b7bb2fe4754ac94ee3 /src/push.c
parent4c02d393748d0db382450871ad9ef6898a2ce360 (diff)
downloadlibgit2-efc2fec50e3bb725b2b244fdeacfb2dfad6ee78e.tar.gz
push: report the update plan to the callercmn/negotiation-notify
It can be useful for the caller to know which update commands will be sent to the server before the packfile is pushed up. git does this via the pre-push hook. We don't have hooks, but as it adds introspection into what is happening, we can add a callback which performs the same function.
Diffstat (limited to 'src/push.c')
-rw-r--r--src/push.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/push.c b/src/push.c
index d4171bbd6..3ac6fbf63 100644
--- a/src/push.c
+++ b/src/push.c
@@ -54,6 +54,13 @@ int git_push_new(git_push **out, git_remote *remote)
return -1;
}
+ if (git_vector_init(&p->updates, 0, NULL) < 0) {
+ git_vector_free(&p->status);
+ git_vector_free(&p->specs);
+ git__free(p);
+ return -1;
+ }
+
*out = p;
return 0;
}
@@ -75,7 +82,9 @@ int git_push_set_callbacks(
git_packbuilder_progress pack_progress_cb,
void *pack_progress_cb_payload,
git_push_transfer_progress transfer_progress_cb,
- void *transfer_progress_cb_payload)
+ void *transfer_progress_cb_payload,
+ git_push_negotiation negotiation_cb,
+ void *negotiation_cb_payload)
{
if (!push)
return -1;
@@ -86,6 +95,9 @@ int git_push_set_callbacks(
push->transfer_progress_cb = transfer_progress_cb;
push->transfer_progress_cb_payload = transfer_progress_cb_payload;
+ push->negotiation_cb = negotiation_cb;
+ push->negotiation_cb_payload = negotiation_cb_payload;
+
return 0;
}
@@ -534,6 +546,22 @@ on_error:
return error;
}
+static int add_update(git_push *push, push_spec *spec)
+{
+ git_push_update *u = git__calloc(1, sizeof(git_push_update));
+ GITERR_CHECK_ALLOC(u);
+
+ u->src_refname = git__strdup(spec->refspec.src);
+ GITERR_CHECK_ALLOC(u->src_refname);
+ u->dst_refname = git__strdup(spec->refspec.src);
+ GITERR_CHECK_ALLOC(u->dst_refname);
+
+ git_oid_cpy(&u->src, &spec->loid);
+ git_oid_cpy(&u->dst, &spec->roid);
+
+ return git_vector_insert(&push->updates, u);
+}
+
static int calculate_work(git_push *push)
{
git_remote_head *head;
@@ -559,6 +587,9 @@ static int calculate_work(git_push *push)
break;
}
}
+
+ if (add_update(push, spec) < 0)
+ return -1;
}
return 0;
@@ -590,9 +621,17 @@ static int do_push(git_push *push)
if ((error = git_packbuilder_set_callbacks(push->pb, push->pack_progress_cb, push->pack_progress_cb_payload)) < 0)
goto on_error;
- if ((error = calculate_work(push)) < 0 ||
- (error = queue_objects(push)) < 0 ||
- (error = transport->push(transport, push)) < 0)
+ if ((error = calculate_work(push)) < 0)
+ goto on_error;
+
+ if (push->negotiation_cb &&
+ (error = push->negotiation_cb((const git_push_update **) push->updates.contents,
+ push->updates.length,
+ push->negotiation_cb_payload)))
+ goto on_error;
+
+ if ((error = queue_objects(push)) < 0 ||
+ (error = transport->push(transport, push)) < 0)
goto on_error;
on_error: