Skip to content

Commit 47a5918

Browse files
committed
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 <[email protected]>
1 parent f8abaeb commit 47a5918

15 files changed

+87
-70
lines changed

builtin/fetch-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "builtin.h"
22
#include "pkt-line.h"
33
#include "fetch-pack.h"
4+
#include "remote.h"
5+
#include "connect.h"
46

57
static const char fetch_pack_usage[] =
68
"git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "

builtin/receive-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "commit.h"
99
#include "object.h"
1010
#include "remote.h"
11+
#include "connect.h"
1112
#include "transport.h"
1213
#include "string-list.h"
1314
#include "sha1-array.h"

builtin/send-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "sideband.h"
66
#include "run-command.h"
77
#include "remote.h"
8+
#include "connect.h"
89
#include "send-pack.h"
910
#include "quote.h"
1011
#include "transport.h"

cache.h

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,68 +1035,6 @@ struct pack_entry {
10351035
struct packed_git *p;
10361036
};
10371037

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-
11001038
extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
11011039

11021040
/* A hook for count-objects to report invalid files in pack directory */

connect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "refs.h"
66
#include "run-command.h"
77
#include "remote.h"
8+
#include "connect.h"
89
#include "url.h"
910

1011
static char *server_capabilities;

connect.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "fetch-pack.h"
1010
#include "remote.h"
1111
#include "run-command.h"
12+
#include "connect.h"
1213
#include "transport.h"
1314
#include "version.h"
1415

fetch-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define FETCH_PACK_H
33

44
#include "string-list.h"
5+
#include "run-command.h"
56

67
struct fetch_pack_args {
78
const char *uploadpack;

refs.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,14 +3193,6 @@ int update_ref(const char *action, const char *refname,
31933193
return 0;
31943194
}
31953195

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-
32043196
/*
32053197
* generate a format suitable for scanf from a ref_rev_parse_rules
32063198
* rule, that is replace the "%.*s" spec with a "%s" spec

remote.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,14 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds
13021302
free(sent_tips.tip);
13031303
}
13041304

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+
13051313
/*
13061314
* Given the set of refs the local repository has, the set of refs the
13071315
* remote repository has, and the refspec used for push, determine

0 commit comments

Comments
 (0)