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 /**
8  * License: GPL-2.0(Linking Exception)
9  */
10 module libgit2.revparse;
11 
12 
13 private static import libgit2.types;
14 private import libgit2.common: GIT_EXTERN;
15 
16 /*
17  * @file git2/revparse.h
18  * @brief Git revision parsing routines
19  * @defgroup git_revparse Git revision parsing routines
20  * @ingroup Git
21  * @{
22  */
23 extern (C):
24 nothrow @nogc:
25 public:
26 
27 /**
28  * Find a single object, as specified by a revision string.
29  *
30  * See `man gitrevisions`, or
31  * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for
32  * information on the syntax accepted.
33  *
34  * The returned object should be released with `git_object_free` when no
35  * longer needed.
36  *
37  * Params:
38  *      out_ = pointer to output object
39  *      repo = the repository to search in
40  *      spec = the textual specification for an object
41  *
42  * Returns: 0 on success, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EAMBIGUOUS, git_error_code.GIT_EINVALIDSPEC or an error code
43  */
44 @GIT_EXTERN
45 int git_revparse_single(libgit2.types.git_object** out_, libgit2.types.git_repository* repo, const (char)* spec);
46 
47 /**
48  * Find a single object and intermediate reference by a revision string.
49  *
50  * See `man gitrevisions`, or
51  * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for
52  * information on the syntax accepted.
53  *
54  * In some cases (`@{<-n>}` or `<branchname>@{upstream}`), the expression may
55  * point to an intermediate reference. When such expressions are being passed
56  * in, `reference_out` will be valued as well.
57  *
58  * The returned object should be released with `git_object_free` and the
59  * returned reference with `git_reference_free` when no longer needed.
60  *
61  * Params:
62  *      object_out = pointer to output object
63  *      reference_out = pointer to output reference or null
64  *      repo = the repository to search in
65  *      spec = the textual specification for an object
66  *
67  * Returns: 0 on success, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EAMBIGUOUS, git_error_code.GIT_EINVALIDSPEC or an error code
68  */
69 @GIT_EXTERN
70 int git_revparse_ext(libgit2.types.git_object** object_out, libgit2.types.git_reference** reference_out, libgit2.types.git_repository* repo, const (char)* spec);
71 
72 /**
73  * Revparse flags.  These indicate the intended behavior of the spec passed to
74  * git_revparse.
75  */
76 enum git_revspec_t
77 {
78 	/**
79 	 * The spec targeted a single object.
80 	 */
81 	GIT_REVSPEC_SINGLE = 1 << 0,
82 
83 	/**
84 	 * The spec targeted a range of commits.
85 	 */
86 	GIT_REVSPEC_RANGE = 1 << 1,
87 
88 	/**
89 	 * The spec used the '...' operator, which invokes special semantics.
90 	 */
91 	GIT_REVSPEC_MERGE_BASE = 1 << 2,
92 }
93 
94 //Declaration name in C language
95 enum
96 {
97 	GIT_REVSPEC_SINGLE = .git_revspec_t.GIT_REVSPEC_SINGLE,
98 	GIT_REVSPEC_RANGE = .git_revspec_t.GIT_REVSPEC_RANGE,
99 	GIT_REVSPEC_MERGE_BASE = .git_revspec_t.GIT_REVSPEC_MERGE_BASE,
100 }
101 
102 /**
103  * Git Revision Spec: output of a `git_revparse` operation
104  */
105 struct git_revspec
106 {
107 	/**
108 	 * The left element of the revspec; must be freed by the user
109 	 */
110 	libgit2.types.git_object* from;
111 
112 	/**
113 	 * The right element of the revspec; must be freed by the user
114 	 */
115 	libgit2.types.git_object* to;
116 
117 	/**
118 	 * The intent of the revspec (i.e. `git_revspec_mode_t` flags)
119 	 */
120 	uint flags;
121 }
122 
123 /**
124  * Parse a revision string for `from`, `to`, and intent.
125  *
126  * See `man gitrevisions` or
127  * http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for
128  * information on the syntax accepted.
129  *
130  * Params:
131  *      revspec = Pointer to an user-allocated git_revspec struct where the result of the rev-parse will be stored
132  *      repo = the repository to search in
133  *      spec = the rev-parse spec to parse
134  *
135  * Returns: 0 on success, GIT_INVALIDSPEC, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EAMBIGUOUS or an error code
136  */
137 @GIT_EXTERN
138 int git_revparse(.git_revspec* revspec, libgit2.types.git_repository* repo, const (char)* spec);
139 
140 /* @} */