Skip to content

Commit

Permalink
Drop usage of constants that are deprecated in libgit2
Browse files Browse the repository at this point in the history
  • Loading branch information
stewid committed Oct 5, 2024
1 parent 2693d74 commit b0b60f2
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 125 deletions.
49 changes: 0 additions & 49 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2300,55 +2300,6 @@ if test "x${have_sys_subfolder}" = xyes; then
PKG_CFLAGS="${PKG_CFLAGS} -DGIT2R_HAVE_SYS_SUBFOLDER"
fi

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the libgit2 function git_buf_dispose is available" >&5
printf %s "checking whether the libgit2 function git_buf_dispose is available... " >&6; }
have_buf_dispose=no
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <git2.h>
int
main (void)
{
git_buf_dispose(NULL);
;
return 0;
}
_ACEOF
PKG_CFLAGS="${PKG_CFLAGS} -Werror" "$RBIN" CMD SHLIB conftest.c \
1>&5 2>&5 && have_buf_dispose=yes
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${have_buf_dispose}" >&5
printf "%s\n" "${have_buf_dispose}" >&6; }
if test "x${have_buf_dispose}" = xyes; then
PKG_CFLAGS="${PKG_CFLAGS} -DGIT2R_HAVE_BUF_DISPOSE"
fi

# The constants GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT,
# GIT_OBJ_TAG_GIT_OBJ_TREE and GIT_REF_OID are deprecated in
# libgit2 v0.28.0. Use GIT_OBJECT_ANY, GIT_OBJECT_BLOB,
# GIT_OBJECT_COMMIT, GIT_OBJECT_TAG_GIT_OBJECT_TREE and
# GIT_REFERENCE_DIRECT, if available, instead.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the libgit2 constant GIT_OBJECT_ANY is available" >&5
printf %s "checking whether the libgit2 constant GIT_OBJECT_ANY is available... " >&6; }
have_git_object_any=no
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <git2.h>
int
main (void)
{
git_object_typeisloose(GIT_OBJECT_ANY);
;
return 0;
}
_ACEOF
PKG_CFLAGS="${PKG_CFLAGS} -Werror" "$RBIN" CMD SHLIB conftest.c \
1>&5 2>&5 && have_git_object_any=yes
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${have_git_object_any}" >&5
printf "%s\n" "${have_git_object_any}" >&6; }
if test "x${have_git_object_any}" = xyes; then
PKG_CFLAGS="${PKG_CFLAGS} -DGIT2R_HAVE_OBJECT_ANY"
fi

# Several libgit2 error functions and enumaration values have been
# deprecated, use newer versions.
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the libgit2 function git_error_last is available" >&5
Expand Down
17 changes: 0 additions & 17 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,6 @@ if test "x${have_sys_subfolder}" = xyes; then
PKG_CFLAGS="${PKG_CFLAGS} -DGIT2R_HAVE_SYS_SUBFOLDER"
fi

# The constants GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT,
# GIT_OBJ_TAG_GIT_OBJ_TREE and GIT_REF_OID are deprecated in
# libgit2 v0.28.0. Use GIT_OBJECT_ANY, GIT_OBJECT_BLOB,
# GIT_OBJECT_COMMIT, GIT_OBJECT_TAG_GIT_OBJECT_TREE and
# GIT_REFERENCE_DIRECT, if available, instead.
AC_MSG_CHECKING([whether the libgit2 constant GIT_OBJECT_ANY is available])
have_git_object_any=no
AC_LANG_CONFTEST([AC_LANG_PROGRAM(
[[#include <git2.h>]],
[[git_object_typeisloose(GIT_OBJECT_ANY);]])])
PKG_CFLAGS="${PKG_CFLAGS} -Werror" "$RBIN" CMD SHLIB conftest.c \
1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD && have_git_object_any=yes
AC_MSG_RESULT([${have_git_object_any}])
if test "x${have_git_object_any}" = xyes; then
PKG_CFLAGS="${PKG_CFLAGS} -DGIT2R_HAVE_OBJECT_ANY"
fi

# Several libgit2 error functions and enumaration values have been
# deprecated, use newer versions.
AC_MSG_CHECKING([whether the libgit2 function git_error_last is available])
Expand Down
2 changes: 1 addition & 1 deletion src/git2r_branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ git2r_branch_target(

PROTECT(result = Rf_allocVector(STRSXP, 1));
nprotect++;
if (git_reference_type(reference) == GIT2R_REFERENCE_DIRECT) {
if (git_reference_type(reference) == GIT_REFERENCE_DIRECT) {
git_oid_fmt(sha, git_reference_target(reference));
sha[GIT_OID_HEXSZ] = '\0';
SET_STRING_ELT(result, 0, Rf_mkChar(sha));
Expand Down
6 changes: 3 additions & 3 deletions src/git2r_checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ git2r_checkout_tree(
goto cleanup;

switch (git_object_type(treeish)) {
case GIT2R_OBJECT_COMMIT:
case GIT2R_OBJECT_TAG:
case GIT2R_OBJECT_TREE:
case GIT_OBJECT_COMMIT:
case GIT_OBJECT_TAG:
case GIT_OBJECT_TREE:
error = GIT_OK;
break;
default:
Expand Down
23 changes: 0 additions & 23 deletions src/git2r_deprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,6 @@
#ifndef INCLUDE_git2r_deprecated_h
#define INCLUDE_git2r_deprecated_h

/* The constants GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT,
* GIT_OBJ_TAG_GIT_OBJ_TREE and GIT_REF_OID are deprecated in
* libgit2. Use GIT_OBJECT_ANY, GIT_OBJECT_BLOB, GIT_OBJECT_COMMIT,
* GIT_OBJECT_TAG_GIT_OBJECT_TREE and GIT_REFERENCE_DIRECT, if
* available, instead. */
#if defined(GIT2R_HAVE_OBJECT_ANY)
# define GIT2R_OBJECT_ANY GIT_OBJECT_ANY
# define GIT2R_OBJECT_BLOB GIT_OBJECT_BLOB
# define GIT2R_OBJECT_COMMIT GIT_OBJECT_COMMIT
# define GIT2R_OBJECT_TAG GIT_OBJECT_TAG
# define GIT2R_OBJECT_TREE GIT_OBJECT_TREE
# define GIT2R_REFERENCE_DIRECT GIT_REFERENCE_DIRECT
# define GIT2R_REFERENCE_SYMBOLIC GIT_REFERENCE_SYMBOLIC
#else
# define GIT2R_OBJECT_ANY GIT_OBJ_ANY
# define GIT2R_OBJECT_BLOB GIT_OBJ_BLOB
# define GIT2R_OBJECT_COMMIT GIT_OBJ_COMMIT
# define GIT2R_OBJECT_TAG GIT_OBJ_TAG
# define GIT2R_OBJECT_TREE GIT_OBJ_TREE
# define GIT2R_REFERENCE_DIRECT GIT_REF_OID
# define GIT2R_REFERENCE_SYMBOLIC GIT_REF_SYMBOLIC
#endif

#if defined(GIT2R_HAVE_GIT_ERROR)
# define GIT2R_ERROR_SET_STR git_error_set_str
# define GIT2R_ERROR_LAST git_error_last
Expand Down
12 changes: 6 additions & 6 deletions src/git2r_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,39 @@ git2r_object_lookup(
len = LENGTH(STRING_ELT(sha, 0));
if (GIT_OID_HEXSZ == len) {
git_oid_fromstr(&oid, CHAR(STRING_ELT(sha, 0)));
error = git_object_lookup(&object, repository, &oid, GIT2R_OBJECT_ANY);
error = git_object_lookup(&object, repository, &oid, GIT_OBJECT_ANY);
if (error)
goto cleanup;
} else {
git_oid_fromstrn(&oid, CHAR(STRING_ELT(sha, 0)), len);
error = git_object_lookup_prefix(&object, repository, &oid, len, GIT2R_OBJECT_ANY);
error = git_object_lookup_prefix(&object, repository, &oid, len, GIT_OBJECT_ANY);
if (error)
goto cleanup;
}

switch (git_object_type(object)) {
case GIT2R_OBJECT_COMMIT:
case GIT_OBJECT_COMMIT:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_commit));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_commit));
git2r_commit_init((git_commit*)object, repo, result);
break;
case GIT2R_OBJECT_TREE:
case GIT_OBJECT_TREE:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_tree));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_tree));
git2r_tree_init((git_tree*)object, repo, result);
break;
case GIT2R_OBJECT_BLOB:
case GIT_OBJECT_BLOB:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_blob));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_blob));
git2r_blob_init((git_blob*)object, repo, result);
break;
case GIT2R_OBJECT_TAG:
case GIT_OBJECT_TAG:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_tag));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Expand Down
18 changes: 9 additions & 9 deletions src/git2r_odb.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ git2r_odb_hash(
error = git_odb_hash(&oid,
CHAR(STRING_ELT(data, i)),
LENGTH(STRING_ELT(data, i)),
GIT2R_OBJECT_BLOB);
GIT_OBJECT_BLOB);
if (error)
break;

Expand Down Expand Up @@ -100,7 +100,7 @@ git2r_odb_hashfile(
} else {
error = git_odb_hashfile(&oid,
CHAR(STRING_ELT(path, i)),
GIT2R_OBJECT_BLOB);
GIT_OBJECT_BLOB);
if (error)
break;

Expand Down Expand Up @@ -183,19 +183,19 @@ git2r_odb_objects_cb(
return error;

switch(type) {
case GIT2R_OBJECT_COMMIT:
case GIT_OBJECT_COMMIT:
if (!Rf_isNull(p->list))
git2r_add_object(oid, p->list, p->n, "commit", len);
break;
case GIT2R_OBJECT_TREE:
case GIT_OBJECT_TREE:
if (!Rf_isNull(p->list))
git2r_add_object(oid, p->list, p->n, "tree", len);
break;
case GIT2R_OBJECT_BLOB:
case GIT_OBJECT_BLOB:
if (!Rf_isNull(p->list))
git2r_add_object(oid, p->list, p->n, "blob", len);
break;
case GIT2R_OBJECT_TAG:
case GIT_OBJECT_TAG:
if (!Rf_isNull(p->list))
git2r_add_object(oid, p->list, p->n, "tag", len);
break;
Expand Down Expand Up @@ -362,7 +362,7 @@ git2r_odb_tree_blobs(

entry = git_tree_entry_byindex(tree, i);
switch (git_tree_entry_type(entry)) {
case GIT2R_OBJECT_TREE:
case GIT_OBJECT_TREE:
{
char *buf = NULL;
size_t path_len, buf_len;
Expand Down Expand Up @@ -413,7 +413,7 @@ git2r_odb_tree_blobs(

break;
}
case GIT2R_OBJECT_BLOB:
case GIT_OBJECT_BLOB:
if (!Rf_isNull(data->list)) {
error = git2r_odb_add_blob(
entry,
Expand Down Expand Up @@ -458,7 +458,7 @@ git2r_odb_blobs_cb(
if (error)
return error;

if (type == GIT2R_OBJECT_COMMIT) {
if (type == GIT_OBJECT_COMMIT) {
const git_signature *author;
git_commit *commit = NULL;
git_tree *tree = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/git2r_reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ git2r_reference_init(
Rf_mkString(git_reference_shorthand(source)));

switch (git_reference_type(source)) {
case GIT2R_REFERENCE_DIRECT:
case GIT_REFERENCE_DIRECT:
SET_VECTOR_ELT(
dest,
git2r_S3_item__git_reference__type,
Rf_ScalarInteger(GIT2R_REFERENCE_DIRECT));
Rf_ScalarInteger(GIT_REFERENCE_DIRECT));

git_oid_fmt(sha, git_reference_target(source));
sha[GIT_OID_HEXSZ] = '\0';
Expand All @@ -66,11 +66,11 @@ git2r_reference_init(
git2r_S3_item__git_reference__sha,
Rf_mkString(sha));
break;
case GIT2R_REFERENCE_SYMBOLIC:
case GIT_REFERENCE_SYMBOLIC:
SET_VECTOR_ELT(
dest,
git2r_S3_item__git_reference__type,
Rf_ScalarInteger(GIT2R_REFERENCE_SYMBOLIC));
Rf_ScalarInteger(GIT_REFERENCE_SYMBOLIC));

SET_VECTOR_ELT(
dest,
Expand Down
2 changes: 1 addition & 1 deletion src/git2r_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ git2r_reset_default(
if (error)
goto cleanup;

error = git_reference_peel(&head_commit, head, GIT2R_OBJECT_COMMIT);
error = git_reference_peel(&head_commit, head, GIT_OBJECT_COMMIT);
if (error)
goto cleanup;

Expand Down
8 changes: 4 additions & 4 deletions src/git2r_revparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ git2r_revparse_single(
goto cleanup;

switch (git_object_type(treeish)) {
case GIT2R_OBJECT_BLOB:
case GIT_OBJECT_BLOB:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_blob));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_blob));
git2r_blob_init((git_blob*)treeish, repo, result);
break;
case GIT2R_OBJECT_COMMIT:
case GIT_OBJECT_COMMIT:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_commit));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_commit));
git2r_commit_init((git_commit*)treeish, repo, result);
break;
case GIT2R_OBJECT_TAG:
case GIT_OBJECT_TAG:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_tag));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_tag));
git2r_tag_init((git_tag*)treeish, repo, result);
break;
case GIT2R_OBJECT_TREE:
case GIT_OBJECT_TREE:
PROTECT(result = Rf_mkNamed(VECSXP, git2r_S3_items__git_tree));
nprotect++;
Rf_setAttrib(result, R_ClassSymbol,
Expand Down
10 changes: 5 additions & 5 deletions src/git2r_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,36 +263,36 @@ git2r_tag_foreach_cb(
int skip = 0;
SEXP item = R_NilValue, tag;

error = git_object_lookup(&object, cb_data->repository, oid, GIT2R_OBJECT_ANY);
error = git_object_lookup(&object, cb_data->repository, oid, GIT_OBJECT_ANY);
if (error)
goto cleanup;

switch (git_object_type(object)) {
case GIT2R_OBJECT_COMMIT:
case GIT_OBJECT_COMMIT:
PROTECT(item = Rf_mkNamed(VECSXP, git2r_S3_items__git_commit));
Rf_setAttrib(
item,
R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_commit));
git2r_commit_init((git_commit*)object, cb_data->repo, item);
break;
case GIT2R_OBJECT_TREE:
case GIT_OBJECT_TREE:
PROTECT(item = Rf_mkNamed(VECSXP, git2r_S3_items__git_tree));
Rf_setAttrib(
item,
R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_tree));
git2r_tree_init((git_tree*)object, cb_data->repo, item);
break;
case GIT2R_OBJECT_BLOB:
case GIT_OBJECT_BLOB:
PROTECT(item = Rf_mkNamed(VECSXP, git2r_S3_items__git_blob));
Rf_setAttrib(
item,
R_ClassSymbol,
Rf_mkString(git2r_S3_class__git_blob));
git2r_blob_init((git_blob*)object, cb_data->repo, item);
break;
case GIT2R_OBJECT_TAG:
case GIT_OBJECT_TAG:
PROTECT(item = Rf_mkNamed(VECSXP, git2r_S3_items__git_tag));
Rf_setAttrib(
item,
Expand Down
6 changes: 3 additions & 3 deletions src/git2r_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ git2r_tree_walk_cb(
git2r_tree_walk_cb_data *p = (git2r_tree_walk_cb_data*)payload;

if (p->recursive) {
if (git_tree_entry_type(entry) != GIT2R_OBJECT_BLOB)
if (git_tree_entry_type(entry) != GIT_OBJECT_BLOB)
return 0;
} else if (*root) {
return 1;
Expand Down Expand Up @@ -145,11 +145,11 @@ git2r_tree_walk_cb(
Rf_mkChar(git_tree_entry_name(entry)));

/* length */
if (git_tree_entry_type(entry) == GIT2R_OBJECT_BLOB) {
if (git_tree_entry_type(entry) == GIT_OBJECT_BLOB) {
error = git_tree_entry_to_object(&obj, p->repository, entry);
if (error)
goto cleanup;
error = git_object_peel(&blob, obj, GIT2R_OBJECT_BLOB);
error = git_object_peel(&blob, obj, GIT_OBJECT_BLOB);
if (error)
goto cleanup;
INTEGER(VECTOR_ELT(p->list, 5))[p->n] = git_blob_rawsize((git_blob *)blob);
Expand Down

0 comments on commit b0b60f2

Please sign in to comment.