Skip to content

Commit

Permalink
transport-helper: update remote helper namespace
Browse files Browse the repository at this point in the history
When pushing, the remote namespace is updated correctly
(e.g. refs/origin/master), but not the remote helper's
(e.g. refs/testgit/origin/master), which currently is only
updated while fetching.

Since the remote namespace is used to tell fast-export which commits
to avoid (because they were already imported/exported), it makes
sense to have them in sync so they don't get generated twice. If the
remote helper was implemented properly, they would be ignored, if
not, they probably would end up repeated.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Felipe Contreras authored and Junio C Hamano committed Apr 18, 2013
1 parent 9c51558 commit 664059f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
12 changes: 12 additions & 0 deletions t/t5801-remote-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ test_expect_success 'push ref with existing object' '
compare_refs local dup server dup
'

test_expect_success 'push update refs' '
(cd local &&
git checkout -b update master &&
echo update >>file &&
git commit -a -m update &&
git push origin update
git rev-parse --verify remotes/origin/update >expect &&
git rev-parse --verify testgit/origin/heads/update >actual &&
test_cmp expect actual
)
'

test_expect_success 'proper failure checks for fetching' '
(GIT_REMOTE_TESTGIT_FAILURE=1 &&
export GIT_REMOTE_TESTGIT_FAILURE &&
Expand Down
23 changes: 19 additions & 4 deletions transport-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "thread-utils.h"
#include "sigchain.h"
#include "argv-array.h"
#include "refs.h"

static int debug;

Expand Down Expand Up @@ -620,7 +621,7 @@ static int fetch(struct transport *transport,
return -1;
}

static void push_update_ref_status(struct strbuf *buf,
static int push_update_ref_status(struct strbuf *buf,
struct ref **ref,
struct ref *remote_refs)
{
Expand Down Expand Up @@ -686,7 +687,7 @@ static void push_update_ref_status(struct strbuf *buf,
*ref = find_ref_by_name(remote_refs, refname);
if (!*ref) {
warning("helper reported unexpected status of %s", refname);
return;
return 1;
}

if ((*ref)->status != REF_STATUS_NONE) {
Expand All @@ -695,11 +696,12 @@ static void push_update_ref_status(struct strbuf *buf,
* status reported by the remote helper if the latter is 'no match'.
*/
if (status == REF_STATUS_NONE)
return;
return 1;
}

(*ref)->status = status;
(*ref)->remote_status = msg;
return 0;
}

static void push_update_refs_status(struct helper_data *data,
Expand All @@ -708,11 +710,24 @@ static void push_update_refs_status(struct helper_data *data,
struct strbuf buf = STRBUF_INIT;
struct ref *ref = remote_refs;
for (;;) {
char *private;

recvline(data, &buf);
if (!buf.len)
break;

push_update_ref_status(&buf, &ref, remote_refs);
if (push_update_ref_status(&buf, &ref, remote_refs))
continue;

if (!data->refspecs)
continue;

/* propagate back the update to the remote namespace */
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
if (!private)
continue;
update_ref("update by helper", private, ref->new_sha1, NULL, 0, 0);
free(private);
}
strbuf_release(&buf);
}
Expand Down

0 comments on commit 664059f

Please sign in to comment.