Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 1 | #include "cache.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 2 | #include "config.h" |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 3 | #include "refs.h" |
| 4 | #include "pkt-line.h" |
Junio C Hamano | 958c24b | 2006-09-10 03:20:24 -0700 | [diff] [blame] | 5 | #include "sideband.h" |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 6 | #include "repository.h" |
Stefan Beller | cbd53a2 | 2018-05-15 16:42:15 -0700 | [diff] [blame] | 7 | #include "object-store.h" |
Junio C Hamano | f6b42a8 | 2005-10-13 18:57:40 -0700 | [diff] [blame] | 8 | #include "tag.h" |
| 9 | #include "object.h" |
Johannes Schindelin | f0243f2 | 2005-10-28 04:48:32 +0200 | [diff] [blame] | 10 | #include "commit.h" |
Johannes Schindelin | 9b8dc26 | 2006-10-30 20:08:43 +0100 | [diff] [blame] | 11 | #include "diff.h" |
| 12 | #include "revision.h" |
| 13 | #include "list-objects.h" |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 14 | #include "list-objects-filter.h" |
| 15 | #include "list-objects-filter-options.h" |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 16 | #include "run-command.h" |
Junio C Hamano | 47a5918 | 2013-07-08 13:56:53 -0700 | [diff] [blame] | 17 | #include "connect.h" |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 18 | #include "sigchain.h" |
Jeff King | ff5effd | 2012-08-03 12:19:16 -0400 | [diff] [blame] | 19 | #include "version.h" |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 20 | #include "string-list.h" |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 21 | #include "argv-array.h" |
Jeff King | 5411b10 | 2016-10-11 17:20:16 -0400 | [diff] [blame] | 22 | #include "prio-queue.h" |
Brandon Williams | aa9bab2 | 2017-10-16 10:55:26 -0700 | [diff] [blame] | 23 | #include "protocol.h" |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 24 | #include "quote.h" |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 25 | #include "upload-pack.h" |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 26 | #include "serve.h" |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 27 | |
Nguyễn Thái Ngọc Duy | 208acbf | 2014-03-25 20:23:26 +0700 | [diff] [blame] | 28 | /* Remember to update object flag allocation in object.h */ |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 29 | #define THEY_HAVE (1u << 11) |
| 30 | #define OUR_REF (1u << 12) |
| 31 | #define WANTED (1u << 13) |
| 32 | #define COMMON_KNOWN (1u << 14) |
| 33 | #define REACHABLE (1u << 15) |
| 34 | |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 35 | #define SHALLOW (1u << 16) |
| 36 | #define NOT_SHALLOW (1u << 17) |
| 37 | #define CLIENT_SHALLOW (1u << 18) |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 38 | #define HIDDEN_REF (1u << 19) |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 39 | |
Johannes Schindelin | dddbad7 | 2017-04-26 21:29:31 +0200 | [diff] [blame] | 40 | static timestamp_t oldest_have; |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 41 | |
Nguyễn Thái Ngọc Duy | cccf74e | 2016-06-12 17:54:09 +0700 | [diff] [blame] | 42 | static int deepen_relative; |
Junio C Hamano | 3f1da57 | 2013-01-28 20:45:43 -0800 | [diff] [blame] | 43 | static int multi_ack; |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 44 | static int no_done; |
Shawn O. Pearce | 348e390 | 2008-03-03 22:27:33 -0500 | [diff] [blame] | 45 | static int use_thin_pack, use_ofs_delta, use_include_tag; |
Johannes Sixt | 9462e3f | 2009-06-16 20:41:16 +0200 | [diff] [blame] | 46 | static int no_progress, daemon_mode; |
Fredrik Medley | 7199c09 | 2015-05-21 22:23:38 +0200 | [diff] [blame] | 47 | /* Allow specifying sha1 if it is a ref tip. */ |
| 48 | #define ALLOW_TIP_SHA1 01 |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 49 | /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */ |
| 50 | #define ALLOW_REACHABLE_SHA1 02 |
David Turner | f8edeaa | 2016-11-11 12:23:48 -0500 | [diff] [blame] | 51 | /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ |
| 52 | #define ALLOW_ANY_SHA1 07 |
Fredrik Medley | 7199c09 | 2015-05-21 22:23:38 +0200 | [diff] [blame] | 53 | static unsigned int allow_unadvertised_object_request; |
Nick Edelen | f0cea83 | 2009-06-10 01:50:18 +0200 | [diff] [blame] | 54 | static int shallow_nr; |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 55 | static struct object_array have_obj; |
| 56 | static struct object_array want_obj; |
Nicolas Pitre | 6523078 | 2009-09-03 19:08:33 -0400 | [diff] [blame] | 57 | static struct object_array extra_edge_obj; |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 58 | static unsigned int timeout; |
Jeff King | 115dedd | 2013-09-08 05:02:06 -0400 | [diff] [blame] | 59 | static int keepalive = 5; |
Junio C Hamano | d47f3db | 2006-09-10 16:27:08 -0700 | [diff] [blame] | 60 | /* 0 for no sideband, |
| 61 | * otherwise maximum packet size (up to 65520 bytes). |
| 62 | */ |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 63 | static int use_sideband; |
Shawn O. Pearce | 42526b4 | 2009-10-30 17:47:33 -0700 | [diff] [blame] | 64 | static int stateless_rpc; |
Jeff King | 20b20a2 | 2016-05-18 18:45:37 -0400 | [diff] [blame] | 65 | static const char *pack_objects_hook; |
H. Peter Anvin | 960decc | 2005-10-19 14:27:01 -0700 | [diff] [blame] | 66 | |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 67 | static int filter_capability_requested; |
Jonathan Nieder | c7620bd | 2018-03-28 13:33:03 -0700 | [diff] [blame] | 68 | static int allow_filter; |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 69 | static int allow_ref_in_want; |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 70 | static struct list_objects_filter_options filter_options; |
| 71 | |
H. Peter Anvin | 960decc | 2005-10-19 14:27:01 -0700 | [diff] [blame] | 72 | static void reset_timeout(void) |
| 73 | { |
| 74 | alarm(timeout); |
| 75 | } |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 76 | |
Lukas Fleischer | fcf0fe9 | 2016-06-14 16:49:17 +0200 | [diff] [blame] | 77 | static void send_client_data(int fd, const char *data, ssize_t sz) |
Junio C Hamano | 583b7ea | 2006-06-21 00:30:21 -0700 | [diff] [blame] | 78 | { |
Lukas Fleischer | 4c4b7d1 | 2016-06-14 16:49:16 +0200 | [diff] [blame] | 79 | if (use_sideband) { |
| 80 | send_sideband(1, fd, data, sz, use_sideband); |
Lukas Fleischer | fcf0fe9 | 2016-06-14 16:49:17 +0200 | [diff] [blame] | 81 | return; |
Lukas Fleischer | 4c4b7d1 | 2016-06-14 16:49:16 +0200 | [diff] [blame] | 82 | } |
Junio C Hamano | 958c24b | 2006-09-10 03:20:24 -0700 | [diff] [blame] | 83 | if (fd == 3) |
| 84 | /* emergency quit */ |
| 85 | fd = 2; |
| 86 | if (fd == 2) { |
Andy Whitcroft | 93822c2 | 2007-01-08 15:58:23 +0000 | [diff] [blame] | 87 | /* XXX: are we happy to lose stuff here? */ |
Junio C Hamano | 958c24b | 2006-09-10 03:20:24 -0700 | [diff] [blame] | 88 | xwrite(fd, data, sz); |
Lukas Fleischer | fcf0fe9 | 2016-06-14 16:49:17 +0200 | [diff] [blame] | 89 | return; |
Junio C Hamano | 583b7ea | 2006-06-21 00:30:21 -0700 | [diff] [blame] | 90 | } |
Jeff King | cdf4fb8 | 2013-02-20 15:01:56 -0500 | [diff] [blame] | 91 | write_or_die(fd, data, sz); |
Junio C Hamano | 583b7ea | 2006-06-21 00:30:21 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nguyễn Thái Ngọc Duy | b790e0f | 2014-03-11 19:59:46 +0700 | [diff] [blame] | 94 | static int write_one_shallow(const struct commit_graft *graft, void *cb_data) |
| 95 | { |
| 96 | FILE *fp = cb_data; |
| 97 | if (graft->nr_parent == -1) |
brian m. carlson | 7683e2e | 2015-03-13 23:39:34 +0000 | [diff] [blame] | 98 | fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid)); |
Nguyễn Thái Ngọc Duy | b790e0f | 2014-03-11 19:59:46 +0700 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 102 | static void create_pack_file(void) |
| 103 | { |
René Scharfe | d318027 | 2014-08-19 21:09:35 +0200 | [diff] [blame] | 104 | struct child_process pack_objects = CHILD_PROCESS_INIT; |
Junio C Hamano | 363b781 | 2006-06-20 22:48:23 -0700 | [diff] [blame] | 105 | char data[8193], progress[128]; |
Junio C Hamano | 583b7ea | 2006-06-21 00:30:21 -0700 | [diff] [blame] | 106 | char abort_msg[] = "aborting due to possible repository " |
| 107 | "corruption on the remote side."; |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 108 | int buffered = -1; |
Junio C Hamano | 1456b04 | 2009-12-10 12:17:11 -0800 | [diff] [blame] | 109 | ssize_t sz; |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 110 | int i; |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 111 | FILE *pipe_fd; |
Linus Torvalds | 75bfc6c | 2005-07-04 16:35:13 -0700 | [diff] [blame] | 112 | |
Jeff King | 20b20a2 | 2016-05-18 18:45:37 -0400 | [diff] [blame] | 113 | if (!pack_objects_hook) |
| 114 | pack_objects.git_cmd = 1; |
| 115 | else { |
| 116 | argv_array_push(&pack_objects.args, pack_objects_hook); |
| 117 | argv_array_push(&pack_objects.args, "git"); |
| 118 | pack_objects.use_shell = 1; |
| 119 | } |
| 120 | |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 121 | if (shallow_nr) { |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 122 | argv_array_push(&pack_objects.args, "--shallow-file"); |
| 123 | argv_array_push(&pack_objects.args, ""); |
Nick Edelen | f0cea83 | 2009-06-10 01:50:18 +0200 | [diff] [blame] | 124 | } |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 125 | argv_array_push(&pack_objects.args, "pack-objects"); |
| 126 | argv_array_push(&pack_objects.args, "--revs"); |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 127 | if (use_thin_pack) |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 128 | argv_array_push(&pack_objects.args, "--thin"); |
Linus Torvalds | 75bfc6c | 2005-07-04 16:35:13 -0700 | [diff] [blame] | 129 | |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 130 | argv_array_push(&pack_objects.args, "--stdout"); |
brian m. carlson | 2dacf26 | 2014-12-24 23:05:40 +0000 | [diff] [blame] | 131 | if (shallow_nr) |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 132 | argv_array_push(&pack_objects.args, "--shallow"); |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 133 | if (!no_progress) |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 134 | argv_array_push(&pack_objects.args, "--progress"); |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 135 | if (use_ofs_delta) |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 136 | argv_array_push(&pack_objects.args, "--delta-base-offset"); |
Shawn O. Pearce | 348e390 | 2008-03-03 22:27:33 -0500 | [diff] [blame] | 137 | if (use_include_tag) |
Michael Procter | 65a3629 | 2016-02-25 12:13:26 +0000 | [diff] [blame] | 138 | argv_array_push(&pack_objects.args, "--include-tag"); |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 139 | if (filter_options.filter_spec) { |
Jonathan Tan | 0b6069f | 2017-12-08 15:58:42 +0000 | [diff] [blame] | 140 | if (pack_objects.use_shell) { |
| 141 | struct strbuf buf = STRBUF_INIT; |
| 142 | sq_quote_buf(&buf, filter_options.filter_spec); |
| 143 | argv_array_pushf(&pack_objects.args, "--filter=%s", buf.buf); |
| 144 | strbuf_release(&buf); |
| 145 | } else { |
| 146 | argv_array_pushf(&pack_objects.args, "--filter=%s", |
| 147 | filter_options.filter_spec); |
| 148 | } |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 149 | } |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 150 | |
Jeff King | b961219 | 2011-04-06 17:33:33 -0400 | [diff] [blame] | 151 | pack_objects.in = -1; |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 152 | pack_objects.out = -1; |
| 153 | pack_objects.err = -1; |
Johannes Sixt | 21edd3f | 2007-10-19 21:48:03 +0200 | [diff] [blame] | 154 | |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 155 | if (start_command(&pack_objects)) |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 156 | die("git upload-pack: unable to fork git-pack-objects"); |
Johannes Schindelin | 83a5ad6 | 2007-02-20 03:01:44 +0100 | [diff] [blame] | 157 | |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 158 | pipe_fd = xfdopen(pack_objects.in, "w"); |
Nick Edelen | f0cea83 | 2009-06-10 01:50:18 +0200 | [diff] [blame] | 159 | |
Nguyễn Thái Ngọc Duy | b790e0f | 2014-03-11 19:59:46 +0700 | [diff] [blame] | 160 | if (shallow_nr) |
| 161 | for_each_commit_graft(write_one_shallow, pipe_fd); |
| 162 | |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 163 | for (i = 0; i < want_obj.nr; i++) |
| 164 | fprintf(pipe_fd, "%s\n", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 165 | oid_to_hex(&want_obj.objects[i].item->oid)); |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 166 | fprintf(pipe_fd, "--not\n"); |
| 167 | for (i = 0; i < have_obj.nr; i++) |
| 168 | fprintf(pipe_fd, "%s\n", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 169 | oid_to_hex(&have_obj.objects[i].item->oid)); |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 170 | for (i = 0; i < extra_edge_obj.nr; i++) |
| 171 | fprintf(pipe_fd, "%s\n", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 172 | oid_to_hex(&extra_edge_obj.objects[i].item->oid)); |
Nguyễn Thái Ngọc Duy | cdab485 | 2013-08-16 16:52:05 +0700 | [diff] [blame] | 173 | fprintf(pipe_fd, "\n"); |
| 174 | fflush(pipe_fd); |
| 175 | fclose(pipe_fd); |
Nick Edelen | f0cea83 | 2009-06-10 01:50:18 +0200 | [diff] [blame] | 176 | |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 177 | /* We read from pack_objects.err to capture stderr output for |
| 178 | * progress bar, and pack_objects.out to capture the pack data. |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 179 | */ |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 180 | |
| 181 | while (1) { |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 182 | struct pollfd pfd[2]; |
Junio C Hamano | 363b781 | 2006-06-20 22:48:23 -0700 | [diff] [blame] | 183 | int pe, pu, pollsize; |
Jeff King | 05e9515 | 2013-09-08 05:01:31 -0400 | [diff] [blame] | 184 | int ret; |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 185 | |
Matthias Lederhofer | 0d516ad | 2006-07-18 19:14:51 +0200 | [diff] [blame] | 186 | reset_timeout(); |
| 187 | |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 188 | pollsize = 0; |
Junio C Hamano | 363b781 | 2006-06-20 22:48:23 -0700 | [diff] [blame] | 189 | pe = pu = -1; |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 190 | |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 191 | if (0 <= pack_objects.out) { |
| 192 | pfd[pollsize].fd = pack_objects.out; |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 193 | pfd[pollsize].events = POLLIN; |
| 194 | pu = pollsize; |
| 195 | pollsize++; |
| 196 | } |
Johannes Sixt | cc41fa8 | 2007-10-19 21:47:59 +0200 | [diff] [blame] | 197 | if (0 <= pack_objects.err) { |
| 198 | pfd[pollsize].fd = pack_objects.err; |
Junio C Hamano | 363b781 | 2006-06-20 22:48:23 -0700 | [diff] [blame] | 199 | pfd[pollsize].events = POLLIN; |
| 200 | pe = pollsize; |
| 201 | pollsize++; |
| 202 | } |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 203 | |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 204 | if (!pollsize) |
| 205 | break; |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 206 | |
Edward Thomson | 6c71f8b | 2014-08-22 15:19:11 +0000 | [diff] [blame] | 207 | ret = poll(pfd, pollsize, |
| 208 | keepalive < 0 ? -1 : 1000 * keepalive); |
| 209 | |
Jeff King | 05e9515 | 2013-09-08 05:01:31 -0400 | [diff] [blame] | 210 | if (ret < 0) { |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 211 | if (errno != EINTR) { |
Nguyễn Thái Ngọc Duy | d2b6afa | 2016-05-08 16:47:59 +0700 | [diff] [blame] | 212 | error_errno("poll failed, resuming"); |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 213 | sleep(1); |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 214 | } |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 215 | continue; |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 216 | } |
Nicolas Pitre | 6b59f51 | 2009-11-11 17:24:42 -0500 | [diff] [blame] | 217 | if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) { |
| 218 | /* Status ready; we ship that in the side-band |
| 219 | * or dump to the standard error. |
| 220 | */ |
| 221 | sz = xread(pack_objects.err, progress, |
| 222 | sizeof(progress)); |
| 223 | if (0 < sz) |
| 224 | send_client_data(2, progress, sz); |
| 225 | else if (sz == 0) { |
| 226 | close(pack_objects.err); |
| 227 | pack_objects.err = -1; |
| 228 | } |
| 229 | else |
| 230 | goto fail; |
| 231 | /* give priority to status messages */ |
| 232 | continue; |
| 233 | } |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 234 | if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) { |
| 235 | /* Data ready; we keep the last byte to ourselves |
| 236 | * in case we detect broken rev-list, so that we |
| 237 | * can leave the stream corrupted. This is |
| 238 | * unfortunate -- unpack-objects would happily |
| 239 | * accept a valid packdata with trailing garbage, |
| 240 | * so appending garbage after we pass all the |
| 241 | * pack data is not good enough to signal |
| 242 | * breakage to downstream. |
| 243 | */ |
| 244 | char *cp = data; |
| 245 | ssize_t outsz = 0; |
| 246 | if (0 <= buffered) { |
| 247 | *cp++ = buffered; |
| 248 | outsz++; |
| 249 | } |
| 250 | sz = xread(pack_objects.out, cp, |
| 251 | sizeof(data) - outsz); |
| 252 | if (0 < sz) |
Junio C Hamano | 1456b04 | 2009-12-10 12:17:11 -0800 | [diff] [blame] | 253 | ; |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 254 | else if (sz == 0) { |
| 255 | close(pack_objects.out); |
| 256 | pack_objects.out = -1; |
| 257 | } |
| 258 | else |
| 259 | goto fail; |
| 260 | sz += outsz; |
| 261 | if (1 < sz) { |
| 262 | buffered = data[sz-1] & 0xFF; |
| 263 | sz--; |
| 264 | } |
| 265 | else |
| 266 | buffered = -1; |
Lukas Fleischer | fcf0fe9 | 2016-06-14 16:49:17 +0200 | [diff] [blame] | 267 | send_client_data(1, data, sz); |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 268 | } |
Jeff King | 05e9515 | 2013-09-08 05:01:31 -0400 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * We hit the keepalive timeout without saying anything; send |
| 272 | * an empty message on the data sideband just to let the other |
| 273 | * side know we're still working on it, but don't have any data |
| 274 | * yet. |
| 275 | * |
| 276 | * If we don't have a sideband channel, there's no room in the |
| 277 | * protocol to say anything, so those clients are just out of |
| 278 | * luck. |
| 279 | */ |
| 280 | if (!ret && use_sideband) { |
| 281 | static const char buf[] = "0005\1"; |
| 282 | write_or_die(1, buf, 5); |
| 283 | } |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 284 | } |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 285 | |
| 286 | if (finish_command(&pack_objects)) { |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 287 | error("git upload-pack: git-pack-objects died with error."); |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 288 | goto fail; |
| 289 | } |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 290 | |
| 291 | /* flush the data */ |
| 292 | if (0 <= buffered) { |
| 293 | data[0] = buffered; |
Lukas Fleischer | fcf0fe9 | 2016-06-14 16:49:17 +0200 | [diff] [blame] | 294 | send_client_data(1, data, 1); |
Johannes Sixt | 4c324c0 | 2007-11-04 20:46:48 +0100 | [diff] [blame] | 295 | fprintf(stderr, "flushed.\n"); |
| 296 | } |
| 297 | if (use_sideband) |
| 298 | packet_flush(1); |
| 299 | return; |
| 300 | |
Junio C Hamano | b1c71b7 | 2006-06-20 18:26:34 -0700 | [diff] [blame] | 301 | fail: |
Junio C Hamano | 583b7ea | 2006-06-21 00:30:21 -0700 | [diff] [blame] | 302 | send_client_data(3, abort_msg, sizeof(abort_msg)); |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 303 | die("git upload-pack: %s", abort_msg); |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 304 | } |
| 305 | |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 306 | static int got_oid(const char *hex, struct object_id *oid) |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 307 | { |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 308 | struct object *o; |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 309 | int we_knew_they_have = 0; |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 310 | |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 311 | if (get_oid_hex(hex, oid)) |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 312 | die("git upload-pack: expected SHA1 object, got '%s'", hex); |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 313 | if (!has_object_file(oid)) |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 314 | return -1; |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 315 | |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 316 | o = parse_object(the_repository, oid); |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 317 | if (!o) |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 318 | die("oops (%s)", oid_to_hex(oid)); |
Junio C Hamano | 182a8da | 2006-08-12 22:16:51 -0700 | [diff] [blame] | 319 | if (o->type == OBJ_COMMIT) { |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 320 | struct commit_list *parents; |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 321 | struct commit *commit = (struct commit *)o; |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 322 | if (o->flags & THEY_HAVE) |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 323 | we_knew_they_have = 1; |
| 324 | else |
| 325 | o->flags |= THEY_HAVE; |
| 326 | if (!oldest_have || (commit->date < oldest_have)) |
| 327 | oldest_have = commit->date; |
| 328 | for (parents = commit->parents; |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 329 | parents; |
| 330 | parents = parents->next) |
| 331 | parents->item->object.flags |= THEY_HAVE; |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 332 | } |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 333 | if (!we_knew_they_have) { |
| 334 | add_object_array(o, NULL, &have_obj); |
| 335 | return 1; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int reachable(struct commit *want) |
| 341 | { |
Jeff King | 5411b10 | 2016-10-11 17:20:16 -0400 | [diff] [blame] | 342 | struct prio_queue work = { compare_commits_by_commit_date }; |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 343 | |
Jeff King | 5411b10 | 2016-10-11 17:20:16 -0400 | [diff] [blame] | 344 | prio_queue_put(&work, want); |
| 345 | while (work.nr) { |
René Scharfe | e510ab8 | 2015-10-24 18:21:31 +0200 | [diff] [blame] | 346 | struct commit_list *list; |
Jeff King | 5411b10 | 2016-10-11 17:20:16 -0400 | [diff] [blame] | 347 | struct commit *commit = prio_queue_get(&work); |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 348 | |
| 349 | if (commit->object.flags & THEY_HAVE) { |
| 350 | want->object.flags |= COMMON_KNOWN; |
| 351 | break; |
| 352 | } |
| 353 | if (!commit->object.parsed) |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 354 | parse_object(the_repository, &commit->object.oid); |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 355 | if (commit->object.flags & REACHABLE) |
| 356 | continue; |
| 357 | commit->object.flags |= REACHABLE; |
| 358 | if (commit->date < oldest_have) |
| 359 | continue; |
| 360 | for (list = commit->parents; list; list = list->next) { |
| 361 | struct commit *parent = list->item; |
| 362 | if (!(parent->object.flags & REACHABLE)) |
Jeff King | 5411b10 | 2016-10-11 17:20:16 -0400 | [diff] [blame] | 363 | prio_queue_put(&work, parent); |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | want->object.flags |= REACHABLE; |
| 367 | clear_commit_marks(want, REACHABLE); |
Jeff King | 5411b10 | 2016-10-11 17:20:16 -0400 | [diff] [blame] | 368 | clear_prio_queue(&work); |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 369 | return (want->object.flags & COMMON_KNOWN); |
| 370 | } |
| 371 | |
| 372 | static int ok_to_give_up(void) |
| 373 | { |
| 374 | int i; |
| 375 | |
| 376 | if (!have_obj.nr) |
| 377 | return 0; |
| 378 | |
| 379 | for (i = 0; i < want_obj.nr; i++) { |
| 380 | struct object *want = want_obj.objects[i].item; |
| 381 | |
| 382 | if (want->flags & COMMON_KNOWN) |
| 383 | continue; |
Stefan Beller | a74093d | 2018-06-28 18:22:05 -0700 | [diff] [blame] | 384 | want = deref_tag(the_repository, want, "a want line", 0); |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 385 | if (!want || want->type != OBJ_COMMIT) { |
| 386 | /* no way to tell if this is reachable by |
| 387 | * looking at the ancestry chain alone, so |
| 388 | * leave a note to ourselves not to worry about |
| 389 | * this object anymore. |
| 390 | */ |
| 391 | want_obj.objects[i].item->flags |= COMMON_KNOWN; |
| 392 | continue; |
| 393 | } |
| 394 | if (!reachable((struct commit *)want)) |
| 395 | return 0; |
| 396 | } |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 397 | return 1; |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static int get_common_commits(void) |
| 401 | { |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 402 | struct object_id oid; |
| 403 | char last_hex[GIT_MAX_HEXSZ + 1]; |
Shawn O. Pearce | 49bee71 | 2011-03-14 16:48:39 -0700 | [diff] [blame] | 404 | int got_common = 0; |
| 405 | int got_other = 0; |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 406 | int sent_ready = 0; |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 407 | |
Johannes Schindelin | f0243f2 | 2005-10-28 04:48:32 +0200 | [diff] [blame] | 408 | save_commit_buffer = 0; |
| 409 | |
Brian Gianforcaro | eeefa7c | 2009-09-01 01:35:10 -0400 | [diff] [blame] | 410 | for (;;) { |
Jeff King | 74543a0 | 2013-02-20 15:02:57 -0500 | [diff] [blame] | 411 | char *line = packet_read_line(0, NULL); |
Nguyễn Thái Ngọc Duy | 8bf3b75 | 2016-06-12 17:53:49 +0700 | [diff] [blame] | 412 | const char *arg; |
| 413 | |
H. Peter Anvin | 960decc | 2005-10-19 14:27:01 -0700 | [diff] [blame] | 414 | reset_timeout(); |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 415 | |
Jeff King | 74543a0 | 2013-02-20 15:02:57 -0500 | [diff] [blame] | 416 | if (!line) { |
Shawn O. Pearce | 49bee71 | 2011-03-14 16:48:39 -0700 | [diff] [blame] | 417 | if (multi_ack == 2 && got_common |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 418 | && !got_other && ok_to_give_up()) { |
| 419 | sent_ready = 1; |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 420 | packet_write_fmt(1, "ACK %s ready\n", last_hex); |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 421 | } |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 422 | if (have_obj.nr == 0 || multi_ack) |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 423 | packet_write_fmt(1, "NAK\n"); |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 424 | |
| 425 | if (no_done && sent_ready) { |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 426 | packet_write_fmt(1, "ACK %s\n", last_hex); |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 427 | return 0; |
| 428 | } |
Shawn O. Pearce | 42526b4 | 2009-10-30 17:47:33 -0700 | [diff] [blame] | 429 | if (stateless_rpc) |
| 430 | exit(0); |
Shawn O. Pearce | 49bee71 | 2011-03-14 16:48:39 -0700 | [diff] [blame] | 431 | got_common = 0; |
| 432 | got_other = 0; |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 433 | continue; |
| 434 | } |
Nguyễn Thái Ngọc Duy | 8bf3b75 | 2016-06-12 17:53:49 +0700 | [diff] [blame] | 435 | if (skip_prefix(line, "have ", &arg)) { |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 436 | switch (got_oid(arg, &oid)) { |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 437 | case -1: /* they have what we do not */ |
Shawn O. Pearce | 49bee71 | 2011-03-14 16:48:39 -0700 | [diff] [blame] | 438 | got_other = 1; |
Shawn O. Pearce | 78affc4 | 2009-10-30 17:47:25 -0700 | [diff] [blame] | 439 | if (multi_ack && ok_to_give_up()) { |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 440 | const char *hex = oid_to_hex(&oid); |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 441 | if (multi_ack == 2) { |
| 442 | sent_ready = 1; |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 443 | packet_write_fmt(1, "ACK %s ready\n", hex); |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 444 | } else |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 445 | packet_write_fmt(1, "ACK %s continue\n", hex); |
Shawn O. Pearce | 78affc4 | 2009-10-30 17:47:25 -0700 | [diff] [blame] | 446 | } |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 447 | break; |
| 448 | default: |
Shawn O. Pearce | 49bee71 | 2011-03-14 16:48:39 -0700 | [diff] [blame] | 449 | got_common = 1; |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 450 | oid_to_hex_r(last_hex, &oid); |
Shawn O. Pearce | 78affc4 | 2009-10-30 17:47:25 -0700 | [diff] [blame] | 451 | if (multi_ack == 2) |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 452 | packet_write_fmt(1, "ACK %s common\n", last_hex); |
Shawn O. Pearce | 78affc4 | 2009-10-30 17:47:25 -0700 | [diff] [blame] | 453 | else if (multi_ack) |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 454 | packet_write_fmt(1, "ACK %s continue\n", last_hex); |
Junio C Hamano | c04c4e5 | 2006-07-05 18:12:12 -0700 | [diff] [blame] | 455 | else if (have_obj.nr == 1) |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 456 | packet_write_fmt(1, "ACK %s\n", last_hex); |
Junio C Hamano | 937a515 | 2006-07-05 21:28:20 -0700 | [diff] [blame] | 457 | break; |
Junio C Hamano | af2d3aa | 2005-10-25 14:55:24 -0700 | [diff] [blame] | 458 | } |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 459 | continue; |
| 460 | } |
| 461 | if (!strcmp(line, "done")) { |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 462 | if (have_obj.nr > 0) { |
Johannes Schindelin | 1bd8c8f | 2005-10-28 04:49:16 +0200 | [diff] [blame] | 463 | if (multi_ack) |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 464 | packet_write_fmt(1, "ACK %s\n", last_hex); |
Johannes Schindelin | 1bd8c8f | 2005-10-28 04:49:16 +0200 | [diff] [blame] | 465 | return 0; |
| 466 | } |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 467 | packet_write_fmt(1, "NAK\n"); |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 468 | return -1; |
| 469 | } |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 470 | die("git upload-pack: expected SHA1 list, got '%s'", line); |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 471 | } |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 474 | static int is_our_ref(struct object *o) |
| 475 | { |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 476 | int allow_hidden_ref = (allow_unadvertised_object_request & |
| 477 | (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); |
Fredrik Medley | 7199c09 | 2015-05-21 22:23:38 +0200 | [diff] [blame] | 478 | return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF); |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 479 | } |
| 480 | |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 481 | /* |
| 482 | * on successful case, it's up to the caller to close cmd->out |
| 483 | */ |
| 484 | static int do_reachable_revlist(struct child_process *cmd, |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 485 | struct object_array *src, |
| 486 | struct object_array *reachable) |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 487 | { |
| 488 | static const char *argv[] = { |
| 489 | "rev-list", "--stdin", NULL, |
| 490 | }; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 491 | struct object *o; |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 492 | char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 493 | int i; |
| 494 | |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 495 | cmd->argv = argv; |
| 496 | cmd->git_cmd = 1; |
| 497 | cmd->no_stderr = 1; |
| 498 | cmd->in = -1; |
| 499 | cmd->out = -1; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 500 | |
| 501 | /* |
Nguyễn Thái Ngọc Duy | 7fcbd37 | 2016-06-12 17:53:51 +0700 | [diff] [blame] | 502 | * If the next rev-list --stdin encounters an unknown commit, |
| 503 | * it terminates, which will cause SIGPIPE in the write loop |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 504 | * below. |
| 505 | */ |
| 506 | sigchain_push(SIGPIPE, SIG_IGN); |
| 507 | |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 508 | if (start_command(cmd)) |
Nguyễn Thái Ngọc Duy | 7fcbd37 | 2016-06-12 17:53:51 +0700 | [diff] [blame] | 509 | goto error; |
| 510 | |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 511 | namebuf[0] = '^'; |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 512 | namebuf[GIT_SHA1_HEXSZ + 1] = '\n'; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 513 | for (i = get_max_object_index(); 0 < i; ) { |
| 514 | o = get_indexed_object(--i); |
Brian Harring | 2a74532 | 2011-08-23 22:47:17 -0700 | [diff] [blame] | 515 | if (!o) |
| 516 | continue; |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 517 | if (reachable && o->type == OBJ_COMMIT) |
| 518 | o->flags &= ~TMP_MARK; |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 519 | if (!is_our_ref(o)) |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 520 | continue; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 521 | memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ); |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 522 | if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0) |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 523 | goto error; |
| 524 | } |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 525 | namebuf[GIT_SHA1_HEXSZ] = '\n'; |
Nguyễn Thái Ngọc Duy | 3f0f662 | 2016-06-12 17:53:52 +0700 | [diff] [blame] | 526 | for (i = 0; i < src->nr; i++) { |
| 527 | o = src->objects[i].item; |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 528 | if (is_our_ref(o)) { |
| 529 | if (reachable) |
| 530 | add_object_array(o, NULL, reachable); |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 531 | continue; |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 532 | } |
| 533 | if (reachable && o->type == OBJ_COMMIT) |
| 534 | o->flags |= TMP_MARK; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 535 | memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ); |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 536 | if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0) |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 537 | goto error; |
| 538 | } |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 539 | close(cmd->in); |
| 540 | cmd->in = -1; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 541 | sigchain_pop(SIGPIPE); |
| 542 | |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 543 | return 0; |
| 544 | |
| 545 | error: |
| 546 | sigchain_pop(SIGPIPE); |
| 547 | |
| 548 | if (cmd->in >= 0) |
| 549 | close(cmd->in); |
| 550 | if (cmd->out >= 0) |
| 551 | close(cmd->out); |
| 552 | return -1; |
| 553 | } |
| 554 | |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 555 | static int get_reachable_list(struct object_array *src, |
| 556 | struct object_array *reachable) |
| 557 | { |
| 558 | struct child_process cmd = CHILD_PROCESS_INIT; |
| 559 | int i; |
| 560 | struct object *o; |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 561 | char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ |
| 562 | const unsigned hexsz = the_hash_algo->hexsz; |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 563 | |
| 564 | if (do_reachable_revlist(&cmd, src, reachable) < 0) |
| 565 | return -1; |
| 566 | |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 567 | while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) { |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 568 | struct object_id sha1; |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 569 | const char *p; |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 570 | |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 571 | if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n') |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 572 | break; |
| 573 | |
Stefan Beller | 5abddd1 | 2018-06-28 18:21:52 -0700 | [diff] [blame] | 574 | o = lookup_object(the_repository, sha1.hash); |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 575 | if (o && o->type == OBJ_COMMIT) { |
| 576 | o->flags &= ~TMP_MARK; |
| 577 | } |
| 578 | } |
| 579 | for (i = get_max_object_index(); 0 < i; i--) { |
| 580 | o = get_indexed_object(i - 1); |
| 581 | if (o && o->type == OBJ_COMMIT && |
| 582 | (o->flags & TMP_MARK)) { |
| 583 | add_object_array(o, NULL, reachable); |
| 584 | o->flags &= ~TMP_MARK; |
| 585 | } |
| 586 | } |
| 587 | close(cmd.out); |
| 588 | |
| 589 | if (finish_command(&cmd)) |
| 590 | return -1; |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 595 | static int has_unreachable(struct object_array *src) |
| 596 | { |
| 597 | struct child_process cmd = CHILD_PROCESS_INIT; |
| 598 | char buf[1]; |
| 599 | int i; |
| 600 | |
Nguyễn Thái Ngọc Duy | 079aa97 | 2016-06-12 17:54:08 +0700 | [diff] [blame] | 601 | if (do_reachable_revlist(&cmd, src, NULL) < 0) |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 602 | return 1; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * The commits out of the rev-list are not ancestors of |
| 606 | * our ref. |
| 607 | */ |
Nguyễn Thái Ngọc Duy | 2997178 | 2016-06-12 17:54:07 +0700 | [diff] [blame] | 608 | i = read_in_full(cmd.out, buf, 1); |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 609 | if (i) |
| 610 | goto error; |
| 611 | close(cmd.out); |
Nguyễn Thái Ngọc Duy | 7fcbd37 | 2016-06-12 17:53:51 +0700 | [diff] [blame] | 612 | cmd.out = -1; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 613 | |
| 614 | /* |
| 615 | * rev-list may have died by encountering a bad commit |
| 616 | * in the history, in which case we do want to bail out |
| 617 | * even when it showed no commit. |
| 618 | */ |
| 619 | if (finish_command(&cmd)) |
| 620 | goto error; |
| 621 | |
| 622 | /* All the non-tip ones are ancestors of what we advertised */ |
Nguyễn Thái Ngọc Duy | 3f0f662 | 2016-06-12 17:53:52 +0700 | [diff] [blame] | 623 | return 0; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 624 | |
| 625 | error: |
Nguyễn Thái Ngọc Duy | 7fcbd37 | 2016-06-12 17:53:51 +0700 | [diff] [blame] | 626 | sigchain_pop(SIGPIPE); |
Nguyễn Thái Ngọc Duy | 7fcbd37 | 2016-06-12 17:53:51 +0700 | [diff] [blame] | 627 | if (cmd.out >= 0) |
| 628 | close(cmd.out); |
Nguyễn Thái Ngọc Duy | 3f0f662 | 2016-06-12 17:53:52 +0700 | [diff] [blame] | 629 | return 1; |
| 630 | } |
Nguyễn Thái Ngọc Duy | 7fcbd37 | 2016-06-12 17:53:51 +0700 | [diff] [blame] | 631 | |
Nguyễn Thái Ngọc Duy | 3f0f662 | 2016-06-12 17:53:52 +0700 | [diff] [blame] | 632 | static void check_non_tip(void) |
| 633 | { |
| 634 | int i; |
| 635 | |
| 636 | /* |
| 637 | * In the normal in-process case without |
| 638 | * uploadpack.allowReachableSHA1InWant, |
| 639 | * non-tip requests can never happen. |
| 640 | */ |
| 641 | if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1)) |
| 642 | goto error; |
| 643 | if (!has_unreachable(&want_obj)) |
| 644 | /* All the non-tip ones are ancestors of what we advertised */ |
| 645 | return; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 646 | |
| 647 | error: |
| 648 | /* Pick one of them (we know there at least is one) */ |
| 649 | for (i = 0; i < want_obj.nr; i++) { |
Nguyễn Thái Ngọc Duy | 3f0f662 | 2016-06-12 17:53:52 +0700 | [diff] [blame] | 650 | struct object *o = want_obj.objects[i].item; |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 651 | if (!is_our_ref(o)) |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 652 | die("git upload-pack: not our ref %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 653 | oid_to_hex(&o->oid)); |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
Nguyễn Thái Ngọc Duy | 5c24cde | 2016-06-12 17:53:46 +0700 | [diff] [blame] | 657 | static void send_shallow(struct commit_list *result) |
| 658 | { |
| 659 | while (result) { |
| 660 | struct object *object = &result->item->object; |
| 661 | if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) { |
Junio C Hamano | dbaa6bd | 2016-10-31 13:15:21 -0700 | [diff] [blame] | 662 | packet_write_fmt(1, "shallow %s", |
| 663 | oid_to_hex(&object->oid)); |
Stefan Beller | 19143f1 | 2018-05-17 15:51:44 -0700 | [diff] [blame] | 664 | register_shallow(the_repository, &object->oid); |
Nguyễn Thái Ngọc Duy | 5c24cde | 2016-06-12 17:53:46 +0700 | [diff] [blame] | 665 | shallow_nr++; |
| 666 | } |
| 667 | result = result->next; |
| 668 | } |
| 669 | } |
| 670 | |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 671 | static void send_unshallow(const struct object_array *shallows) |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 672 | { |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 673 | int i; |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 674 | |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 675 | for (i = 0; i < shallows->nr; i++) { |
| 676 | struct object *object = shallows->objects[i].item; |
| 677 | if (object->flags & NOT_SHALLOW) { |
| 678 | struct commit_list *parents; |
Junio C Hamano | dbaa6bd | 2016-10-31 13:15:21 -0700 | [diff] [blame] | 679 | packet_write_fmt(1, "unshallow %s", |
| 680 | oid_to_hex(&object->oid)); |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 681 | object->flags &= ~CLIENT_SHALLOW; |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 682 | /* |
| 683 | * We want to _register_ "object" as shallow, but we |
| 684 | * also need to traverse object's parents to deepen a |
| 685 | * shallow clone. Unregister it for now so we can |
| 686 | * parse and add the parents to the want list, then |
| 687 | * re-register it. |
| 688 | */ |
brian m. carlson | e92b848 | 2017-05-06 22:10:06 +0000 | [diff] [blame] | 689 | unregister_shallow(&object->oid); |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 690 | object->parsed = 0; |
| 691 | parse_commit_or_die((struct commit *)object); |
| 692 | parents = ((struct commit *)object)->parents; |
| 693 | while (parents) { |
| 694 | add_object_array(&parents->item->object, |
| 695 | NULL, &want_obj); |
| 696 | parents = parents->next; |
| 697 | } |
| 698 | add_object_array(object, NULL, &extra_edge_obj); |
| 699 | } |
| 700 | /* make sure commit traversal conforms to client */ |
Stefan Beller | 19143f1 | 2018-05-17 15:51:44 -0700 | [diff] [blame] | 701 | register_shallow(the_repository, &object->oid); |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 702 | } |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 703 | } |
| 704 | |
Nguyễn Thái Ngọc Duy | cccf74e | 2016-06-12 17:54:09 +0700 | [diff] [blame] | 705 | static void deepen(int depth, int deepen_relative, |
| 706 | struct object_array *shallows) |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 707 | { |
Stefan Beller | c881348 | 2018-05-17 15:51:46 -0700 | [diff] [blame] | 708 | if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) { |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 709 | int i; |
| 710 | |
| 711 | for (i = 0; i < shallows->nr; i++) { |
| 712 | struct object *object = shallows->objects[i].item; |
| 713 | object->flags |= NOT_SHALLOW; |
| 714 | } |
Nguyễn Thái Ngọc Duy | cccf74e | 2016-06-12 17:54:09 +0700 | [diff] [blame] | 715 | } else if (deepen_relative) { |
| 716 | struct object_array reachable_shallows = OBJECT_ARRAY_INIT; |
| 717 | struct commit_list *result; |
| 718 | |
| 719 | get_reachable_list(shallows, &reachable_shallows); |
| 720 | result = get_shallow_commits(&reachable_shallows, |
| 721 | depth + 1, |
| 722 | SHALLOW, NOT_SHALLOW); |
| 723 | send_shallow(result); |
| 724 | free_commit_list(result); |
| 725 | object_array_clear(&reachable_shallows); |
Nguyễn Thái Ngọc Duy | 873700c | 2016-06-12 17:53:48 +0700 | [diff] [blame] | 726 | } else { |
| 727 | struct commit_list *result; |
| 728 | |
| 729 | result = get_shallow_commits(&want_obj, depth, |
| 730 | SHALLOW, NOT_SHALLOW); |
| 731 | send_shallow(result); |
| 732 | free_commit_list(result); |
| 733 | } |
| 734 | |
| 735 | send_unshallow(shallows); |
Nguyễn Thái Ngọc Duy | e8e44de | 2016-06-12 17:53:45 +0700 | [diff] [blame] | 736 | } |
| 737 | |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 738 | static void deepen_by_rev_list(int ac, const char **av, |
| 739 | struct object_array *shallows) |
| 740 | { |
| 741 | struct commit_list *result; |
| 742 | |
| 743 | result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); |
| 744 | send_shallow(result); |
| 745 | free_commit_list(result); |
| 746 | send_unshallow(shallows); |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /* Returns 1 if a shallow list is sent or 0 otherwise */ |
| 750 | static int send_shallow_list(int depth, int deepen_rev_list, |
| 751 | timestamp_t deepen_since, |
| 752 | struct string_list *deepen_not, |
| 753 | struct object_array *shallows) |
| 754 | { |
| 755 | int ret = 0; |
| 756 | |
| 757 | if (depth > 0 && deepen_rev_list) |
| 758 | die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together"); |
| 759 | if (depth > 0) { |
| 760 | deepen(depth, deepen_relative, shallows); |
| 761 | ret = 1; |
| 762 | } else if (deepen_rev_list) { |
| 763 | struct argv_array av = ARGV_ARRAY_INIT; |
| 764 | int i; |
| 765 | |
| 766 | argv_array_push(&av, "rev-list"); |
| 767 | if (deepen_since) |
| 768 | argv_array_pushf(&av, "--max-age=%"PRItime, deepen_since); |
| 769 | if (deepen_not->nr) { |
| 770 | argv_array_push(&av, "--not"); |
| 771 | for (i = 0; i < deepen_not->nr; i++) { |
| 772 | struct string_list_item *s = deepen_not->items + i; |
| 773 | argv_array_push(&av, s->string); |
| 774 | } |
| 775 | argv_array_push(&av, "--not"); |
| 776 | } |
| 777 | for (i = 0; i < want_obj.nr; i++) { |
| 778 | struct object *o = want_obj.objects[i].item; |
| 779 | argv_array_push(&av, oid_to_hex(&o->oid)); |
| 780 | } |
| 781 | deepen_by_rev_list(av.argc, av.argv, shallows); |
| 782 | argv_array_clear(&av); |
| 783 | ret = 1; |
| 784 | } else { |
| 785 | if (shallows->nr > 0) { |
| 786 | int i; |
| 787 | for (i = 0; i < shallows->nr; i++) |
Junio C Hamano | 00624d6 | 2018-07-18 12:20:27 -0700 | [diff] [blame] | 788 | register_shallow(the_repository, |
| 789 | &shallows->objects[i].item->oid); |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
| 793 | shallow_nr += shallows->nr; |
| 794 | return ret; |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 795 | } |
| 796 | |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 797 | static int process_shallow(const char *line, struct object_array *shallows) |
| 798 | { |
| 799 | const char *arg; |
| 800 | if (skip_prefix(line, "shallow ", &arg)) { |
| 801 | struct object_id oid; |
| 802 | struct object *object; |
| 803 | if (get_oid_hex(arg, &oid)) |
| 804 | die("invalid shallow line: %s", line); |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 805 | object = parse_object(the_repository, &oid); |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 806 | if (!object) |
| 807 | return 1; |
| 808 | if (object->type != OBJ_COMMIT) |
| 809 | die("invalid shallow object %s", oid_to_hex(&oid)); |
| 810 | if (!(object->flags & CLIENT_SHALLOW)) { |
| 811 | object->flags |= CLIENT_SHALLOW; |
| 812 | add_object_array(object, NULL, shallows); |
| 813 | } |
| 814 | return 1; |
| 815 | } |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | static int process_deepen(const char *line, int *depth) |
| 821 | { |
| 822 | const char *arg; |
| 823 | if (skip_prefix(line, "deepen ", &arg)) { |
| 824 | char *end = NULL; |
| 825 | *depth = (int)strtol(arg, &end, 0); |
| 826 | if (!end || *end || *depth <= 0) |
| 827 | die("Invalid deepen: %s", line); |
| 828 | return 1; |
| 829 | } |
| 830 | |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | static int process_deepen_since(const char *line, timestamp_t *deepen_since, int *deepen_rev_list) |
| 835 | { |
| 836 | const char *arg; |
| 837 | if (skip_prefix(line, "deepen-since ", &arg)) { |
| 838 | char *end = NULL; |
| 839 | *deepen_since = parse_timestamp(arg, &end, 0); |
| 840 | if (!end || *end || !deepen_since || |
| 841 | /* revisions.c's max_age -1 is special */ |
| 842 | *deepen_since == -1) |
| 843 | die("Invalid deepen-since: %s", line); |
| 844 | *deepen_rev_list = 1; |
| 845 | return 1; |
| 846 | } |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | static int process_deepen_not(const char *line, struct string_list *deepen_not, int *deepen_rev_list) |
| 851 | { |
| 852 | const char *arg; |
| 853 | if (skip_prefix(line, "deepen-not ", &arg)) { |
| 854 | char *ref = NULL; |
| 855 | struct object_id oid; |
| 856 | if (expand_ref(arg, strlen(arg), &oid, &ref) != 1) |
| 857 | die("git upload-pack: ambiguous deepen-not: %s", line); |
| 858 | string_list_append(deepen_not, ref); |
| 859 | free(ref); |
| 860 | *deepen_rev_list = 1; |
| 861 | return 1; |
| 862 | } |
| 863 | return 0; |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 866 | static void receive_needs(void) |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 867 | { |
Thiago Farina | 3cd4745 | 2010-08-28 23:04:17 -0300 | [diff] [blame] | 868 | struct object_array shallows = OBJECT_ARRAY_INIT; |
Nguyễn Thái Ngọc Duy | 269a7a8 | 2016-06-12 17:54:03 +0700 | [diff] [blame] | 869 | struct string_list deepen_not = STRING_LIST_INIT_DUP; |
Jeff King | 74543a0 | 2013-02-20 15:02:57 -0500 | [diff] [blame] | 870 | int depth = 0; |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 871 | int has_non_tip = 0; |
Johannes Schindelin | dddbad7 | 2017-04-26 21:29:31 +0200 | [diff] [blame] | 872 | timestamp_t deepen_since = 0; |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 873 | int deepen_rev_list = 0; |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 874 | |
Nick Edelen | f0cea83 | 2009-06-10 01:50:18 +0200 | [diff] [blame] | 875 | shallow_nr = 0; |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 876 | for (;;) { |
Junio C Hamano | 565ebbf | 2005-10-24 18:59:18 -0700 | [diff] [blame] | 877 | struct object *o; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 878 | const char *features; |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 879 | struct object_id oid_buf; |
Jeff King | 74543a0 | 2013-02-20 15:02:57 -0500 | [diff] [blame] | 880 | char *line = packet_read_line(0, NULL); |
Nguyễn Thái Ngọc Duy | 8bf3b75 | 2016-06-12 17:53:49 +0700 | [diff] [blame] | 881 | const char *arg; |
| 882 | |
H. Peter Anvin | 960decc | 2005-10-19 14:27:01 -0700 | [diff] [blame] | 883 | reset_timeout(); |
Jeff King | 74543a0 | 2013-02-20 15:02:57 -0500 | [diff] [blame] | 884 | if (!line) |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 885 | break; |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 886 | |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 887 | if (process_shallow(line, &shallows)) |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 888 | continue; |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 889 | if (process_deepen(line, &depth)) |
Johannes Schindelin | 016e6cc | 2006-10-30 20:09:29 +0100 | [diff] [blame] | 890 | continue; |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 891 | if (process_deepen_since(line, &deepen_since, &deepen_rev_list)) |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 892 | continue; |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 893 | if (process_deepen_not(line, &deepen_not, &deepen_rev_list)) |
Nguyễn Thái Ngọc Duy | 269a7a8 | 2016-06-12 17:54:03 +0700 | [diff] [blame] | 894 | continue; |
Brandon Williams | ae2948f | 2018-03-14 11:31:42 -0700 | [diff] [blame] | 895 | |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 896 | if (skip_prefix(line, "filter ", &arg)) { |
| 897 | if (!filter_capability_requested) |
| 898 | die("git upload-pack: filtering capability not negotiated"); |
| 899 | parse_list_objects_filter(&filter_options, arg); |
| 900 | continue; |
| 901 | } |
Junio C Hamano | 9bfa0f9 | 2018-05-08 15:59:15 +0900 | [diff] [blame] | 902 | |
Nguyễn Thái Ngọc Duy | 8bf3b75 | 2016-06-12 17:53:49 +0700 | [diff] [blame] | 903 | if (!skip_prefix(line, "want ", &arg) || |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 904 | parse_oid_hex(arg, &oid_buf, &features)) |
Junio C Hamano | 7e44c93 | 2008-08-31 09:39:19 -0700 | [diff] [blame] | 905 | die("git upload-pack: protocol error, " |
brian m. carlson | 55dc227 | 2018-05-02 00:25:51 +0000 | [diff] [blame] | 906 | "expected to get object ID, not '%s'", line); |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 907 | |
Nguyễn Thái Ngọc Duy | cccf74e | 2016-06-12 17:54:09 +0700 | [diff] [blame] | 908 | if (parse_feature_request(features, "deepen-relative")) |
| 909 | deepen_relative = 1; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 910 | if (parse_feature_request(features, "multi_ack_detailed")) |
Shawn O. Pearce | 78affc4 | 2009-10-30 17:47:25 -0700 | [diff] [blame] | 911 | multi_ack = 2; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 912 | else if (parse_feature_request(features, "multi_ack")) |
Johannes Schindelin | 1bd8c8f | 2005-10-28 04:49:16 +0200 | [diff] [blame] | 913 | multi_ack = 1; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 914 | if (parse_feature_request(features, "no-done")) |
Junio C Hamano | 4e10cf9 | 2011-03-29 12:29:10 -0700 | [diff] [blame] | 915 | no_done = 1; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 916 | if (parse_feature_request(features, "thin-pack")) |
Junio C Hamano | b19696c | 2006-02-20 00:38:39 -0800 | [diff] [blame] | 917 | use_thin_pack = 1; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 918 | if (parse_feature_request(features, "ofs-delta")) |
Nicolas Pitre | e4fe4b8 | 2006-09-26 11:27:39 -0400 | [diff] [blame] | 919 | use_ofs_delta = 1; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 920 | if (parse_feature_request(features, "side-band-64k")) |
Junio C Hamano | d47f3db | 2006-09-10 16:27:08 -0700 | [diff] [blame] | 921 | use_sideband = LARGE_PACKET_MAX; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 922 | else if (parse_feature_request(features, "side-band")) |
Junio C Hamano | d47f3db | 2006-09-10 16:27:08 -0700 | [diff] [blame] | 923 | use_sideband = DEFAULT_PACKET_MAX; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 924 | if (parse_feature_request(features, "no-progress")) |
Johannes Schindelin | b0e9089 | 2007-02-23 20:03:10 +0100 | [diff] [blame] | 925 | no_progress = 1; |
Junio C Hamano | f47182c | 2012-01-08 22:06:19 +0100 | [diff] [blame] | 926 | if (parse_feature_request(features, "include-tag")) |
Shawn O. Pearce | 348e390 | 2008-03-03 22:27:33 -0500 | [diff] [blame] | 927 | use_include_tag = 1; |
Jonathan Nieder | c7620bd | 2018-03-28 13:33:03 -0700 | [diff] [blame] | 928 | if (allow_filter && parse_feature_request(features, "filter")) |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 929 | filter_capability_requested = 1; |
Junio C Hamano | 565ebbf | 2005-10-24 18:59:18 -0700 | [diff] [blame] | 930 | |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 931 | o = parse_object(the_repository, &oid_buf); |
Jonathan Tan | bdb31ea | 2017-02-23 10:43:03 -0800 | [diff] [blame] | 932 | if (!o) { |
| 933 | packet_write_fmt(1, |
| 934 | "ERR upload-pack: not our ref %s", |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 935 | oid_to_hex(&oid_buf)); |
Elijah Newren | 9f9aa76 | 2010-07-31 14:11:46 -0600 | [diff] [blame] | 936 | die("git upload-pack: not our ref %s", |
brian m. carlson | cf93982 | 2017-05-06 22:10:28 +0000 | [diff] [blame] | 937 | oid_to_hex(&oid_buf)); |
Jonathan Tan | bdb31ea | 2017-02-23 10:43:03 -0800 | [diff] [blame] | 938 | } |
Junio C Hamano | 565ebbf | 2005-10-24 18:59:18 -0700 | [diff] [blame] | 939 | if (!(o->flags & WANTED)) { |
| 940 | o->flags |= WANTED; |
David Turner | f8edeaa | 2016-11-11 12:23:48 -0500 | [diff] [blame] | 941 | if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 |
| 942 | || is_our_ref(o))) |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 943 | has_non_tip = 1; |
Junio C Hamano | b1e9fff | 2006-07-05 18:00:02 -0700 | [diff] [blame] | 944 | add_object_array(o, NULL, &want_obj); |
Junio C Hamano | 565ebbf | 2005-10-24 18:59:18 -0700 | [diff] [blame] | 945 | } |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 946 | } |
Johannes Sixt | 9462e3f | 2009-06-16 20:41:16 +0200 | [diff] [blame] | 947 | |
Junio C Hamano | 051e400 | 2011-08-05 13:54:06 -0700 | [diff] [blame] | 948 | /* |
| 949 | * We have sent all our refs already, and the other end |
| 950 | * should have chosen out of them. When we are operating |
| 951 | * in the stateless RPC mode, however, their choice may |
| 952 | * have been based on the set of older refs advertised |
| 953 | * by another process that handled the initial request. |
| 954 | */ |
| 955 | if (has_non_tip) |
| 956 | check_non_tip(); |
| 957 | |
Johannes Sixt | 9462e3f | 2009-06-16 20:41:16 +0200 | [diff] [blame] | 958 | if (!use_sideband && daemon_mode) |
| 959 | no_progress = 1; |
| 960 | |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 961 | if (depth == 0 && !deepen_rev_list && shallows.nr == 0) |
Johannes Schindelin | f53514b | 2006-10-30 20:09:53 +0100 | [diff] [blame] | 962 | return; |
Nguyễn Thái Ngọc Duy | 569e554 | 2016-06-12 17:53:58 +0700 | [diff] [blame] | 963 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 964 | if (send_shallow_list(depth, deepen_rev_list, deepen_since, |
| 965 | &deepen_not, &shallows)) |
| 966 | packet_flush(1); |
Martin Ågren | dcb572a | 2017-09-23 01:34:52 +0200 | [diff] [blame] | 967 | object_array_clear(&shallows); |
Linus Torvalds | fb9040c | 2005-07-04 15:29:17 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 970 | /* return non-zero if the ref is hidden, otherwise 0 */ |
Lukas Fleischer | 78a766a | 2015-11-03 08:58:16 +0100 | [diff] [blame] | 971 | static int mark_our_ref(const char *refname, const char *refname_full, |
| 972 | const struct object_id *oid) |
Junio C Hamano | cbbe50d | 2013-01-18 15:48:49 -0800 | [diff] [blame] | 973 | { |
Michael Haggerty | 363e98b | 2015-05-25 18:39:12 +0000 | [diff] [blame] | 974 | struct object *o = lookup_unknown_object(oid->hash); |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 975 | |
Lukas Fleischer | 78a766a | 2015-11-03 08:58:16 +0100 | [diff] [blame] | 976 | if (ref_is_hidden(refname, refname_full)) { |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 977 | o->flags |= HIDDEN_REF; |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 978 | return 1; |
Junio C Hamano | 390eb36 | 2013-01-28 21:49:57 -0800 | [diff] [blame] | 979 | } |
Junio C Hamano | 3f1da57 | 2013-01-28 20:45:43 -0800 | [diff] [blame] | 980 | o->flags |= OUR_REF; |
Junio C Hamano | cbbe50d | 2013-01-18 15:48:49 -0800 | [diff] [blame] | 981 | return 0; |
| 982 | } |
| 983 | |
Lukas Fleischer | 78a766a | 2015-11-03 08:58:16 +0100 | [diff] [blame] | 984 | static int check_ref(const char *refname_full, const struct object_id *oid, |
Michael Haggerty | 363e98b | 2015-05-25 18:39:12 +0000 | [diff] [blame] | 985 | int flag, void *cb_data) |
Jeff King | e172755 | 2015-03-13 00:42:12 -0400 | [diff] [blame] | 986 | { |
Lukas Fleischer | 78a766a | 2015-11-03 08:58:16 +0100 | [diff] [blame] | 987 | const char *refname = strip_namespace(refname_full); |
| 988 | |
| 989 | mark_our_ref(refname, refname_full, oid); |
Jeff King | e172755 | 2015-03-13 00:42:12 -0400 | [diff] [blame] | 990 | return 0; |
| 991 | } |
| 992 | |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 993 | static void format_symref_info(struct strbuf *buf, struct string_list *symref) |
| 994 | { |
| 995 | struct string_list_item *item; |
| 996 | |
| 997 | if (!symref->nr) |
| 998 | return; |
| 999 | for_each_string_list_item(item, symref) |
| 1000 | strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util); |
| 1001 | } |
| 1002 | |
Michael Haggerty | 363e98b | 2015-05-25 18:39:12 +0000 | [diff] [blame] | 1003 | static int send_ref(const char *refname, const struct object_id *oid, |
| 1004 | int flag, void *cb_data) |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 1005 | { |
Johannes Schindelin | ed09aef | 2006-10-30 20:09:06 +0100 | [diff] [blame] | 1006 | static const char *capabilities = "multi_ack thin-pack side-band" |
Nguyễn Thái Ngọc Duy | cccf74e | 2016-06-12 17:54:09 +0700 | [diff] [blame] | 1007 | " side-band-64k ofs-delta shallow deepen-since deepen-not" |
| 1008 | " deepen-relative no-progress include-tag multi_ack_detailed"; |
Josh Triplett | 6b01ecf | 2011-07-08 16:13:32 -0700 | [diff] [blame] | 1009 | const char *refname_nons = strip_namespace(refname); |
Michael Haggerty | 21758af | 2015-05-25 18:39:13 +0000 | [diff] [blame] | 1010 | struct object_id peeled; |
Carl Worth | b5b1699 | 2006-02-17 16:14:52 -0800 | [diff] [blame] | 1011 | |
Lukas Fleischer | 78a766a | 2015-11-03 08:58:16 +0100 | [diff] [blame] | 1012 | if (mark_our_ref(refname_nons, refname, oid)) |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1013 | return 0; |
Junio C Hamano | cbbe50d | 2013-01-18 15:48:49 -0800 | [diff] [blame] | 1014 | |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1015 | if (capabilities) { |
| 1016 | struct strbuf symref_info = STRBUF_INIT; |
| 1017 | |
| 1018 | format_symref_info(&symref_info, cb_data); |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 1019 | packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n", |
Michael Haggerty | 363e98b | 2015-05-25 18:39:12 +0000 | [diff] [blame] | 1020 | oid_to_hex(oid), refname_nons, |
Junio C Hamano | cf2ad8e | 2011-03-29 10:24:59 -0700 | [diff] [blame] | 1021 | 0, capabilities, |
Fredrik Medley | 7199c09 | 2015-05-21 22:23:38 +0200 | [diff] [blame] | 1022 | (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ? |
| 1023 | " allow-tip-sha1-in-want" : "", |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 1024 | (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ? |
| 1025 | " allow-reachable-sha1-in-want" : "", |
Jeff King | ff5effd | 2012-08-03 12:19:16 -0400 | [diff] [blame] | 1026 | stateless_rpc ? " no-done" : "", |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1027 | symref_info.buf, |
Jonathan Nieder | c7620bd | 2018-03-28 13:33:03 -0700 | [diff] [blame] | 1028 | allow_filter ? " filter" : "", |
Jeff King | ff5effd | 2012-08-03 12:19:16 -0400 | [diff] [blame] | 1029 | git_user_agent_sanitized()); |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1030 | strbuf_release(&symref_info); |
| 1031 | } else { |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 1032 | packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons); |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1033 | } |
Johannes Schindelin | 1f5881b | 2005-10-28 05:56:41 +0200 | [diff] [blame] | 1034 | capabilities = NULL; |
brian m. carlson | b420d90 | 2017-10-15 22:07:02 +0000 | [diff] [blame] | 1035 | if (!peel_ref(refname, &peeled)) |
Lars Schneider | 81c634e | 2016-10-16 16:20:29 -0700 | [diff] [blame] | 1036 | packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons); |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 1037 | return 0; |
| 1038 | } |
| 1039 | |
Michael Haggerty | 7dabd05 | 2015-05-25 18:39:10 +0000 | [diff] [blame] | 1040 | static int find_symref(const char *refname, const struct object_id *oid, |
| 1041 | int flag, void *cb_data) |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1042 | { |
| 1043 | const char *symref_target; |
| 1044 | struct string_list_item *item; |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1045 | |
| 1046 | if ((flag & REF_ISSYMREF) == 0) |
| 1047 | return 0; |
René Scharfe | 744c040 | 2017-09-23 11:45:04 +0200 | [diff] [blame] | 1048 | symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag); |
Junio C Hamano | 7171d8c | 2013-09-17 16:17:33 -0700 | [diff] [blame] | 1049 | if (!symref_target || (flag & REF_ISSYMREF) == 0) |
| 1050 | die("'%s' is a symref but it is not?", refname); |
| 1051 | item = string_list_append(cb_data, refname); |
| 1052 | item->util = xstrdup(symref_target); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1056 | static int upload_pack_config(const char *var, const char *value, void *unused) |
| 1057 | { |
Fredrik Medley | 7199c09 | 2015-05-21 22:23:38 +0200 | [diff] [blame] | 1058 | if (!strcmp("uploadpack.allowtipsha1inwant", var)) { |
| 1059 | if (git_config_bool(var, value)) |
| 1060 | allow_unadvertised_object_request |= ALLOW_TIP_SHA1; |
| 1061 | else |
| 1062 | allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1; |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 1063 | } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) { |
| 1064 | if (git_config_bool(var, value)) |
| 1065 | allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1; |
| 1066 | else |
| 1067 | allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1; |
David Turner | f8edeaa | 2016-11-11 12:23:48 -0500 | [diff] [blame] | 1068 | } else if (!strcmp("uploadpack.allowanysha1inwant", var)) { |
| 1069 | if (git_config_bool(var, value)) |
| 1070 | allow_unadvertised_object_request |= ALLOW_ANY_SHA1; |
| 1071 | else |
| 1072 | allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1; |
Fredrik Medley | 7199c09 | 2015-05-21 22:23:38 +0200 | [diff] [blame] | 1073 | } else if (!strcmp("uploadpack.keepalive", var)) { |
Jeff King | 05e9515 | 2013-09-08 05:01:31 -0400 | [diff] [blame] | 1074 | keepalive = git_config_int(var, value); |
| 1075 | if (!keepalive) |
| 1076 | keepalive = -1; |
Jeff King | 20b20a2 | 2016-05-18 18:45:37 -0400 | [diff] [blame] | 1077 | } else if (current_config_scope() != CONFIG_SCOPE_REPO) { |
| 1078 | if (!strcmp("uploadpack.packobjectshook", var)) |
| 1079 | return git_config_string(&pack_objects_hook, var, value); |
Jeff Hostetler | 10ac85c | 2017-12-08 15:58:39 +0000 | [diff] [blame] | 1080 | } else if (!strcmp("uploadpack.allowfilter", var)) { |
Jonathan Nieder | c7620bd | 2018-03-28 13:33:03 -0700 | [diff] [blame] | 1081 | allow_filter = git_config_bool(var, value); |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1082 | } else if (!strcmp("uploadpack.allowrefinwant", var)) { |
| 1083 | allow_ref_in_want = git_config_bool(var, value); |
Jeff King | 05e9515 | 2013-09-08 05:01:31 -0400 | [diff] [blame] | 1084 | } |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1085 | return parse_hide_refs_config(var, value, "uploadpack"); |
| 1086 | } |
| 1087 | |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1088 | void upload_pack(struct upload_pack_options *options) |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 1089 | { |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1090 | struct string_list symref = STRING_LIST_INIT_DUP; |
H. Peter Anvin | 960decc | 2005-10-19 14:27:01 -0700 | [diff] [blame] | 1091 | |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1092 | stateless_rpc = options->stateless_rpc; |
| 1093 | timeout = options->timeout; |
| 1094 | daemon_mode = options->daemon_mode; |
Nguyễn Thái Ngọc Duy | ad49136 | 2013-12-05 20:02:32 +0700 | [diff] [blame] | 1095 | |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1096 | git_config(upload_pack_config, NULL); |
Brandon Williams | aa9bab2 | 2017-10-16 10:55:26 -0700 | [diff] [blame] | 1097 | |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1098 | head_ref_namespaced(find_symref, &symref); |
Brandon Williams | aa9bab2 | 2017-10-16 10:55:26 -0700 | [diff] [blame] | 1099 | |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1100 | if (options->advertise_refs || !stateless_rpc) { |
| 1101 | reset_timeout(); |
| 1102 | head_ref_namespaced(send_ref, &symref); |
| 1103 | for_each_namespaced_ref(send_ref, &symref); |
| 1104 | advertise_shallow_grafts(1); |
| 1105 | packet_flush(1); |
| 1106 | } else { |
| 1107 | head_ref_namespaced(check_ref, NULL); |
| 1108 | for_each_namespaced_ref(check_ref, NULL); |
Brandon Williams | aa9bab2 | 2017-10-16 10:55:26 -0700 | [diff] [blame] | 1109 | } |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1110 | string_list_clear(&symref, 1); |
| 1111 | if (options->advertise_refs) |
| 1112 | return; |
Brandon Williams | aa9bab2 | 2017-10-16 10:55:26 -0700 | [diff] [blame] | 1113 | |
Brandon Williams | a3d6b53 | 2018-03-14 11:31:41 -0700 | [diff] [blame] | 1114 | receive_needs(); |
| 1115 | if (want_obj.nr) { |
| 1116 | get_common_commits(); |
| 1117 | create_pack_file(); |
| 1118 | } |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 1119 | } |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1120 | |
| 1121 | struct upload_pack_data { |
| 1122 | struct object_array wants; |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1123 | struct string_list wanted_refs; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1124 | struct oid_array haves; |
| 1125 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1126 | struct object_array shallows; |
| 1127 | struct string_list deepen_not; |
| 1128 | int depth; |
| 1129 | timestamp_t deepen_since; |
| 1130 | int deepen_rev_list; |
| 1131 | int deepen_relative; |
| 1132 | |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1133 | unsigned stateless_rpc : 1; |
| 1134 | |
| 1135 | unsigned use_thin_pack : 1; |
| 1136 | unsigned use_ofs_delta : 1; |
| 1137 | unsigned no_progress : 1; |
| 1138 | unsigned use_include_tag : 1; |
| 1139 | unsigned done : 1; |
| 1140 | }; |
| 1141 | |
| 1142 | static void upload_pack_data_init(struct upload_pack_data *data) |
| 1143 | { |
| 1144 | struct object_array wants = OBJECT_ARRAY_INIT; |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1145 | struct string_list wanted_refs = STRING_LIST_INIT_DUP; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1146 | struct oid_array haves = OID_ARRAY_INIT; |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1147 | struct object_array shallows = OBJECT_ARRAY_INIT; |
| 1148 | struct string_list deepen_not = STRING_LIST_INIT_DUP; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1149 | |
| 1150 | memset(data, 0, sizeof(*data)); |
| 1151 | data->wants = wants; |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1152 | data->wanted_refs = wanted_refs; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1153 | data->haves = haves; |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1154 | data->shallows = shallows; |
| 1155 | data->deepen_not = deepen_not; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static void upload_pack_data_clear(struct upload_pack_data *data) |
| 1159 | { |
| 1160 | object_array_clear(&data->wants); |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1161 | string_list_clear(&data->wanted_refs, 1); |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1162 | oid_array_clear(&data->haves); |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1163 | object_array_clear(&data->shallows); |
| 1164 | string_list_clear(&data->deepen_not, 0); |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | static int parse_want(const char *line) |
| 1168 | { |
| 1169 | const char *arg; |
| 1170 | if (skip_prefix(line, "want ", &arg)) { |
| 1171 | struct object_id oid; |
| 1172 | struct object *o; |
| 1173 | |
| 1174 | if (get_oid_hex(arg, &oid)) |
| 1175 | die("git upload-pack: protocol error, " |
| 1176 | "expected to get oid, not '%s'", line); |
| 1177 | |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 1178 | o = parse_object(the_repository, &oid); |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1179 | if (!o) { |
| 1180 | packet_write_fmt(1, |
| 1181 | "ERR upload-pack: not our ref %s", |
| 1182 | oid_to_hex(&oid)); |
| 1183 | die("git upload-pack: not our ref %s", |
| 1184 | oid_to_hex(&oid)); |
| 1185 | } |
| 1186 | |
| 1187 | if (!(o->flags & WANTED)) { |
| 1188 | o->flags |= WANTED; |
| 1189 | add_object_array(o, NULL, &want_obj); |
| 1190 | } |
| 1191 | |
| 1192 | return 1; |
Linus Torvalds | def88e9 | 2005-07-04 13:26:53 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | return 0; |
| 1196 | } |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1197 | |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1198 | static int parse_want_ref(const char *line, struct string_list *wanted_refs) |
| 1199 | { |
| 1200 | const char *arg; |
| 1201 | if (skip_prefix(line, "want-ref ", &arg)) { |
| 1202 | struct object_id oid; |
| 1203 | struct string_list_item *item; |
| 1204 | struct object *o; |
| 1205 | |
| 1206 | if (read_ref(arg, &oid)) { |
| 1207 | packet_write_fmt(1, "ERR unknown ref %s", arg); |
| 1208 | die("unknown ref %s", arg); |
| 1209 | } |
| 1210 | |
| 1211 | item = string_list_append(wanted_refs, arg); |
| 1212 | item->util = oiddup(&oid); |
| 1213 | |
| 1214 | o = parse_object_or_die(&oid, arg); |
| 1215 | if (!(o->flags & WANTED)) { |
| 1216 | o->flags |= WANTED; |
| 1217 | add_object_array(o, NULL, &want_obj); |
| 1218 | } |
| 1219 | |
| 1220 | return 1; |
| 1221 | } |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1226 | static int parse_have(const char *line, struct oid_array *haves) |
| 1227 | { |
| 1228 | const char *arg; |
| 1229 | if (skip_prefix(line, "have ", &arg)) { |
| 1230 | struct object_id oid; |
| 1231 | |
| 1232 | if (get_oid_hex(arg, &oid)) |
| 1233 | die("git upload-pack: expected SHA1 object, got '%s'", arg); |
| 1234 | oid_array_append(haves, &oid); |
| 1235 | return 1; |
| 1236 | } |
| 1237 | |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | static void process_args(struct packet_reader *request, |
| 1242 | struct upload_pack_data *data) |
| 1243 | { |
| 1244 | while (packet_reader_read(request) != PACKET_READ_FLUSH) { |
| 1245 | const char *arg = request->line; |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 1246 | const char *p; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* process want */ |
| 1249 | if (parse_want(arg)) |
| 1250 | continue; |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1251 | if (allow_ref_in_want && parse_want_ref(arg, &data->wanted_refs)) |
| 1252 | continue; |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1253 | /* process have line */ |
| 1254 | if (parse_have(arg, &data->haves)) |
| 1255 | continue; |
| 1256 | |
| 1257 | /* process args like thin-pack */ |
| 1258 | if (!strcmp(arg, "thin-pack")) { |
| 1259 | use_thin_pack = 1; |
| 1260 | continue; |
| 1261 | } |
| 1262 | if (!strcmp(arg, "ofs-delta")) { |
| 1263 | use_ofs_delta = 1; |
| 1264 | continue; |
| 1265 | } |
| 1266 | if (!strcmp(arg, "no-progress")) { |
| 1267 | no_progress = 1; |
| 1268 | continue; |
| 1269 | } |
| 1270 | if (!strcmp(arg, "include-tag")) { |
| 1271 | use_include_tag = 1; |
| 1272 | continue; |
| 1273 | } |
| 1274 | if (!strcmp(arg, "done")) { |
| 1275 | data->done = 1; |
| 1276 | continue; |
| 1277 | } |
| 1278 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1279 | /* Shallow related arguments */ |
| 1280 | if (process_shallow(arg, &data->shallows)) |
| 1281 | continue; |
| 1282 | if (process_deepen(arg, &data->depth)) |
| 1283 | continue; |
| 1284 | if (process_deepen_since(arg, &data->deepen_since, |
| 1285 | &data->deepen_rev_list)) |
| 1286 | continue; |
| 1287 | if (process_deepen_not(arg, &data->deepen_not, |
| 1288 | &data->deepen_rev_list)) |
| 1289 | continue; |
| 1290 | if (!strcmp(arg, "deepen-relative")) { |
| 1291 | data->deepen_relative = 1; |
| 1292 | continue; |
| 1293 | } |
| 1294 | |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 1295 | if (allow_filter && skip_prefix(arg, "filter ", &p)) { |
| 1296 | parse_list_objects_filter(&filter_options, p); |
| 1297 | continue; |
| 1298 | } |
| 1299 | |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1300 | /* ignore unknown lines maybe? */ |
Jonathan Tan | 7cc6ed2 | 2018-05-01 17:31:29 -0700 | [diff] [blame] | 1301 | die("unexpected line: '%s'", arg); |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | static int process_haves(struct oid_array *haves, struct oid_array *common) |
| 1306 | { |
| 1307 | int i; |
| 1308 | |
| 1309 | /* Process haves */ |
| 1310 | for (i = 0; i < haves->nr; i++) { |
| 1311 | const struct object_id *oid = &haves->oid[i]; |
| 1312 | struct object *o; |
| 1313 | int we_knew_they_have = 0; |
| 1314 | |
| 1315 | if (!has_object_file(oid)) |
| 1316 | continue; |
| 1317 | |
| 1318 | oid_array_append(common, oid); |
| 1319 | |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 1320 | o = parse_object(the_repository, oid); |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1321 | if (!o) |
| 1322 | die("oops (%s)", oid_to_hex(oid)); |
| 1323 | if (o->type == OBJ_COMMIT) { |
| 1324 | struct commit_list *parents; |
| 1325 | struct commit *commit = (struct commit *)o; |
| 1326 | if (o->flags & THEY_HAVE) |
| 1327 | we_knew_they_have = 1; |
| 1328 | else |
| 1329 | o->flags |= THEY_HAVE; |
| 1330 | if (!oldest_have || (commit->date < oldest_have)) |
| 1331 | oldest_have = commit->date; |
| 1332 | for (parents = commit->parents; |
| 1333 | parents; |
| 1334 | parents = parents->next) |
| 1335 | parents->item->object.flags |= THEY_HAVE; |
| 1336 | } |
| 1337 | if (!we_knew_they_have) |
| 1338 | add_object_array(o, NULL, &have_obj); |
| 1339 | } |
| 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | static int send_acks(struct oid_array *acks, struct strbuf *response) |
| 1345 | { |
| 1346 | int i; |
| 1347 | |
| 1348 | packet_buf_write(response, "acknowledgments\n"); |
| 1349 | |
| 1350 | /* Send Acks */ |
| 1351 | if (!acks->nr) |
| 1352 | packet_buf_write(response, "NAK\n"); |
| 1353 | |
| 1354 | for (i = 0; i < acks->nr; i++) { |
| 1355 | packet_buf_write(response, "ACK %s\n", |
| 1356 | oid_to_hex(&acks->oid[i])); |
| 1357 | } |
| 1358 | |
| 1359 | if (ok_to_give_up()) { |
| 1360 | /* Send Ready */ |
| 1361 | packet_buf_write(response, "ready\n"); |
| 1362 | return 1; |
| 1363 | } |
| 1364 | |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | static int process_haves_and_send_acks(struct upload_pack_data *data) |
| 1369 | { |
| 1370 | struct oid_array common = OID_ARRAY_INIT; |
| 1371 | struct strbuf response = STRBUF_INIT; |
| 1372 | int ret = 0; |
| 1373 | |
| 1374 | process_haves(&data->haves, &common); |
| 1375 | if (data->done) { |
| 1376 | ret = 1; |
| 1377 | } else if (send_acks(&common, &response)) { |
| 1378 | packet_buf_delim(&response); |
| 1379 | ret = 1; |
| 1380 | } else { |
| 1381 | /* Add Flush */ |
| 1382 | packet_buf_flush(&response); |
| 1383 | ret = 0; |
| 1384 | } |
| 1385 | |
| 1386 | /* Send response */ |
| 1387 | write_or_die(1, response.buf, response.len); |
| 1388 | strbuf_release(&response); |
| 1389 | |
| 1390 | oid_array_clear(&data->haves); |
| 1391 | oid_array_clear(&common); |
| 1392 | return ret; |
| 1393 | } |
| 1394 | |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1395 | static void send_wanted_ref_info(struct upload_pack_data *data) |
| 1396 | { |
| 1397 | const struct string_list_item *item; |
| 1398 | |
| 1399 | if (!data->wanted_refs.nr) |
| 1400 | return; |
| 1401 | |
| 1402 | packet_write_fmt(1, "wanted-refs\n"); |
| 1403 | |
| 1404 | for_each_string_list_item(item, &data->wanted_refs) { |
| 1405 | packet_write_fmt(1, "%s %s\n", |
| 1406 | oid_to_hex(item->util), |
| 1407 | item->string); |
| 1408 | } |
| 1409 | |
| 1410 | packet_delim(1); |
| 1411 | } |
| 1412 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1413 | static void send_shallow_info(struct upload_pack_data *data) |
| 1414 | { |
| 1415 | /* No shallow info needs to be sent */ |
| 1416 | if (!data->depth && !data->deepen_rev_list && !data->shallows.nr && |
Junio C Hamano | 00624d6 | 2018-07-18 12:20:27 -0700 | [diff] [blame] | 1417 | !is_repository_shallow(the_repository)) |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1418 | return; |
| 1419 | |
| 1420 | packet_write_fmt(1, "shallow-info\n"); |
| 1421 | |
| 1422 | if (!send_shallow_list(data->depth, data->deepen_rev_list, |
| 1423 | data->deepen_since, &data->deepen_not, |
Junio C Hamano | 00624d6 | 2018-07-18 12:20:27 -0700 | [diff] [blame] | 1424 | &data->shallows) && |
| 1425 | is_repository_shallow(the_repository)) |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1426 | deepen(INFINITE_DEPTH, data->deepen_relative, &data->shallows); |
| 1427 | |
| 1428 | packet_delim(1); |
| 1429 | } |
| 1430 | |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1431 | enum fetch_state { |
| 1432 | FETCH_PROCESS_ARGS = 0, |
| 1433 | FETCH_SEND_ACKS, |
| 1434 | FETCH_SEND_PACK, |
| 1435 | FETCH_DONE, |
| 1436 | }; |
| 1437 | |
| 1438 | int upload_pack_v2(struct repository *r, struct argv_array *keys, |
| 1439 | struct packet_reader *request) |
| 1440 | { |
| 1441 | enum fetch_state state = FETCH_PROCESS_ARGS; |
| 1442 | struct upload_pack_data data; |
| 1443 | |
Jonathan Tan | 5459268 | 2018-05-03 16:46:55 -0700 | [diff] [blame] | 1444 | git_config(upload_pack_config, NULL); |
| 1445 | |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1446 | upload_pack_data_init(&data); |
| 1447 | use_sideband = LARGE_PACKET_MAX; |
| 1448 | |
| 1449 | while (state != FETCH_DONE) { |
| 1450 | switch (state) { |
| 1451 | case FETCH_PROCESS_ARGS: |
| 1452 | process_args(request, &data); |
| 1453 | |
| 1454 | if (!want_obj.nr) { |
| 1455 | /* |
| 1456 | * Request didn't contain any 'want' lines, |
| 1457 | * guess they didn't want anything. |
| 1458 | */ |
| 1459 | state = FETCH_DONE; |
| 1460 | } else if (data.haves.nr) { |
| 1461 | /* |
| 1462 | * Request had 'have' lines, so lets ACK them. |
| 1463 | */ |
| 1464 | state = FETCH_SEND_ACKS; |
| 1465 | } else { |
| 1466 | /* |
| 1467 | * Request had 'want's but no 'have's so we can |
| 1468 | * immedietly go to construct and send a pack. |
| 1469 | */ |
| 1470 | state = FETCH_SEND_PACK; |
| 1471 | } |
| 1472 | break; |
| 1473 | case FETCH_SEND_ACKS: |
| 1474 | if (process_haves_and_send_acks(&data)) |
| 1475 | state = FETCH_SEND_PACK; |
| 1476 | else |
| 1477 | state = FETCH_DONE; |
| 1478 | break; |
| 1479 | case FETCH_SEND_PACK: |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1480 | send_wanted_ref_info(&data); |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1481 | send_shallow_info(&data); |
| 1482 | |
Brandon Williams | 3145ea9 | 2018-03-15 10:31:27 -0700 | [diff] [blame] | 1483 | packet_write_fmt(1, "packfile\n"); |
| 1484 | create_pack_file(); |
| 1485 | state = FETCH_DONE; |
| 1486 | break; |
| 1487 | case FETCH_DONE: |
| 1488 | continue; |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | upload_pack_data_clear(&data); |
| 1493 | return 0; |
| 1494 | } |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1495 | |
| 1496 | int upload_pack_advertise(struct repository *r, |
| 1497 | struct strbuf *value) |
| 1498 | { |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 1499 | if (value) { |
| 1500 | int allow_filter_value; |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1501 | int allow_ref_in_want; |
| 1502 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1503 | strbuf_addstr(value, "shallow"); |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1504 | |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 1505 | if (!repo_config_get_bool(the_repository, |
| 1506 | "uploadpack.allowfilter", |
| 1507 | &allow_filter_value) && |
| 1508 | allow_filter_value) |
| 1509 | strbuf_addstr(value, " filter"); |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1510 | |
| 1511 | if (!repo_config_get_bool(the_repository, |
| 1512 | "uploadpack.allowrefinwant", |
| 1513 | &allow_ref_in_want) && |
| 1514 | allow_ref_in_want) |
| 1515 | strbuf_addstr(value, " ref-in-want"); |
Jonathan Tan | ba95710 | 2018-05-03 16:46:56 -0700 | [diff] [blame] | 1516 | } |
Brandon Williams | 516e2b7 | 2018-06-27 15:30:17 -0700 | [diff] [blame] | 1517 | |
Brandon Williams | 685fbd3 | 2018-03-15 10:31:28 -0700 | [diff] [blame] | 1518 | return 1; |
| 1519 | } |