Skip to content

Commit 3714831

Browse files
iabervongitster
authored andcommitted
Allow fetch to modify refs
This allows the transport to use the null sha1 for a ref reported to be present in the remote repository to indicate that a ref exists but its actual value is presently unknown and will be set if the objects are fetched. Also adds documentation to the API to specify exactly what the methods should do and how they should interpret arguments. Signed-off-by: Daniel Barkalow <[email protected]> Signed-off-by: Sverre Rabbelier <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a4da29 commit 3714831

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

Diff for: builtin-clone.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
360360
const char *repo_name, *repo, *work_tree, *git_dir;
361361
char *path, *dir;
362362
int dest_exists;
363-
const struct ref *refs, *remote_head, *mapped_refs;
363+
const struct ref *refs, *remote_head;
364364
const struct ref *remote_head_points_at;
365365
const struct ref *our_head_points_at;
366+
struct ref *mapped_refs;
366367
struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
367368
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
368369
struct transport *transport = NULL;

Diff for: transport-helper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int release_helper(struct transport *transport)
7575
}
7676

7777
static int fetch_with_fetch(struct transport *transport,
78-
int nr_heads, const struct ref **to_fetch)
78+
int nr_heads, struct ref **to_fetch)
7979
{
8080
struct child_process *helper = get_helper(transport);
8181
FILE *file = xfdopen(helper->out, "r");
@@ -99,7 +99,7 @@ static int fetch_with_fetch(struct transport *transport,
9999
}
100100

101101
static int fetch(struct transport *transport,
102-
int nr_heads, const struct ref **to_fetch)
102+
int nr_heads, struct ref **to_fetch)
103103
{
104104
struct helper_data *data = transport->data;
105105
int i, count;

Diff for: transport.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
204204
}
205205

206206
static int fetch_objs_via_rsync(struct transport *transport,
207-
int nr_objs, const struct ref **to_fetch)
207+
int nr_objs, struct ref **to_fetch)
208208
{
209209
struct strbuf buf = STRBUF_INIT;
210210
struct child_process rsync;
@@ -408,7 +408,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus
408408
}
409409

410410
static int fetch_refs_from_bundle(struct transport *transport,
411-
int nr_heads, const struct ref **to_fetch)
411+
int nr_heads, struct ref **to_fetch)
412412
{
413413
struct bundle_transport_data *data = transport->data;
414414
return unbundle(&data->header, data->fd);
@@ -486,7 +486,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
486486
}
487487

488488
static int fetch_refs_via_pack(struct transport *transport,
489-
int nr_heads, const struct ref **to_fetch)
489+
int nr_heads, struct ref **to_fetch)
490490
{
491491
struct git_transport_data *data = transport->data;
492492
char **heads = xmalloc(nr_heads * sizeof(*heads));
@@ -926,16 +926,17 @@ const struct ref *transport_get_remote_refs(struct transport *transport)
926926
return transport->remote_refs;
927927
}
928928

929-
int transport_fetch_refs(struct transport *transport, const struct ref *refs)
929+
int transport_fetch_refs(struct transport *transport, struct ref *refs)
930930
{
931931
int rc;
932932
int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
933-
const struct ref **heads = NULL;
934-
const struct ref *rm;
933+
struct ref **heads = NULL;
934+
struct ref *rm;
935935

936936
for (rm = refs; rm; rm = rm->next) {
937937
nr_refs++;
938938
if (rm->peer_ref &&
939+
!is_null_sha1(rm->old_sha1) &&
939940
!hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
940941
continue;
941942
ALLOC_GROW(heads, nr_heads + 1, nr_alloc);

Diff for: transport.h

+39-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,48 @@ struct transport {
1818
int (*set_option)(struct transport *connection, const char *name,
1919
const char *value);
2020

21+
/**
22+
* Returns a list of the remote side's refs. In order to allow
23+
* the transport to try to share connections, for_push is a
24+
* hint as to whether the ultimate operation is a push or a fetch.
25+
*
26+
* If the transport is able to determine the remote hash for
27+
* the ref without a huge amount of effort, it should store it
28+
* in the ref's old_sha1 field; otherwise it should be all 0.
29+
**/
2130
struct ref *(*get_refs_list)(struct transport *transport, int for_push);
22-
int (*fetch)(struct transport *transport, int refs_nr, const struct ref **refs);
31+
32+
/**
33+
* Fetch the objects for the given refs. Note that this gets
34+
* an array, and should ignore the list structure.
35+
*
36+
* If the transport did not get hashes for refs in
37+
* get_refs_list(), it should set the old_sha1 fields in the
38+
* provided refs now.
39+
**/
40+
int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
41+
42+
/**
43+
* Push the objects and refs. Send the necessary objects, and
44+
* then, for any refs where peer_ref is set and
45+
* peer_ref->new_sha1 is different from old_sha1, tell the
46+
* remote side to update each ref in the list from old_sha1 to
47+
* peer_ref->new_sha1.
48+
*
49+
* Where possible, set the status for each ref appropriately.
50+
*
51+
* The transport must modify new_sha1 in the ref to the new
52+
* value if the remote accepted the change. Note that this
53+
* could be a different value from peer_ref->new_sha1 if the
54+
* process involved generating new commits.
55+
**/
2356
int (*push_refs)(struct transport *transport, struct ref *refs, int flags);
2457
int (*push)(struct transport *connection, int refspec_nr, const char **refspec, int flags);
2558

59+
/** get_refs_list(), fetch(), and push_refs() can keep
60+
* resources (such as a connection) reserved for futher
61+
* use. disconnect() releases these resources.
62+
**/
2663
int (*disconnect)(struct transport *connection);
2764
char *pack_lockfile;
2865
signed verbose : 2;
@@ -74,7 +111,7 @@ int transport_push(struct transport *connection,
74111

75112
const struct ref *transport_get_remote_refs(struct transport *transport);
76113

77-
int transport_fetch_refs(struct transport *transport, const struct ref *refs);
114+
int transport_fetch_refs(struct transport *transport, struct ref *refs);
78115
void transport_unlock_pack(struct transport *transport);
79116
int transport_disconnect(struct transport *transport);
80117
char *transport_anonymize_url(const char *url);

0 commit comments

Comments
 (0)