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