resolve_ref(): expand documentation
Record information about resolve_ref(), hard-won via reverse engineering, in a comment for future spelunkers. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f989fea0e0
commit
7cb368421f
34
cache.h
34
cache.h
@ -831,7 +831,39 @@ extern int get_sha1_hex(const char *hex, unsigned char *sha1);
|
|||||||
|
|
||||||
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
|
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
|
||||||
extern int read_ref(const char *filename, unsigned char *sha1);
|
extern int read_ref(const char *filename, unsigned char *sha1);
|
||||||
extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
|
|
||||||
|
/*
|
||||||
|
* Resolve a reference, recursively following symbolic refererences.
|
||||||
|
*
|
||||||
|
* Store the referred-to object's name in sha1 and return the name of
|
||||||
|
* the non-symbolic reference that ultimately pointed at it. The
|
||||||
|
* return value, if not NULL, is a pointer into either a static buffer
|
||||||
|
* or the input ref.
|
||||||
|
*
|
||||||
|
* If the reference cannot be resolved to an object, the behavior
|
||||||
|
* depends on the "reading" argument:
|
||||||
|
*
|
||||||
|
* - If reading is set, return NULL.
|
||||||
|
*
|
||||||
|
* - If reading is not set, clear sha1 and return the name of the last
|
||||||
|
* reference name in the chain, which will either be a non-symbolic
|
||||||
|
* reference or an undefined reference. If this is a prelude to
|
||||||
|
* "writing" to the ref, the return value is the name of the ref
|
||||||
|
* that will actually be created or changed.
|
||||||
|
*
|
||||||
|
* If flag is non-NULL, set the value that it points to the
|
||||||
|
* combination of REF_ISPACKED (if the reference was found among the
|
||||||
|
* packed references) and REF_ISSYMREF (if the initial reference was a
|
||||||
|
* symbolic reference).
|
||||||
|
*
|
||||||
|
* If ref is not a properly-formatted, normalized reference, return
|
||||||
|
* NULL. If more than MAXDEPTH recursive symbolic lookups are needed,
|
||||||
|
* give up and return NULL.
|
||||||
|
*
|
||||||
|
* errno is sometimes set on errors, but not always.
|
||||||
|
*/
|
||||||
|
extern const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag);
|
||||||
|
|
||||||
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
|
extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
|
||||||
extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
|
extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
|
||||||
extern int interpret_branch_name(const char *str, struct strbuf *);
|
extern int interpret_branch_name(const char *str, struct strbuf *);
|
||||||
|
12
refs.c
12
refs.c
@ -482,18 +482,6 @@ static int get_packed_ref(const char *ref, unsigned char *sha1)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If the "reading" argument is set, this function finds out what _object_
|
|
||||||
* the ref points at by "reading" the ref. The ref, if it is not symbolic,
|
|
||||||
* has to exist, and if it is symbolic, it has to point at an existing ref,
|
|
||||||
* because the "read" goes through the symref to the ref it points at.
|
|
||||||
*
|
|
||||||
* The access that is not "reading" may often be "writing", but does not
|
|
||||||
* have to; it can be merely checking _where it leads to_. If it is a
|
|
||||||
* prelude to "writing" to the ref, a write to a symref that points at
|
|
||||||
* yet-to-be-born ref will create the real ref pointed by the symref.
|
|
||||||
* reading=0 allows the caller to check where such a symref leads to.
|
|
||||||
*/
|
|
||||||
const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)
|
const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *flag)
|
||||||
{
|
{
|
||||||
int depth = MAXDEPTH;
|
int depth = MAXDEPTH;
|
||||||
|
Loading…
Reference in New Issue
Block a user