refs: move the remaining ref module declarations to refs.h
Some functions from the refs module were still declared in cache.h. Move them to refs.h. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 22, 2015 at 16:03 UTC
fb58c8d50734c14a90f3e4e7dd99f36e4f37c4e6
10 files changed
+109
-91
archive.c
+1
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "refs.h"
3
#include "commit.h"
4
#include "tree-walk.h"
5
#include "attr.h"
builtin/blame.c
+1
@@ -6,6 +6,7 @@
6
*/
7
8
#include "cache.h"
9
+#include "refs.h"
10
#include "builtin.h"
11
#include "blob.h"
12
#include "commit.h"
builtin/fast-export.c
+1
@@ -5,6 +5,7 @@
5
*/
6
#include "builtin.h"
7
#include "cache.h"
8
+#include "refs.h"
9
#include "commit.h"
10
#include "object.h"
11
#include "tag.h"
builtin/fmt-merge-msg.c
+1
@@ -1,5 +1,6 @@
1
#include "builtin.h"
2
#include "cache.h"
3
+#include "refs.h"
4
#include "commit.h"
5
#include "diff.h"
6
#include "revision.h"
builtin/init-db.c
+1
@@ -4,6 +4,7 @@
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
#include "cache.h"
7
+#include "refs.h"
8
#include "builtin.h"
9
#include "exec_cmd.h"
10
#include "parse-options.h"
builtin/log.c
+1
@@ -5,6 +5,7 @@
5
* 2006 Junio Hamano
6
*/
7
#include "cache.h"
8
+#include "refs.h"
9
#include "color.h"
10
#include "commit.h"
11
#include "diff.h"
cache.h
-66
@@ -1009,76 +1009,10 @@ extern int get_oid_hex(const char *hex, struct object_id *sha1);
1009
1010
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
1011
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
1012
-extern int read_ref_full(const char *refname, int resolve_flags,
1013
- unsigned char *sha1, int *flags);
1014
-extern int read_ref(const char *refname, unsigned char *sha1);
1012
1016
-/*
1017
- * Resolve a reference, recursively following symbolic refererences.
1018
- *
1019
- * Store the referred-to object's name in sha1 and return the name of
1020
- * the non-symbolic reference that ultimately pointed at it. The
1021
- * return value, if not NULL, is a pointer into either a static buffer
1022
- * or the input ref.
1023
- *
1024
- * If the reference cannot be resolved to an object, the behavior
1025
- * depends on the RESOLVE_REF_READING flag:
1026
- *
1027
- * - If RESOLVE_REF_READING is set, return NULL.
1028
- *
1029
- * - If RESOLVE_REF_READING is not set, clear sha1 and return the name of
1030
- * the last reference name in the chain, which will either be a non-symbolic
1031
- * reference or an undefined reference. If this is a prelude to
1032
- * "writing" to the ref, the return value is the name of the ref
1033
- * that will actually be created or changed.
1034
- *
1035
- * If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
1036
- * level of symbolic reference. The value stored in sha1 for a symbolic
1037
- * reference will always be null_sha1 in this case, and the return
1038
- * value is the reference that the symref refers to directly.
1039
- *
1040
- * If flags is non-NULL, set the value that it points to the
1041
- * combination of REF_ISPACKED (if the reference was found among the
1042
- * packed references), REF_ISSYMREF (if the initial reference was a
1043
- * symbolic reference), REF_BAD_NAME (if the reference name is ill
1044
- * formed --- see RESOLVE_REF_ALLOW_BAD_NAME below), and REF_ISBROKEN
1045
- * (if the ref is malformed or has a bad name). See refs.h for more detail
1046
- * on each flag.
1047
- *
1048
- * If ref is not a properly-formatted, normalized reference, return
1049
- * NULL. If more than MAXDEPTH recursive symbolic lookups are needed,
1050
- * give up and return NULL.
1051
- *
1052
- * RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
1053
- * name is invalid according to git-check-ref-format(1). If the name
1054
- * is bad then the value stored in sha1 will be null_sha1 and the two
1055
- * flags REF_ISBROKEN and REF_BAD_NAME will be set.
1056
- *
1057
- * Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
1058
- * directory and do not consist of all caps and underscores cannot be
1059
- * resolved. The function returns NULL for such ref names.
1060
- * Caps and underscores refers to the special refs, such as HEAD,
1061
- * FETCH_HEAD and friends, that all live outside of the refs/ directory.
1062
- */
1063
-#define RESOLVE_REF_READING 0x01
1064
-#define RESOLVE_REF_NO_RECURSE 0x02
1065
-#define RESOLVE_REF_ALLOW_BAD_NAME 0x04
1066
-extern const char *resolve_ref_unsafe(const char *ref, int resolve_flags, unsigned char *sha1, int *flags);
1067
-extern char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, int *flags);
1068
-
1069
-extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
1070
-extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
1013
extern int interpret_branch_name(const char *str, int len, struct strbuf *);
1014
extern int get_sha1_mb(const char *str, unsigned char *sha1);
1015
1074
-/*
1075
- * Return true iff abbrev_name is a possible abbreviation for
1076
- * full_name according to the rules defined by ref_rev_parse_rules in
1077
- * refs.c.
1078
- */
1079
-extern int refname_match(const char *abbrev_name, const char *full_name);
1080
-
1081
-extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg);
1016
extern int validate_headref(const char *ref);
1017
1018
extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
refs.c
+4
-2
@@ -1732,9 +1732,11 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
1732
return ret;
1733
}
1734
1735
-char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, int *flags)
1735
+char *resolve_refdup(const char *refname, int resolve_flags,
1736
+ unsigned char *sha1, int *flags)
1737
{
1737
- return xstrdup_or_null(resolve_ref_unsafe(ref, resolve_flags, sha1, flags));
1738
+ return xstrdup_or_null(resolve_ref_unsafe(refname, resolve_flags,
1739
+ sha1, flags));
1740
}
1741
1742
/* The argument to filter_refs */
refs.h
+98
-23
@@ -1,6 +1,98 @@
1
#ifndef REFS_H
2
#define REFS_H
3
4
+/*
5
+ * Resolve a reference, recursively following symbolic refererences.
6
+ *
7
+ * Store the referred-to object's name in sha1 and return the name of
8
+ * the non-symbolic reference that ultimately pointed at it. The
9
+ * return value, if not NULL, is a pointer into either a static buffer
10
+ * or the input ref.
11
+ *
12
+ * If the reference cannot be resolved to an object, the behavior
13
+ * depends on the RESOLVE_REF_READING flag:
14
+ *
15
+ * - If RESOLVE_REF_READING is set, return NULL.
16
+ *
17
+ * - If RESOLVE_REF_READING is not set, clear sha1 and return the name of
18
+ * the last reference name in the chain, which will either be a non-symbolic
19
+ * reference or an undefined reference. If this is a prelude to
20
+ * "writing" to the ref, the return value is the name of the ref
21
+ * that will actually be created or changed.
22
+ *
23
+ * If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
24
+ * level of symbolic reference. The value stored in sha1 for a symbolic
25
+ * reference will always be null_sha1 in this case, and the return
26
+ * value is the reference that the symref refers to directly.
27
+ *
28
+ * If flags is non-NULL, set the value that it points to the
29
+ * combination of REF_ISPACKED (if the reference was found among the
30
+ * packed references), REF_ISSYMREF (if the initial reference was a
31
+ * symbolic reference), REF_BAD_NAME (if the reference name is ill
32
+ * formed --- see RESOLVE_REF_ALLOW_BAD_NAME below), and REF_ISBROKEN
33
+ * (if the ref is malformed or has a bad name). See refs.h for more detail
34
+ * on each flag.
35
+ *
36
+ * If ref is not a properly-formatted, normalized reference, return
37
+ * NULL. If more than MAXDEPTH recursive symbolic lookups are needed,
38
+ * give up and return NULL.
39
+ *
40
+ * RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
41
+ * name is invalid according to git-check-ref-format(1). If the name
42
+ * is bad then the value stored in sha1 will be null_sha1 and the two
43
+ * flags REF_ISBROKEN and REF_BAD_NAME will be set.
44
+ *
45
+ * Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
46
+ * directory and do not consist of all caps and underscores cannot be
47
+ * resolved. The function returns NULL for such ref names.
48
+ * Caps and underscores refers to the special refs, such as HEAD,
49
+ * FETCH_HEAD and friends, that all live outside of the refs/ directory.
50
+ */
51
+#define RESOLVE_REF_READING 0x01
52
+#define RESOLVE_REF_NO_RECURSE 0x02
53
+#define RESOLVE_REF_ALLOW_BAD_NAME 0x04
54
+
55
+extern const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
56
+ unsigned char *sha1, int *flags);
57
+
58
+extern char *resolve_refdup(const char *refname, int resolve_flags,
59
+ unsigned char *sha1, int *flags);
60
+
61
+extern int read_ref_full(const char *refname, int resolve_flags,
62
+ unsigned char *sha1, int *flags);
63
+extern int read_ref(const char *refname, unsigned char *sha1);
64
+
65
+extern int ref_exists(const char *);
66
+
67
+extern int is_branch(const char *refname);
68
+
69
+/*
70
+ * If refname is a non-symbolic reference that refers to a tag object,
71
+ * and the tag can be (recursively) dereferenced to a non-tag object,
72
+ * store the SHA1 of the referred-to object to sha1 and return 0. If
73
+ * any of these conditions are not met, return a non-zero value.
74
+ * Symbolic references are considered unpeelable, even if they
75
+ * ultimately resolve to a peelable tag.
76
+ */
77
+extern int peel_ref(const char *refname, unsigned char *sha1);
78
+
79
+/**
80
+ * Resolve refname in the nested "gitlink" repository that is located
81
+ * at path. If the resolution is successful, return 0 and set sha1 to
82
+ * the name of the object; otherwise, return a non-zero value.
83
+ */
84
+extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1);
85
+
86
+/*
87
+ * Return true iff abbrev_name is a possible abbreviation for
88
+ * full_name according to the rules defined by ref_rev_parse_rules in
89
+ * refs.c.
90
+ */
91
+extern int refname_match(const char *abbrev_name, const char *full_name);
92
+
93
+extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
94
+extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
95
+
96
/*
97
* A ref_transaction represents a collection of ref updates
98
* that should succeed or fail together.
@@ -99,14 +191,14 @@ extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn,
191
extern int head_ref_namespaced(each_ref_fn fn, void *cb_data);
192
extern int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);
193
194
+/* can be used to learn about broken ref and symref */
195
+extern int for_each_rawref(each_ref_fn, void *);
196
+
197
static inline const char *has_glob_specials(const char *pattern)
198
{
199
return strpbrk(pattern, "?*[");
200
}
201
107
-/* can be used to learn about broken ref and symref */
108
-extern int for_each_rawref(each_ref_fn, void *);
109
-
202
extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname);
203
extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames);
204
@@ -124,20 +216,6 @@ extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct st
216
*/
217
int pack_refs(unsigned int flags);
218
127
-extern int ref_exists(const char *);
128
-
129
-extern int is_branch(const char *refname);
130
-
131
-/*
132
- * If refname is a non-symbolic reference that refers to a tag object,
133
- * and the tag can be (recursively) dereferenced to a non-tag object,
134
- * store the SHA1 of the referred-to object to sha1 and return 0. If
135
- * any of these conditions are not met, return a non-zero value.
136
- * Symbolic references are considered unpeelable, even if they
137
- * ultimately resolve to a peelable tag.
138
- */
139
-extern int peel_ref(const char *refname, unsigned char *sha1);
140
-
219
/*
220
* Flags controlling ref_transaction_update(), ref_transaction_create(), etc.
221
* REF_NODEREF: act on the ref directly, instead of dereferencing
@@ -206,17 +284,13 @@ extern int for_each_reflog(each_ref_fn, void *);
284
extern int check_refname_format(const char *refname, int flags);
285
286
extern const char *prettify_refname(const char *refname);
287
+
288
extern char *shorten_unambiguous_ref(const char *refname, int strict);
289
290
/** rename ref, return 0 on success **/
291
extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
292
214
-/**
215
- * Resolve refname in the nested "gitlink" repository that is located
216
- * at path. If the resolution is successful, return 0 and set sha1 to
217
- * the name of the object; otherwise, return a non-zero value.
218
- */
219
-extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1);
293
+extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg);
294
295
enum action_on_err {
296
UPDATE_REFS_MSG_ON_ERR,
@@ -367,6 +441,7 @@ int update_ref(const char *msg, const char *refname,
441
unsigned int flags, enum action_on_err onerr);
442
443
extern int parse_hide_refs_config(const char *var, const char *value, const char *);
444
+
445
extern int ref_is_hidden(const char *);
446
447
enum expire_reflog_flags {
remote-testsvn.c
+1
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "refs.h"
3
#include "remote.h"
4
#include "strbuf.h"
5
#include "url.h"