Jonathan Tan | 88e2f9e | 2017-12-05 16:58:49 +0000 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "packfile.h" |
| 3 | #include "pkt-line.h" |
| 4 | #include "strbuf.h" |
| 5 | #include "transport.h" |
| 6 | #include "fetch-object.h" |
| 7 | |
Jonathan Tan | c0c578b | 2017-12-08 15:58:47 +0000 | [diff] [blame] | 8 | static void fetch_refs(const char *remote_name, struct ref *ref) |
Jonathan Tan | 88e2f9e | 2017-12-05 16:58:49 +0000 | [diff] [blame] | 9 | { |
| 10 | struct remote *remote; |
| 11 | struct transport *transport; |
Jonathan Tan | 8b4c010 | 2017-12-08 15:27:14 +0000 | [diff] [blame] | 12 | int original_fetch_if_missing = fetch_if_missing; |
Jonathan Tan | 88e2f9e | 2017-12-05 16:58:49 +0000 | [diff] [blame] | 13 | |
Jonathan Tan | 8b4c010 | 2017-12-08 15:27:14 +0000 | [diff] [blame] | 14 | fetch_if_missing = 0; |
Jonathan Tan | 88e2f9e | 2017-12-05 16:58:49 +0000 | [diff] [blame] | 15 | remote = remote_get(remote_name); |
| 16 | if (!remote->url[0]) |
| 17 | die(_("Remote with no URL")); |
| 18 | transport = transport_get(remote, remote->url[0]); |
| 19 | |
Jonathan Tan | 88e2f9e | 2017-12-05 16:58:49 +0000 | [diff] [blame] | 20 | transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1"); |
| 21 | transport_set_option(transport, TRANS_OPT_NO_DEPENDENTS, "1"); |
| 22 | transport_fetch_refs(transport, ref); |
Jonathan Tan | 8b4c010 | 2017-12-08 15:27:14 +0000 | [diff] [blame] | 23 | fetch_if_missing = original_fetch_if_missing; |
Jonathan Tan | 88e2f9e | 2017-12-05 16:58:49 +0000 | [diff] [blame] | 24 | } |
Jonathan Tan | c0c578b | 2017-12-08 15:58:47 +0000 | [diff] [blame] | 25 | |
| 26 | void fetch_object(const char *remote_name, const unsigned char *sha1) |
| 27 | { |
| 28 | struct ref *ref = alloc_ref(sha1_to_hex(sha1)); |
| 29 | hashcpy(ref->old_oid.hash, sha1); |
| 30 | fetch_refs(remote_name, ref); |
| 31 | } |
| 32 | |
| 33 | void fetch_objects(const char *remote_name, const struct oid_array *to_fetch) |
| 34 | { |
| 35 | struct ref *ref = NULL; |
| 36 | int i; |
| 37 | |
| 38 | for (i = 0; i < to_fetch->nr; i++) { |
| 39 | struct ref *new_ref = alloc_ref(oid_to_hex(&to_fetch->oid[i])); |
| 40 | oidcpy(&new_ref->old_oid, &to_fetch->oid[i]); |
| 41 | new_ref->next = ref; |
| 42 | ref = new_ref; |
| 43 | } |
| 44 | fetch_refs(remote_name, ref); |
| 45 | } |