Git fork
at reftables-rust 139 lines 5.4 kB view raw
1#ifndef OBJECT_NAME_H 2#define OBJECT_NAME_H 3 4#include "object.h" 5#include "strbuf.h" 6 7struct object_id; 8struct repository; 9 10struct 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 25void object_context_release(struct object_context *ctx); 26 27/* 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. 31 * 32 * The non-`_r` version returns a static buffer which remains valid until 4 33 * more calls to repo_find_unique_abbrev are made. 34 * 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). 38 * 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. 41 */ 42const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); 43int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); 44 45/** 46 * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to 47 * the strbuf `sb`. 48 */ 49void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, 50 const struct object_id *oid, int abbrev_len); 51void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, 52 int abbrev_len); 53 54/* 55 * This is like "get_oid_basic()", except it allows "object ID expressions", 56 * notably "xyz^" for "parent of xyz". Accepts GET_OID_* flags. 57 */ 58int repo_get_oid_with_flags(struct repository *r, const char *str, 59 struct object_id *oid, unsigned flags); 60int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); 61__attribute__((format (printf, 2, 3))) 62int get_oidf(struct object_id *oid, const char *fmt, ...); 63int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid); 64int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid); 65int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid); 66int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid); 67int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid); 68int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid); 69void maybe_die_on_misspelt_object_name(struct repository *repo, 70 const char *name, 71 const char *prefix); 72enum get_oid_result get_oid_with_context(struct repository *repo, const char *str, 73 unsigned flags, struct object_id *oid, 74 struct object_context *oc); 75 76 77typedef int each_abbrev_fn(const struct object_id *oid, void *); 78int repo_for_each_abbrev(struct repository *r, const char *prefix, 79 const struct git_hash_algo *algo, each_abbrev_fn, void *); 80 81int set_disambiguate_hint_config(const char *var, const char *value); 82 83/* 84 * This reads short-hand syntax that not only evaluates to a commit 85 * object name, but also can act as if the end user spelled the name 86 * of the branch from the command line. 87 * 88 * - "@{-N}" finds the name of the Nth previous branch we were on, and 89 * places the name of the branch in the given buf and returns the 90 * number of characters parsed if successful. 91 * 92 * - "<branch>@{upstream}" finds the name of the other ref that 93 * <branch> is configured to merge with (missing <branch> defaults 94 * to the current branch), and places the name of the branch in the 95 * given buf and returns the number of characters parsed if 96 * successful. 97 * 98 * If the input is not of the accepted format, it returns a negative 99 * number to signal an error. 100 * 101 * If the input was ok but there are not N branch switches in the 102 * reflog, it returns 0. 103 */ 104#define INTERPRET_BRANCH_LOCAL (1<<0) 105#define INTERPRET_BRANCH_REMOTE (1<<1) 106#define INTERPRET_BRANCH_HEAD (1<<2) 107struct interpret_branch_name_options { 108 /* 109 * If "allowed" is non-zero, it is a treated as a bitfield of allowable 110 * expansions: local branches ("refs/heads/"), remote branches 111 * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is 112 * allowed, even ones to refs outside of those namespaces. 113 */ 114 unsigned allowed; 115 116 /* 117 * If ^{upstream} or ^{push} (or equivalent) is requested, and the 118 * branch in question does not have such a reference, return -1 instead 119 * of die()-ing. 120 */ 121 unsigned nonfatal_dangling_mark : 1; 122}; 123int repo_interpret_branch_name(struct repository *r, 124 const char *str, int len, 125 struct strbuf *buf, 126 const struct interpret_branch_name_options *options); 127 128struct object *repo_peel_to_type(struct repository *r, 129 const char *name, int namelen, 130 struct object *o, enum object_type); 131 132/* Convert to/from hex/sha1 representation */ 133#define MINIMUM_ABBREV minimum_abbrev 134#define DEFAULT_ABBREV default_abbrev 135 136/* used when the code does not know or care what the default abbrev is */ 137#define FALLBACK_DEFAULT_ABBREV 7 138 139#endif /* OBJECT_NAME_H */