cache.h: move remote/connect API out of it

The definition of "struct ref" in "cache.h", a header file so central to the system, always confused me. This structure is not about the local ref used by sha1-name API to name local objects. It is what refspecs are expanded into, after finding out what refs the other side has, to define what refs are updated after object transfer succeeds to what values. It belongs to "remote.h" together with "struct refspec". While we are at it, also move the types and functions related to the Git transport connection to a new header file connect.h Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 8, 2013 at 13:56 UTC 47a59185369b8905ad3a4012688cba92fd2ac1ff
15 files changed +87 -70
builtin/fetch-pack.c
+2
@@ -1,6 +1,8 @@
1 #include "builtin.h"
2 #include "pkt-line.h"
3 #include "fetch-pack.h"
4 +#include "remote.h"
5 +#include "connect.h"
6
7 static const char fetch_pack_usage[] =
8 "git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
builtin/receive-pack.c
+1
@@ -8,6 +8,7 @@
8 #include "commit.h"
9 #include "object.h"
10 #include "remote.h"
11 +#include "connect.h"
12 #include "transport.h"
13 #include "string-list.h"
14 #include "sha1-array.h"
builtin/send-pack.c
+1
@@ -5,6 +5,7 @@
5 #include "sideband.h"
6 #include "run-command.h"
7 #include "remote.h"
8 +#include "connect.h"
9 #include "send-pack.h"
10 #include "quote.h"
11 #include "transport.h"
cache.h
-62
@@ -1035,68 +1035,6 @@ struct pack_entry {
1035 struct packed_git *p;
1036 };
1037
1038 -struct ref {
1039 - struct ref *next;
1040 - unsigned char old_sha1[20];
1041 - unsigned char new_sha1[20];
1042 - char *symref;
1043 - unsigned int
1044 - force:1,
1045 - forced_update:1,
1046 - deletion:1,
1047 - matched:1;
1048 -
1049 - /*
1050 - * Order is important here, as we write to FETCH_HEAD
1051 - * in numeric order. And the default NOT_FOR_MERGE
1052 - * should be 0, so that xcalloc'd structures get it
1053 - * by default.
1054 - */
1055 - enum {
1056 - FETCH_HEAD_MERGE = -1,
1057 - FETCH_HEAD_NOT_FOR_MERGE = 0,
1058 - FETCH_HEAD_IGNORE = 1
1059 - } fetch_head_status;
1060 -
1061 - enum {
1062 - REF_STATUS_NONE = 0,
1063 - REF_STATUS_OK,
1064 - REF_STATUS_REJECT_NONFASTFORWARD,
1065 - REF_STATUS_REJECT_ALREADY_EXISTS,
1066 - REF_STATUS_REJECT_NODELETE,
1067 - REF_STATUS_REJECT_FETCH_FIRST,
1068 - REF_STATUS_REJECT_NEEDS_FORCE,
1069 - REF_STATUS_UPTODATE,
1070 - REF_STATUS_REMOTE_REJECT,
1071 - REF_STATUS_EXPECTING_REPORT
1072 - } status;
1073 - char *remote_status;
1074 - struct ref *peer_ref; /* when renaming */
1075 - char name[FLEX_ARRAY]; /* more */
1076 -};
1077 -
1078 -#define REF_NORMAL (1u << 0)
1079 -#define REF_HEADS (1u << 1)
1080 -#define REF_TAGS (1u << 2)
1081 -
1082 -extern struct ref *find_ref_by_name(const struct ref *list, const char *name);
1083 -
1084 -#define CONNECT_VERBOSE (1u << 0)
1085 -extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
1086 -extern int finish_connect(struct child_process *conn);
1087 -extern int git_connection_is_socket(struct child_process *conn);
1088 -struct extra_have_objects {
1089 - int nr, alloc;
1090 - unsigned char (*array)[20];
1091 -};
1092 -extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
1093 - struct ref **list, unsigned int flags,
1094 - struct extra_have_objects *);
1095 -extern int server_supports(const char *feature);
1096 -extern int parse_feature_request(const char *features, const char *feature);
1097 -extern const char *server_feature_value(const char *feature, int *len_ret);
1098 -extern const char *parse_feature_value(const char *feature_list, const char *feature, int *len_ret);
1099 -
1038 extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
1039
1040 /* A hook for count-objects to report invalid files in pack directory */
connect.c
+1
@@ -5,6 +5,7 @@
5 #include "refs.h"
6 #include "run-command.h"
7 #include "remote.h"
8 +#include "connect.h"
9 #include "url.h"
10
11 static char *server_capabilities;
connect.h new
+13
@@ -0,0 +1,13 @@
1 +#ifndef CONNECT_H
2 +#define CONNECT_H
3 +
4 +#define CONNECT_VERBOSE (1u << 0)
5 +extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
6 +extern int finish_connect(struct child_process *conn);
7 +extern int git_connection_is_socket(struct child_process *conn);
8 +extern int server_supports(const char *feature);
9 +extern int parse_feature_request(const char *features, const char *feature);
10 +extern const char *server_feature_value(const char *feature, int *len_ret);
11 +extern const char *parse_feature_value(const char *feature_list, const char *feature, int *len_ret);
12 +
13 +#endif
fetch-pack.c
+1
@@ -9,6 +9,7 @@
9 #include "fetch-pack.h"
10 #include "remote.h"
11 #include "run-command.h"
12 +#include "connect.h"
13 #include "transport.h"
14 #include "version.h"
15
fetch-pack.h
+1
@@ -2,6 +2,7 @@
2 #define FETCH_PACK_H
3
4 #include "string-list.h"
5 +#include "run-command.h"
6
7 struct fetch_pack_args {
8 const char *uploadpack;
refs.c
-8
@@ -3193,14 +3193,6 @@ int update_ref(const char *action, const char *refname,
3193 return 0;
3194 }
3195
3196 -struct ref *find_ref_by_name(const struct ref *list, const char *name)
3197 -{
3198 - for ( ; list; list = list->next)
3199 - if (!strcmp(list->name, name))
3200 - return (struct ref *)list;
3201 - return NULL;
3202 -}
3203 -
3196 /*
3197 * generate a format suitable for scanf from a ref_rev_parse_rules
3198 * rule, that is replace the "%.*s" spec with a "%s" spec
remote.c
+8
@@ -1302,6 +1302,14 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
1302 free(sent_tips.tip);
1303 }
1304
1305 +struct ref *find_ref_by_name(const struct ref *list, const char *name)
1306 +{
1307 + for ( ; list; list = list->next)
1308 + if (!strcmp(list->name, name))
1309 + return (struct ref *)list;
1310 + return NULL;
1311 +}
1312 +
1313 /*
1314 * Given the set of refs the local repository has, the set of refs the
1315 * remote repository has, and the refspec used for push, determine
remote.h
+54
@@ -71,6 +71,52 @@ struct refspec {
71
72 extern const struct refspec *tag_refspec;
73
74 +struct ref {
75 + struct ref *next;
76 + unsigned char old_sha1[20];
77 + unsigned char new_sha1[20];
78 + char *symref;
79 + unsigned int
80 + force:1,
81 + forced_update:1,
82 + deletion:1,
83 + matched:1;
84 +
85 + /*
86 + * Order is important here, as we write to FETCH_HEAD
87 + * in numeric order. And the default NOT_FOR_MERGE
88 + * should be 0, so that xcalloc'd structures get it
89 + * by default.
90 + */
91 + enum {
92 + FETCH_HEAD_MERGE = -1,
93 + FETCH_HEAD_NOT_FOR_MERGE = 0,
94 + FETCH_HEAD_IGNORE = 1
95 + } fetch_head_status;
96 +
97 + enum {
98 + REF_STATUS_NONE = 0,
99 + REF_STATUS_OK,
100 + REF_STATUS_REJECT_NONFASTFORWARD,
101 + REF_STATUS_REJECT_ALREADY_EXISTS,
102 + REF_STATUS_REJECT_NODELETE,
103 + REF_STATUS_REJECT_FETCH_FIRST,
104 + REF_STATUS_REJECT_NEEDS_FORCE,
105 + REF_STATUS_UPTODATE,
106 + REF_STATUS_REMOTE_REJECT,
107 + REF_STATUS_EXPECTING_REPORT
108 + } status;
109 + char *remote_status;
110 + struct ref *peer_ref; /* when renaming */
111 + char name[FLEX_ARRAY]; /* more */
112 +};
113 +
114 +#define REF_NORMAL (1u << 0)
115 +#define REF_HEADS (1u << 1)
116 +#define REF_TAGS (1u << 2)
117 +
118 +extern struct ref *find_ref_by_name(const struct ref *list, const char *name);
119 +
120 struct ref *alloc_ref(const char *name);
121 struct ref *copy_ref(const struct ref *ref);
122 struct ref *copy_ref_list(const struct ref *ref);
@@ -84,6 +130,14 @@ int check_ref_type(const struct ref *ref, int flags);
130 */
131 void free_refs(struct ref *ref);
132
133 +struct extra_have_objects {
134 + int nr, alloc;
135 + unsigned char (*array)[20];
136 +};
137 +extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
138 + struct ref **list, unsigned int flags,
139 + struct extra_have_objects *);
140 +
141 int resolve_remote_symref(struct ref *ref, struct ref *list);
142 int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
143
send-pack.c
+1
@@ -5,6 +5,7 @@
5 #include "sideband.h"
6 #include "run-command.h"
7 #include "remote.h"
8 +#include "connect.h"
9 #include "send-pack.h"
10 #include "quote.h"
11 #include "transport.h"
transport.c
+2
@@ -3,6 +3,8 @@
3 #include "run-command.h"
4 #include "pkt-line.h"
5 #include "fetch-pack.h"
6 +#include "remote.h"
7 +#include "connect.h"
8 #include "send-pack.h"
9 #include "walker.h"
10 #include "bundle.h"
transport.h
+1
@@ -2,6 +2,7 @@
2 #define TRANSPORT_H
3
4 #include "cache.h"
5 +#include "run-command.h"
6 #include "remote.h"
7
8 struct git_transport_options {
upload-pack.c
+1
@@ -10,6 +10,7 @@
10 #include "revision.h"
11 #include "list-objects.h"
12 #include "run-command.h"
13 +#include "connect.h"
14 #include "sigchain.h"
15 #include "version.h"
16 #include "string-list.h"