|
6 | 6 | #include "tag.h" |
7 | 7 | #include "object.h" |
8 | 8 | #include "commit.h" |
9 | | -#include "exec_cmd.h" |
10 | 9 | #include "diff.h" |
11 | 10 | #include "revision.h" |
12 | 11 | #include "list-objects.h" |
|
15 | 14 | #include "sigchain.h" |
16 | 15 | #include "version.h" |
17 | 16 | #include "string-list.h" |
18 | | -#include "parse-options.h" |
19 | 17 | #include "argv-array.h" |
20 | 18 | #include "prio-queue.h" |
21 | 19 | #include "protocol.h" |
22 | | - |
23 | | -static const char * const upload_pack_usage[] = { |
24 | | - N_("git upload-pack [<options>] <dir>"), |
25 | | - NULL |
26 | | -}; |
| 20 | +#include "upload-pack.h" |
27 | 21 |
|
28 | 22 | /* Remember to update object flag allocation in object.h */ |
29 | 23 | #define THEY_HAVE (1u << 11) |
@@ -61,7 +55,6 @@ static int keepalive = 5; |
61 | 55 | * otherwise maximum packet size (up to 65520 bytes). |
62 | 56 | */ |
63 | 57 | static int use_sideband; |
64 | | -static int advertise_refs; |
65 | 58 | static int stateless_rpc; |
66 | 59 | static const char *pack_objects_hook; |
67 | 60 |
|
@@ -977,33 +970,6 @@ static int find_symref(const char *refname, const struct object_id *oid, |
977 | 970 | return 0; |
978 | 971 | } |
979 | 972 |
|
980 | | -static void upload_pack(void) |
981 | | -{ |
982 | | - struct string_list symref = STRING_LIST_INIT_DUP; |
983 | | - |
984 | | - head_ref_namespaced(find_symref, &symref); |
985 | | - |
986 | | - if (advertise_refs || !stateless_rpc) { |
987 | | - reset_timeout(); |
988 | | - head_ref_namespaced(send_ref, &symref); |
989 | | - for_each_namespaced_ref(send_ref, &symref); |
990 | | - advertise_shallow_grafts(1); |
991 | | - packet_flush(1); |
992 | | - } else { |
993 | | - head_ref_namespaced(check_ref, NULL); |
994 | | - for_each_namespaced_ref(check_ref, NULL); |
995 | | - } |
996 | | - string_list_clear(&symref, 1); |
997 | | - if (advertise_refs) |
998 | | - return; |
999 | | - |
1000 | | - receive_needs(); |
1001 | | - if (want_obj.nr) { |
1002 | | - get_common_commits(); |
1003 | | - create_pack_file(); |
1004 | | - } |
1005 | | -} |
1006 | | - |
1007 | 973 | static int upload_pack_config(const char *var, const char *value, void *unused) |
1008 | 974 | { |
1009 | 975 | if (!strcmp("uploadpack.allowtipsha1inwant", var)) { |
@@ -1032,58 +998,35 @@ static int upload_pack_config(const char *var, const char *value, void *unused) |
1032 | 998 | return parse_hide_refs_config(var, value, "uploadpack"); |
1033 | 999 | } |
1034 | 1000 |
|
1035 | | -int cmd_main(int argc, const char **argv) |
| 1001 | +void upload_pack(struct upload_pack_options *options) |
1036 | 1002 | { |
1037 | | - const char *dir; |
1038 | | - int strict = 0; |
1039 | | - struct option options[] = { |
1040 | | - OPT_BOOL(0, "stateless-rpc", &stateless_rpc, |
1041 | | - N_("quit after a single request/response exchange")), |
1042 | | - OPT_BOOL(0, "advertise-refs", &advertise_refs, |
1043 | | - N_("exit immediately after initial ref advertisement")), |
1044 | | - OPT_BOOL(0, "strict", &strict, |
1045 | | - N_("do not try <directory>/.git/ if <directory> is no Git directory")), |
1046 | | - OPT_INTEGER(0, "timeout", &timeout, |
1047 | | - N_("interrupt transfer after <n> seconds of inactivity")), |
1048 | | - OPT_END() |
1049 | | - }; |
1050 | | - |
1051 | | - packet_trace_identity("upload-pack"); |
1052 | | - check_replace_refs = 0; |
1053 | | - |
1054 | | - argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0); |
1055 | | - |
1056 | | - if (argc != 1) |
1057 | | - usage_with_options(upload_pack_usage, options); |
1058 | | - |
1059 | | - if (timeout) |
1060 | | - daemon_mode = 1; |
1061 | | - |
1062 | | - setup_path(); |
1063 | | - |
1064 | | - dir = argv[0]; |
| 1003 | + struct string_list symref = STRING_LIST_INIT_DUP; |
1065 | 1004 |
|
1066 | | - if (!enter_repo(dir, strict)) |
1067 | | - die("'%s' does not appear to be a git repository", dir); |
| 1005 | + stateless_rpc = options->stateless_rpc; |
| 1006 | + timeout = options->timeout; |
| 1007 | + daemon_mode = options->daemon_mode; |
1068 | 1008 |
|
1069 | 1009 | git_config(upload_pack_config, NULL); |
1070 | 1010 |
|
1071 | | - switch (determine_protocol_version_server()) { |
1072 | | - case protocol_v1: |
1073 | | - /* |
1074 | | - * v1 is just the original protocol with a version string, |
1075 | | - * so just fall through after writing the version string. |
1076 | | - */ |
1077 | | - if (advertise_refs || !stateless_rpc) |
1078 | | - packet_write_fmt(1, "version 1\n"); |
1079 | | - |
1080 | | - /* fallthrough */ |
1081 | | - case protocol_v0: |
1082 | | - upload_pack(); |
1083 | | - break; |
1084 | | - case protocol_unknown_version: |
1085 | | - BUG("unknown protocol version"); |
| 1011 | + head_ref_namespaced(find_symref, &symref); |
| 1012 | + |
| 1013 | + if (options->advertise_refs || !stateless_rpc) { |
| 1014 | + reset_timeout(); |
| 1015 | + head_ref_namespaced(send_ref, &symref); |
| 1016 | + for_each_namespaced_ref(send_ref, &symref); |
| 1017 | + advertise_shallow_grafts(1); |
| 1018 | + packet_flush(1); |
| 1019 | + } else { |
| 1020 | + head_ref_namespaced(check_ref, NULL); |
| 1021 | + for_each_namespaced_ref(check_ref, NULL); |
1086 | 1022 | } |
| 1023 | + string_list_clear(&symref, 1); |
| 1024 | + if (options->advertise_refs) |
| 1025 | + return; |
1087 | 1026 |
|
1088 | | - return 0; |
| 1027 | + receive_needs(); |
| 1028 | + if (want_obj.nr) { |
| 1029 | + get_common_commits(); |
| 1030 | + create_pack_file(); |
| 1031 | + } |
1089 | 1032 | } |
0 commit comments