Skip to content

Commit 1aa21fe

Browse files
committed
Deprecate git_revparse_single and _rangelike
1 parent 8480eef commit 1aa21fe

File tree

16 files changed

+156
-166
lines changed

16 files changed

+156
-166
lines changed

examples/diff.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ static int resolve_to_tree(
1515
git_repository *repo, const char *identifier, git_tree **tree)
1616
{
1717
int err = 0;
18+
git_oid oid;
1819
git_object *obj = NULL;
1920

20-
if (git_revparse_single(&obj, repo, identifier) < 0)
21+
if (git_revparse(&oid, NULL, NULL, repo, identifier) < 0 ||
22+
git_object_lookup(&obj, repo, &oid, GIT_OBJ_ANY) < 0)
2123
return GIT_ENOTFOUND;
2224

2325
switch (git_object_type(obj)) {

examples/rev-list.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,46 @@ static void check_error(int error_code, const char *action)
1414
exit(1);
1515
}
1616

17-
static int push_commit(git_revwalk *walk, git_object *obj, int hide)
17+
static int push_commit(git_revwalk *walk, git_oid *oid, int hide)
1818
{
1919
if (hide)
20-
return git_revwalk_hide(walk, git_object_id(obj));
20+
return git_revwalk_hide(walk, oid);
2121
else
22-
return git_revwalk_push(walk, git_object_id(obj));
22+
return git_revwalk_push(walk, oid);
2323
}
2424

2525
static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec, int hide)
2626
{
2727
int error;
28-
git_object *obj;
28+
git_oid oid;
2929

30-
if ((error = git_revparse_single(&obj, repo, spec)))
30+
if ((error = git_revparse(&oid, NULL, NULL, repo, spec)))
3131
return error;
32-
return push_commit(walk, obj, hide);
32+
return push_commit(walk, &oid, hide);
3333
}
3434

3535
static int push_range(git_repository *repo, git_revwalk *walk, const char *range, int hide)
3636
{
37-
git_object *left, *right;
38-
int threedots;
37+
git_oid left, right;
38+
git_revparse_flag_t flags;
3939
int error = 0;
4040

41-
if ((error = git_revparse_rangelike(&left, &right, &threedots, repo, range)))
41+
if ((error = git_revparse(&left, &right, &flags, repo, range)))
4242
return error;
43-
if (threedots) {
43+
if (flags & GIT_REVPARSE_MERGE_BASE) {
4444
/* TODO: support "<commit>...<commit>" */
4545
return GIT_EINVALIDSPEC;
4646
}
4747

48-
if ((error = push_commit(walk, left, !hide)))
48+
if ((error = push_commit(walk, &left, !hide)))
4949
goto out;
50-
error = push_commit(walk, right, hide);
50+
error = push_commit(walk, &right, hide);
5151

5252
out:
53-
git_object_free(left);
54-
git_object_free(right);
5553
return error;
5654
}
5755

58-
static int revwalk_parseopts(git_repository *repo, git_revwalk *walk, int nopts, const char *const *opts)
56+
static int revwalk_parseopts(git_repository *repo, git_revwalk *walk, int nopts, char **opts)
5957
{
6058
int hide, i, error;
6159
unsigned int sorting = GIT_SORT_NONE;

include/git2/revparse.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@
2020
*/
2121
GIT_BEGIN_DECL
2222

23-
/**
24-
* Find an object, as specified by a revision string. See `man gitrevisions`, or the documentation
25-
* for `git rev-parse` for information on the syntax accepted.
26-
*
27-
* @param out pointer to output object
28-
* @param repo the repository to search in
29-
* @param spec the textual specification for an object
30-
* @return 0 on success, GIT_ENOTFOUND, GIT_EAMBIGUOUS,
31-
* GIT_EINVALIDSPEC or an error code
32-
*/
33-
GIT_EXTERN(int) git_revparse_single(git_object **out, git_repository *repo, const char *spec);
34-
35-
/**
36-
* Parse a string with the form of a revision range, as accepted by
37-
* `git rev-list`, `git diff`, and others.
38-
*
39-
* @param left (output) the left-hand commit
40-
* @param right (output) the right-hand commit
41-
* @param threedots (output) 0 if the endpoints are separated by two dots, 1 if by three
42-
* @param repo the repository to find the commits in
43-
* @param rangelike the rangelike string to be parsed
44-
* @return 0 on success, or any error `git_revparse_single` can return
45-
*/
46-
GIT_EXTERN(int) git_revparse_rangelike(git_object **left, git_object **right, int *threedots, git_repository *repo, const char *rangelike);
47-
4823

4924
/**
5025
* Revparse flags. These indicate the intended behavior of the spec passed to

include/git2/revwalk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
221221
*
222222
* The range should be of the form
223223
* <commit>..<commit>
224-
* where each <commit> is in the form accepted by 'git_revparse_single'.
224+
* where each <commit> is in the form accepted by 'git_revparse'.
225225
* The left-hand commit will be hidden and the right-hand commit pushed.
226226
*
227227
* @param walk the walker being used for the traversal

src/push.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,18 @@ static int check_rref(char *ref)
9696
static int check_lref(git_push *push, char *ref)
9797
{
9898
/* lref must be resolvable to an existing object */
99-
git_object *obj;
100-
int error = git_revparse_single(&obj, push->repo, ref);
101-
102-
if (error) {
103-
if (error == GIT_ENOTFOUND)
104-
giterr_set(GITERR_REFERENCE,
105-
"src refspec '%s' does not match any existing object", ref);
106-
else
107-
giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref);
99+
git_oid oid;
100+
int error = git_revparse(&oid, NULL, NULL, push->repo, ref);
108101

109-
return -1;
110-
} else
111-
git_object_free(obj);
102+
if (!error)
103+
return 0;
112104

113-
return 0;
105+
if (error == GIT_ENOTFOUND)
106+
giterr_set(GITERR_REFERENCE,
107+
"src refspec '%s' does not match any existing object", ref);
108+
else
109+
giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref);
110+
return -1;
114111
}
115112

116113
static int parse_refspec(git_push *push, push_spec **spec, const char *str)

src/revparse.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static int ensure_left_hand_identifier_is_not_known_yet(git_object *object, git_
722722
return GIT_EINVALIDSPEC;
723723
}
724724

725-
int git_revparse_single(git_object **out, git_repository *repo, const char *spec)
725+
static int git_revparse_single(git_object **out, git_repository *repo, const char *spec)
726726
{
727727
size_t pos = 0, identifier_len = 0;
728728
int error = -1, n;
@@ -868,31 +868,6 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
868868
return error;
869869
}
870870

871-
int git_revparse_rangelike(git_object **left, git_object **right, int *threedots, git_repository *repo, const char *rangelike)
872-
{
873-
int error = 0;
874-
const char *p, *q;
875-
char *revspec;
876-
877-
p = strstr(rangelike, "..");
878-
if (!p) {
879-
giterr_set(GITERR_INVALID, "Malformed range (or rangelike syntax): %s", rangelike);
880-
return GIT_EINVALIDSPEC;
881-
} else if (p[2] == '.') {
882-
*threedots = 1;
883-
q = p + 3;
884-
} else {
885-
*threedots = 0;
886-
q = p + 2;
887-
}
888-
889-
revspec = git__substrdup(rangelike, p - rangelike);
890-
error = (git_revparse_single(left, repo, revspec)
891-
|| git_revparse_single(right, repo, q));
892-
git__free(revspec);
893-
return error;
894-
}
895-
896871

897872
int git_revparse(
898873
git_oid *left,

src/revwalk.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,23 @@ int git_revwalk_push_ref(git_revwalk *walk, const char *refname)
231231

232232
int git_revwalk_push_range(git_revwalk *walk, const char *range)
233233
{
234-
git_object *left, *right;
235-
int threedots;
234+
git_oid left, right;
235+
git_revparse_flag_t revparseflags;
236236
int error = 0;
237237

238-
if ((error = git_revparse_rangelike(&left, &right, &threedots, walk->repo, range)))
238+
if ((error = git_revparse(&left, &right, &revparseflags, walk->repo, range)))
239239
return error;
240-
if (threedots) {
240+
if (revparseflags & GIT_REVPARSE_MERGE_BASE) {
241241
/* TODO: support "<commit>...<commit>" */
242242
giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk");
243243
return GIT_EINVALIDSPEC;
244244
}
245245

246-
if ((error = push_commit(walk, git_object_id(left), 1)))
246+
if ((error = push_commit(walk, &left, 1)))
247247
goto out;
248-
error = push_commit(walk, git_object_id(right), 0);
248+
error = push_commit(walk, &right, 0);
249249

250250
out:
251-
git_object_free(left);
252-
git_object_free(right);
253251
return error;
254252
}
255253

src/transports/local.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,13 @@ static int local_negotiate_fetch(
236236

237237
/* Fill in the loids */
238238
git_vector_foreach(&t->refs, i, rhead) {
239-
git_object *obj;
239+
git_oid oid;
240240

241-
int error = git_revparse_single(&obj, repo, rhead->name);
241+
int error = git_revparse(&oid, NULL, NULL, repo, rhead->name);
242242
if (!error)
243-
git_oid_cpy(&rhead->loid, git_object_id(obj));
243+
git_oid_cpy(&rhead->loid, &oid);
244244
else if (error != GIT_ENOTFOUND)
245245
return error;
246-
git_object_free(obj);
247246
giterr_clear();
248247
}
249248

0 commit comments

Comments
 (0)