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 <barkalow@iabervon.org> Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Barkalow committed
Nov 18, 2009 at 02:42 UTC
3714831189b32591ffe33c08e209a9a61c25a2f6
4 files changed
+50
-11
builtin-clone.c
+2
-1
@@ -360,9 +360,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
360
const char *repo_name, *repo, *work_tree, *git_dir;
361
char *path, *dir;
362
int dest_exists;
363
- const struct ref *refs, *remote_head, *mapped_refs;
363
+ const struct ref *refs, *remote_head;
364
const struct ref *remote_head_points_at;
365
const struct ref *our_head_points_at;
366
+ struct ref *mapped_refs;
367
struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
368
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
369
struct transport *transport = NULL;
transport-helper.c
+2
-2
@@ -75,7 +75,7 @@ static int release_helper(struct transport *transport)
75
}
76
77
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)
79
{
80
struct child_process *helper = get_helper(transport);
81
FILE *file = xfdopen(helper->out, "r");
@@ -99,7 +99,7 @@ static int fetch_with_fetch(struct transport *transport,
99
}
100
101
static int fetch(struct transport *transport,
102
- int nr_heads, const struct ref **to_fetch)
102
+ int nr_heads, struct ref **to_fetch)
103
{
104
struct helper_data *data = transport->data;
105
int i, count;
transport.c
+7
-6
@@ -204,7 +204,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
204
}
205
206
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)
208
{
209
struct strbuf buf = STRBUF_INIT;
210
struct child_process rsync;
@@ -408,7 +408,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus
408
}
409
410
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)
412
{
413
struct bundle_transport_data *data = transport->data;
414
return unbundle(&data->header, data->fd);
@@ -486,7 +486,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
486
}
487
488
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)
490
{
491
struct git_transport_data *data = transport->data;
492
char **heads = xmalloc(nr_heads * sizeof(*heads));
@@ -926,16 +926,17 @@ const struct ref *transport_get_remote_refs(struct transport *transport)
926
return transport->remote_refs;
927
}
928
929
-int transport_fetch_refs(struct transport *transport, const struct ref *refs)
929
+int transport_fetch_refs(struct transport *transport, struct ref *refs)
930
{
931
int rc;
932
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;
935
936
for (rm = refs; rm; rm = rm->next) {
937
nr_refs++;
938
if (rm->peer_ref &&
939
+ !is_null_sha1(rm->old_sha1) &&
940
!hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
941
continue;
942
ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
transport.h
+39
-2
@@ -18,11 +18,48 @@ struct transport {
18
int (*set_option)(struct transport *connection, const char *name,
19
const char *value);
20
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
+ **/
30
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
+ **/
56
int (*push_refs)(struct transport *transport, struct ref *refs, int flags);
57
int (*push)(struct transport *connection, int refspec_nr, const char **refspec, int flags);
58
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
+ **/
63
int (*disconnect)(struct transport *connection);
64
char *pack_lockfile;
65
signed verbose : 2;
@@ -74,7 +111,7 @@ int transport_push(struct transport *connection,
111
112
const struct ref *transport_get_remote_refs(struct transport *transport);
113
77
-int transport_fetch_refs(struct transport *transport, const struct ref *refs);
114
+int transport_fetch_refs(struct transport *transport, struct ref *refs);
115
void transport_unlock_pack(struct transport *transport);
116
int transport_disconnect(struct transport *transport);
117
char *transport_anonymize_url(const char *url);