]> git.proxmox.com Git - libgit2.git/blob - src/refs.h
Merge branch 'development'
[libgit2.git] / src / refs.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_refs_h__
8 #define INCLUDE_refs_h__
9
10 #include "common.h"
11 #include "git2/oid.h"
12 #include "git2/refs.h"
13 #include "git2/refdb.h"
14 #include "strmap.h"
15 #include "buffer.h"
16 #include "oid.h"
17
18 #define GIT_REFS_DIR "refs/"
19 #define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/"
20 #define GIT_REFS_TAGS_DIR GIT_REFS_DIR "tags/"
21 #define GIT_REFS_REMOTES_DIR GIT_REFS_DIR "remotes/"
22 #define GIT_REFS_DIR_MODE 0777
23 #define GIT_REFS_FILE_MODE 0666
24
25 #define GIT_RENAMED_REF_FILE GIT_REFS_DIR "RENAMED-REF"
26
27 #define GIT_SYMREF "ref: "
28 #define GIT_PACKEDREFS_FILE "packed-refs"
29 #define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled fully-peeled "
30 #define GIT_PACKEDREFS_FILE_MODE 0666
31
32 #define GIT_HEAD_FILE "HEAD"
33 #define GIT_ORIG_HEAD_FILE "ORIG_HEAD"
34 #define GIT_FETCH_HEAD_FILE "FETCH_HEAD"
35 #define GIT_MERGE_HEAD_FILE "MERGE_HEAD"
36 #define GIT_REVERT_HEAD_FILE "REVERT_HEAD"
37 #define GIT_CHERRY_PICK_HEAD_FILE "CHERRY_PICK_HEAD"
38 #define GIT_BISECT_LOG_FILE "BISECT_LOG"
39 #define GIT_REBASE_MERGE_DIR "rebase-merge/"
40 #define GIT_REBASE_MERGE_INTERACTIVE_FILE GIT_REBASE_MERGE_DIR "interactive"
41 #define GIT_REBASE_APPLY_DIR "rebase-apply/"
42 #define GIT_REBASE_APPLY_REBASING_FILE GIT_REBASE_APPLY_DIR "rebasing"
43 #define GIT_REBASE_APPLY_APPLYING_FILE GIT_REBASE_APPLY_DIR "applying"
44 #define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
45
46 #define GIT_STASH_FILE "stash"
47 #define GIT_REFS_STASH_FILE GIT_REFS_DIR GIT_STASH_FILE
48
49 #define GIT_REF_FORMAT__PRECOMPOSE_UNICODE (1u << 16)
50
51 #define GIT_REFNAME_MAX 1024
52
53 struct git_reference {
54 git_refdb *db;
55 git_ref_t type;
56
57 union {
58 git_oid oid;
59 char *symbolic;
60 } target;
61
62 git_oid peel;
63 char name[0];
64 };
65
66 git_reference *git_reference__set_name(git_reference *ref, const char *name);
67
68 int git_reference__normalize_name_lax(char *buffer_out, size_t out_size, const char *name);
69 int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
70 int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid);
71 int git_reference__is_valid_name(const char *refname, unsigned int flags);
72 int git_reference__is_branch(const char *ref_name);
73 int git_reference__is_remote(const char *ref_name);
74 int git_reference__is_tag(const char *ref_name);
75
76 /**
77 * Lookup a reference by name and try to resolve to an OID.
78 *
79 * You can control how many dereferences this will attempt to resolve the
80 * reference with the `max_deref` parameter, or pass -1 to use a sane
81 * default. If you pass 0 for `max_deref`, this will not attempt to resolve
82 * the reference. For any value of `max_deref` other than 0, not
83 * successfully resolving the reference will be reported as an error.
84
85 * The generated reference must be freed by the user.
86 *
87 * @param reference_out Pointer to the looked-up reference
88 * @param repo The repository to look up the reference
89 * @param name The long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
90 * @param max_deref Maximum number of dereferences to make of symbolic refs, 0 means simple lookup, < 0 means use default reasonable value
91 * @return 0 on success or < 0 on error; not being able to resolve the reference is an error unless 0 was passed for max_deref
92 */
93 int git_reference_lookup_resolved(
94 git_reference **reference_out,
95 git_repository *repo,
96 const char *name,
97 int max_deref);
98
99 #endif