]>
Commit | Line | Data |
---|---|---|
dabab1d6 EN |
1 | #ifndef OBJECT_NAME_H |
2 | #define OBJECT_NAME_H | |
3 | ||
4 | #include "object.h" | |
5 | #include "strbuf.h" | |
6 | ||
7 | struct object_id; | |
8 | struct repository; | |
9 | ||
10 | struct object_context { | |
11 | unsigned short mode; | |
12 | /* | |
13 | * symlink_path is only used by get_tree_entry_follow_symlinks, | |
14 | * and only for symlinks that point outside the repository. | |
15 | */ | |
16 | struct strbuf symlink_path; | |
17 | /* | |
18 | * If GET_OID_RECORD_PATH is set, this will record path (if any) | |
19 | * found when resolving the name. The caller is responsible for | |
20 | * releasing the memory. | |
21 | */ | |
22 | char *path; | |
23 | }; | |
24 | ||
25 | /* | |
26 | * Return an abbreviated sha1 unique within this repository's object database. | |
27 | * The result will be at least `len` characters long, and will be NUL | |
28 | * terminated. | |
29 | * | |
30 | * The non-`_r` version returns a static buffer which remains valid until 4 | |
31 | * more calls to repo_find_unique_abbrev are made. | |
32 | * | |
33 | * The `_r` variant writes to a buffer supplied by the caller, which must be at | |
34 | * least `GIT_MAX_HEXSZ + 1` bytes. The return value is the number of bytes | |
35 | * written (excluding the NUL terminator). | |
36 | * | |
37 | * Note that while this version avoids the static buffer, it is not fully | |
38 | * reentrant, as it calls into other non-reentrant git code. | |
39 | */ | |
40 | const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); | |
41 | int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); | |
42 | ||
43 | int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); | |
44 | __attribute__((format (printf, 2, 3))) | |
45 | int get_oidf(struct object_id *oid, const char *fmt, ...); | |
46 | int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid); | |
47 | int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid); | |
48 | int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid); | |
49 | int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid); | |
50 | int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid); | |
51 | int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid); | |
52 | void maybe_die_on_misspelt_object_name(struct repository *repo, | |
53 | const char *name, | |
54 | const char *prefix); | |
55 | enum get_oid_result get_oid_with_context(struct repository *repo, const char *str, | |
56 | unsigned flags, struct object_id *oid, | |
57 | struct object_context *oc); | |
58 | ||
59 | ||
60 | typedef int each_abbrev_fn(const struct object_id *oid, void *); | |
61 | int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *); | |
62 | ||
63 | int set_disambiguate_hint_config(const char *var, const char *value); | |
64 | ||
65 | /* | |
66 | * This reads short-hand syntax that not only evaluates to a commit | |
67 | * object name, but also can act as if the end user spelled the name | |
68 | * of the branch from the command line. | |
69 | * | |
70 | * - "@{-N}" finds the name of the Nth previous branch we were on, and | |
71 | * places the name of the branch in the given buf and returns the | |
72 | * number of characters parsed if successful. | |
73 | * | |
74 | * - "<branch>@{upstream}" finds the name of the other ref that | |
75 | * <branch> is configured to merge with (missing <branch> defaults | |
76 | * to the current branch), and places the name of the branch in the | |
77 | * given buf and returns the number of characters parsed if | |
78 | * successful. | |
79 | * | |
80 | * If the input is not of the accepted format, it returns a negative | |
81 | * number to signal an error. | |
82 | * | |
83 | * If the input was ok but there are not N branch switches in the | |
84 | * reflog, it returns 0. | |
85 | */ | |
86 | #define INTERPRET_BRANCH_LOCAL (1<<0) | |
87 | #define INTERPRET_BRANCH_REMOTE (1<<1) | |
88 | #define INTERPRET_BRANCH_HEAD (1<<2) | |
89 | struct interpret_branch_name_options { | |
90 | /* | |
91 | * If "allowed" is non-zero, it is a treated as a bitfield of allowable | |
92 | * expansions: local branches ("refs/heads/"), remote branches | |
93 | * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is | |
94 | * allowed, even ones to refs outside of those namespaces. | |
95 | */ | |
96 | unsigned allowed; | |
97 | ||
98 | /* | |
99 | * If ^{upstream} or ^{push} (or equivalent) is requested, and the | |
100 | * branch in question does not have such a reference, return -1 instead | |
101 | * of die()-ing. | |
102 | */ | |
103 | unsigned nonfatal_dangling_mark : 1; | |
104 | }; | |
105 | int repo_interpret_branch_name(struct repository *r, | |
106 | const char *str, int len, | |
107 | struct strbuf *buf, | |
108 | const struct interpret_branch_name_options *options); | |
109 | ||
110 | struct object *repo_peel_to_type(struct repository *r, | |
111 | const char *name, int namelen, | |
112 | struct object *o, enum object_type); | |
113 | ||
114 | /* Convert to/from hex/sha1 representation */ | |
115 | #define MINIMUM_ABBREV minimum_abbrev | |
116 | #define DEFAULT_ABBREV default_abbrev | |
117 | ||
118 | /* used when the code does not know or care what the default abbrev is */ | |
119 | #define FALLBACK_DEFAULT_ABBREV 7 | |
120 | ||
121 | #endif /* OBJECT_NAME_H */ |