public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Mamoru TASAKA <mtasaka@fedoraproject.org>
To: git-commits@fedoraproject.org
Subject: [rpms/rubygem-rugged] rawhide: Backport upstream patch to use TypedData API needed for ruby4.1
Date: Sun, 25 Oct 2026 10:52:24 GMT	[thread overview]
Message-ID: <179292554495.1.11238685277189331023.rpms-rubygem-rugged-6e8105ee7341@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/rubygem-rugged
Branch : rawhide
Commit : 6e8105ee73410f0064e4dc302a1aacdf8d66b5ca
Author : Mamoru TASAKA <mtasaka@fedoraproject.org>
Date   : 2026-10-25T19:52:10+09:00
Stats  : +3139/-1 in 3 file(s)
URL    : https://src.fedoraproject.org/rpms/rubygem-rugged/c/6e8105ee73410f0064e4dc302a1aacdf8d66b5ca?branch=rawhide

Log:
Backport upstream patch to use TypedData API needed for ruby4.1

---
diff --git a/rubygem-rugged-pr1003-TypedData-api.patch b/rubygem-rugged-pr1003-TypedData-api.patch
new file mode 100644
index 0000000..ad6fc4e
--- /dev/null
+++ b/rubygem-rugged-pr1003-TypedData-api.patch
@@ -0,0 +1,66 @@
+From 3757b20062dbb681217ea398105af994d573fd44 Mon Sep 17 00:00:00 2001
+From: John Hawthorn <john@hawthorn.email>
+Date: Fri, 29 May 2026 12:15:26 -0700
+Subject: [PATCH 1/2] Fix shutdown hook and use TypedData
+
+Co-authored-by: Randy Stauner <randy.stauner@shopify.com>
+---
+ ext/rugged/rugged.c | 13 ++++++++++++-
+ 1 file changed, 12 insertions(+), 1 deletion(-)
+
+diff --git a/ext/rugged/rugged.c b/ext/rugged/rugged.c
+index daed3fc4f..0c5948f16 100644
+--- a/ext/rugged/rugged.c
++++ b/ext/rugged/rugged.c
+@@ -336,6 +336,16 @@ static void cleanup_cb(void *unused)
+ 	git_libgit2_shutdown();
+ }
+ 
++static const rb_data_type_t rugged_shutdown_hook_type = {
++	.wrap_struct_name = "Rugged::ShutdownHook",
++	.function = {
++		.dmark = NULL,
++		.dfree = cleanup_cb,
++		.dsize = NULL,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ void rugged_exception_raise(void)
+ {
+ 	VALUE err_klass, err_obj;
+@@ -687,6 +697,7 @@ void Init_rugged(void)
+ 
+ 	/* Hook a global object to cleanup the library
+ 	 * on shutdown */
+-	rb_mShutdownHook = Data_Wrap_Struct(rb_cObject, NULL, &cleanup_cb, NULL);
++	/* Non-NULL data so the GC actually invokes cleanup_cb on shutdown. */
++	rb_mShutdownHook = TypedData_Wrap_Struct(rb_cObject, &rugged_shutdown_hook_type, (void *)1);
+ 	rb_global_variable(&rb_mShutdownHook);
+ }
+
+From 64e4b6f7e4d829c7412f0813931f12cfaf206f83 Mon Sep 17 00:00:00 2001
+From: John Hawthorn <john@hawthorn.email>
+Date: Mon, 1 Jun 2026 10:04:16 -0700
+Subject: [PATCH 2/2] Use RTYPEDDATA_DATA for backend
+
+Co-authored-by: Randy Stauner <randy.stauner@shopify.com>
+---
+ ext/rugged/rugged_repo.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c
+index 0a43b457e..5d583bc0a 100644
+--- a/ext/rugged/rugged_repo.c
++++ b/ext/rugged/rugged_repo.c
+@@ -225,7 +225,9 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
+ 		rb_raise(rb_eRuggedError, "Backend must be an instance of Rugged::Backend");
+ 	}
+ 
+-	Data_Get_Struct(rb_backend, rugged_backend, backend);
++	/* Backends are wrapped by external code with a type descriptor we don't
++	 * own, so we can't TypedData_Get_Struct against a known type. */
++	backend = (rugged_backend *)RTYPEDDATA_DATA(rb_backend);
+ 
+ 	error = git_odb_new(&odb);
+ 	if (error) goto cleanup;

diff --git a/rubygem-rugged-pr998-TypedData-api.patch b/rubygem-rugged-pr998-TypedData-api.patch
new file mode 100644
index 0000000..ca88b1d
--- /dev/null
+++ b/rubygem-rugged-pr998-TypedData-api.patch
@@ -0,0 +1,3064 @@
+From 8758e137170ffd65e1b10286090d52f74d842365 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 18:32:20 +0100
+Subject: [PATCH 01/14] repository: use `TypedData` for `Rugged::Repository`
+
+---
+ ext/rugged/rugged_blame.c                |  4 +-
+ ext/rugged/rugged_blob.c                 | 13 ++--
+ ext/rugged/rugged_branch.c               |  4 +-
+ ext/rugged/rugged_branch_collection.c    | 14 ++--
+ ext/rugged/rugged_commit.c               | 13 ++--
+ ext/rugged/rugged_index.c                |  9 ++-
+ ext/rugged/rugged_note.c                 | 13 ++--
+ ext/rugged/rugged_object.c               |  5 +-
+ ext/rugged/rugged_rebase.c               |  5 +-
+ ext/rugged/rugged_reference_collection.c | 16 ++--
+ ext/rugged/rugged_remote.c               |  4 +-
+ ext/rugged/rugged_remote_collection.c    | 20 ++---
+ ext/rugged/rugged_repo.c                 | 93 +++++++++++++-----------
+ ext/rugged/rugged_revwalk.c              |  5 +-
+ ext/rugged/rugged_submodule.c            |  8 +-
+ ext/rugged/rugged_submodule_collection.c | 12 +--
+ ext/rugged/rugged_tag.c                  |  5 +-
+ ext/rugged/rugged_tag_collection.c       | 12 +--
+ ext/rugged/rugged_tree.c                 | 13 ++--
+ 19 files changed, 153 insertions(+), 115 deletions(-)
+
+diff --git a/ext/rugged/rugged_blame.c b/ext/rugged/rugged_blame.c
+index 9ddde7564..dba638925 100644
+--- a/ext/rugged/rugged_blame.c
++++ b/ext/rugged/rugged_blame.c
+@@ -10,6 +10,8 @@
+ extern VALUE rb_mRugged;
+ VALUE rb_cRuggedBlame;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ static VALUE rb_git_blame_hunk_fromC(const git_blame_hunk *hunk)
+ {
+ 	VALUE rb_hunk;
+@@ -135,7 +137,7 @@ static VALUE rb_git_blame_new(int argc, VALUE *argv, VALUE klass)
+ 	rb_scan_args(argc, argv, "20:", &rb_repo, &rb_path, &rb_options);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_path, T_STRING);
+ 
+diff --git a/ext/rugged/rugged_blob.c b/ext/rugged/rugged_blob.c
+index 1be79501a..7a0d2dd02 100644
+--- a/ext/rugged/rugged_blob.c
++++ b/ext/rugged/rugged_blob.c
+@@ -18,6 +18,7 @@ VALUE rb_cRuggedBlob;
+ VALUE rb_cRuggedBlobSig;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ /*
+  *  call-seq:
+@@ -143,7 +144,7 @@ static VALUE rb_git_blob_from_buffer(VALUE self, VALUE rb_repo, VALUE rb_buffer)
+ 	Check_Type(rb_buffer, T_STRING);
+ 	rugged_check_repo(rb_repo);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_blob_create_frombuffer(&oid, repo, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
+ 	rugged_exception_check(error);
+@@ -170,7 +171,7 @@ static VALUE rb_git_blob_from_workdir(VALUE self, VALUE rb_repo, VALUE rb_path)
+ 	FilePathValue(rb_path);
+ 	rugged_check_repo(rb_repo);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_blob_create_fromworkdir(&oid, repo, StringValueCStr(rb_path));
+ 	rugged_exception_check(error);
+@@ -198,7 +199,7 @@ static VALUE rb_git_blob_from_disk(VALUE self, VALUE rb_repo, VALUE rb_path)
+ 	FilePathValue(rb_path);
+ 	rugged_check_repo(rb_repo);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_blob_create_fromdisk(&oid, repo, StringValueCStr(rb_path));
+ 	rugged_exception_check(error);
+@@ -253,7 +254,7 @@ static VALUE rb_git_blob_from_io(int argc, VALUE *argv, VALUE klass)
+ 	rb_scan_args(argc, argv, "21", &rb_repo, &rb_io, &rb_hint_path);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!NIL_P(rb_hint_path)) {
+ 		FilePathValue(rb_hint_path);
+@@ -507,7 +508,7 @@ static VALUE rb_git_blob_to_buffer(int argc, VALUE *argv, VALUE self)
+ 	rb_scan_args(argc, argv, "21", &rb_repo, &rb_sha1, &rb_max_bytes);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	blob = (git_blob *)rugged_object_get(repo, rb_sha1, GIT_OBJ_BLOB);
+ 
+@@ -607,7 +608,7 @@ static VALUE rb_git_blob_merge_files(int argc, VALUE *argv, VALUE klass)
+ 
+ 	if (!NIL_P(rb_repo)) {
+ 		rugged_check_repo(rb_repo);
+-		Data_Get_Struct(rb_repo, git_repository, repo);
++		TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 	}
+ 
+ 	if (!NIL_P(rb_options))
+diff --git a/ext/rugged/rugged_branch.c b/ext/rugged/rugged_branch.c
+index d5c20f81c..fd0e5d49f 100644
+--- a/ext/rugged/rugged_branch.c
++++ b/ext/rugged/rugged_branch.c
+@@ -13,6 +13,8 @@ extern VALUE rb_cRuggedObject;
+ extern VALUE rb_cRuggedReference;
+ VALUE rb_cRuggedBranch;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ static inline VALUE rugged_branch_new(VALUE owner, git_reference *ref)
+ {
+ 	return rugged_ref_new(rb_cRuggedBranch, owner, ref);
+@@ -58,7 +60,7 @@ static VALUE rb_git_branch__remote_name(VALUE rb_repo, const char *canonical_nam
+ 	int error;
+ 	VALUE result = Qnil;
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if ((error = git_branch_remote_name(&remote_name, repo, canonical_name)) == GIT_OK)
+ 		result = rb_enc_str_new(remote_name.ptr, remote_name.size, rb_utf8_encoding());
+diff --git a/ext/rugged/rugged_branch_collection.c b/ext/rugged/rugged_branch_collection.c
+index 21e0d5f21..ca93fdf19 100644
+--- a/ext/rugged/rugged_branch_collection.c
++++ b/ext/rugged/rugged_branch_collection.c
+@@ -13,6 +13,8 @@ extern VALUE rb_cRuggedBranch;
+ 
+ VALUE rb_cRuggedBranchCollection;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ static inline VALUE rugged_branch_new(VALUE owner, git_reference *ref)
+ {
+ 	return rugged_ref_new(rb_cRuggedBranch, owner, ref);
+@@ -119,7 +121,7 @@ static VALUE rb_git_branch_collection_create(int argc, VALUE *argv, VALUE self)
+ 	rb_scan_args(argc, argv, "20:", &rb_name, &rb_target, &rb_options);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 	Check_Type(rb_target, T_STRING);
+@@ -164,7 +166,7 @@ static VALUE rb_git_branch_collection_aref(VALUE self, VALUE rb_name) {
+ 	int error;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -193,7 +195,7 @@ static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_onl
+ 	if (!NIL_P(rb_filter))
+ 		filter = parse_branch_type(rb_filter);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_branch_iterator_new(&iter, repo, filter);
+ 	rugged_exception_check(error);
+@@ -273,7 +275,7 @@ static VALUE rb_git_branch_collection_delete(VALUE self, VALUE rb_name_or_branch
+ 	int error;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = rugged_branch_lookup(&branch, repo, rb_name_or_branch);
+ 	rugged_exception_check(error);
+@@ -320,7 +322,7 @@ static VALUE rb_git_branch_collection_move(int argc, VALUE *argv, VALUE self)
+ 	Check_Type(rb_new_branch_name, T_STRING);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = rugged_branch_lookup(&old_branch, repo, rb_name_or_branch);
+ 	rugged_exception_check(error);
+@@ -353,7 +355,7 @@ static VALUE rb_git_branch_collection_exist_p(VALUE self, VALUE rb_name)
+ 	int error;
+ 
+ 	Check_Type(rb_name, T_STRING);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = rugged_branch_lookup(&branch, repo, rb_name);
+ 	git_reference_free(branch);
+diff --git a/ext/rugged/rugged_commit.c b/ext/rugged/rugged_commit.c
+index dd89baea3..01a747ce0 100644
+--- a/ext/rugged/rugged_commit.c
++++ b/ext/rugged/rugged_commit.c
+@@ -16,6 +16,7 @@ extern VALUE rb_cRuggedSignature;
+ VALUE rb_cRuggedCommit;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ /*
+  *  call-seq:
+@@ -357,7 +358,7 @@ static VALUE rb_git_commit_amend(VALUE self, VALUE rb_data)
+ 	TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit_to_amend);
+ 
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	rb_ref = rb_hash_aref(rb_data, CSTR2SYM("update_ref"));
+ 	if (!NIL_P(rb_ref)) {
+@@ -549,7 +550,7 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
+ 	Check_Type(rb_data, T_HASH);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if ((error = parse_commit_options(&commit_data, repo, rb_data)) < 0)
+ 		goto cleanup;
+@@ -614,7 +615,7 @@ static VALUE rb_git_commit_to_mbox(int argc, VALUE *argv, VALUE self)
+ 	rb_scan_args(argc, argv, ":", &rb_options);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	TypedData_Get_Struct(self, git_commit, &rugged_object_type, commit);
+ 
+@@ -735,7 +736,7 @@ static VALUE rb_git_commit_extract_signature(int argc, VALUE *argv, VALUE self)
+ 	rb_scan_args(argc, argv, "21", &rb_repo, &rb_commit, &rb_field);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_oid_fromstr(&commit_id, StringValueCStr(rb_commit));
+ 	rugged_exception_check(error);
+@@ -799,7 +800,7 @@ static VALUE rb_git_commit_create_to_s(VALUE self, VALUE rb_repo, VALUE rb_data)
+ 	Check_Type(rb_data, T_HASH);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if ((error = parse_commit_options(&commit_data, repo, rb_data)) < 0)
+ 		goto cleanup;
+@@ -850,7 +851,7 @@ static VALUE rb_git_commit_create_with_signature(int argc, VALUE *argv, VALUE se
+ 	rb_scan_args(argc, argv, "31", &rb_repo, &rb_content, &rb_signature, &rb_field);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_content, T_STRING);
+ 	Check_Type(rb_signature, T_STRING);
+diff --git a/ext/rugged/rugged_index.c b/ext/rugged/rugged_index.c
+index 12ca6f452..89afb4c08 100644
+--- a/ext/rugged/rugged_index.c
++++ b/ext/rugged/rugged_index.c
+@@ -14,6 +14,7 @@ extern VALUE rb_cRuggedDiff;
+ extern VALUE rb_cRuggedTree;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry);
+ static VALUE rb_git_indexentry_fromC(const git_index_entry *entry);
+@@ -633,7 +634,7 @@ static VALUE rb_git_index_writetree(int argc, VALUE *argv, VALUE self)
+ 	if (rb_scan_args(argc, argv, "01", &rb_repo) == 1) {
+ 		git_repository *repo = NULL;
+ 		rugged_check_repo(rb_repo);
+-		Data_Get_Struct(rb_repo, git_repository, repo);
++		TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 		error = git_index_write_tree_to(&tree_oid, index, repo);
+ 	}
+ 	else {
+@@ -686,7 +687,7 @@ static VALUE rb_git_diff_tree_to_index(VALUE self, VALUE rb_other, VALUE rb_opti
+ 
+ 	Data_Get_Struct(self, git_index, index);
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	// Need to flip the reverse option, so that the index is by default
+ 	// the "old file" side of the diff.
+@@ -714,7 +715,7 @@ static VALUE rb_git_diff_index_to_workdir(VALUE self, VALUE rb_options)
+ 
+ 	Data_Get_Struct(self, git_index, index);
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_diff_index_to_workdir(&diff, repo, index, &opts);
+ 
+@@ -897,7 +898,7 @@ static VALUE rb_git_merge_file(int argc, VALUE *argv, VALUE self)
+ 	Data_Get_Struct(self, git_index, index);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_index_conflict_get(&ancestor, &ours, &theirs, index, StringValueCStr(rb_path));
+ 	if (error == GIT_ENOTFOUND)
+diff --git a/ext/rugged/rugged_note.c b/ext/rugged/rugged_note.c
+index 8a81490a6..2b20dd0cb 100644
+--- a/ext/rugged/rugged_note.c
++++ b/ext/rugged/rugged_note.c
+@@ -11,6 +11,7 @@ extern VALUE rb_cRuggedRepo;
+ extern VALUE rb_cRuggedObject;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ static VALUE rugged_git_note_message(const git_note *note)
+ {
+@@ -64,7 +65,7 @@ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
+ 	TypedData_Get_Struct(self, git_object, &rugged_object_type, object);
+ 
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_note_read(&note, repo, notes_ref, git_object_id(object));
+ 
+@@ -129,7 +130,7 @@ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
+ 	TypedData_Get_Struct(self, git_object, &rugged_object_type, target);
+ 
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
+ 
+@@ -212,7 +213,7 @@ static VALUE rb_git_note_remove(int argc, VALUE *argv, VALUE self)
+ 	TypedData_Get_Struct(self, git_object, &rugged_object_type, target);
+ 
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	rb_scan_args(argc, argv, "01", &rb_data);
+ 
+@@ -259,7 +260,7 @@ static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object
+ 
+ 	git_repository *repo;
+ 
+-	Data_Get_Struct(payload->rb_data, git_repository, repo);
++	TypedData_Get_Struct(payload->rb_data, git_repository, &rugged_repository_type, repo);
+ 
+ 	rugged_exception_check(
+ 		git_object_lookup(&annotated_object, repo, annotated_object_id, GIT_OBJ_ANY)
+@@ -307,7 +308,7 @@ static VALUE rb_git_note_each(int argc, VALUE *argv, VALUE self)
+ 		notes_ref = StringValueCStr(rb_notes_ref);
+ 	}
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_note_foreach(repo, notes_ref, &cb_note__each, &payload);
+ 
+@@ -334,7 +335,7 @@ static VALUE rb_git_note_default_ref_GET(VALUE self)
+ 	git_buf ref_name = { 0 };
+ 	VALUE rb_result;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	rugged_exception_check(
+ 		git_note_default_ref(&ref_name, repo)
+diff --git a/ext/rugged/rugged_object.c b/ext/rugged/rugged_object.c
+index fd0d3d4e7..11a17b3eb 100644
+--- a/ext/rugged/rugged_object.c
++++ b/ext/rugged/rugged_object.c
+@@ -17,6 +17,7 @@ extern VALUE rb_cRuggedRepo;
+ VALUE rb_cRuggedObject;
+ 
+ const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ git_otype rugged_otype_get(VALUE self)
+ {
+@@ -267,7 +268,7 @@ VALUE rb_git_object_lookup(VALUE klass, VALUE rb_repo, VALUE rb_hex)
+ 	if (oid_length > GIT_OID_HEXSZ)
+ 		rb_raise(rb_eTypeError, "The given OID is too long");
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_oid_fromstrn(&oid, RSTRING_PTR(rb_hex), oid_length);
+ 	rugged_exception_check(error);
+@@ -295,7 +296,7 @@ VALUE rugged_object_rev_parse(VALUE rb_repo, VALUE rb_spec, int as_obj)
+ 
+ 	rugged_check_repo(rb_repo);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_revparse_single(&object, repo, spec);
+ 	rugged_exception_check(error);
+diff --git a/ext/rugged/rugged_rebase.c b/ext/rugged/rugged_rebase.c
+index 39413cdf7..f65cc4653 100644
+--- a/ext/rugged/rugged_rebase.c
++++ b/ext/rugged/rugged_rebase.c
+@@ -16,6 +16,7 @@ extern VALUE rb_cRuggedReference;
+ VALUE rb_cRuggedRebase;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ static VALUE rebase_operation_type(git_rebase_operation *operation);
+ 
+@@ -66,7 +67,7 @@ static void get_annotated_commit(git_annotated_commit **annotated_commit, VALUE
+ 	int error;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (rb_obj_is_kind_of(rb_value, rb_cRuggedCommit)) {
+ 		const git_commit * commit;
+@@ -152,7 +153,7 @@ static VALUE rb_git_rebase_new(int argc, VALUE* argv, VALUE klass)
+ 	git_rebase_options options = GIT_REBASE_OPTIONS_INIT;
+ 
+ 	rb_scan_args(argc, argv, "31:", &rb_repo, &rb_branch, &rb_upstream, &rb_onto, &rb_options);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if ((exception = rugged_get_annotated_commit(&branch, rb_repo, rb_branch)))
+ 		goto cleanup;
+diff --git a/ext/rugged/rugged_reference_collection.c b/ext/rugged/rugged_reference_collection.c
+index 907fa4c39..7639963c9 100644
+--- a/ext/rugged/rugged_reference_collection.c
++++ b/ext/rugged/rugged_reference_collection.c
+@@ -13,6 +13,8 @@ extern VALUE rb_cRuggedReference;
+ 
+ VALUE rb_cRuggedReferenceCollection;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ /*
+  *  call-seq:
+  *    ReferenceCollection.new(repo) -> refs
+@@ -56,7 +58,7 @@ static VALUE rb_git_reference_collection_create(int argc, VALUE *argv, VALUE sel
+ 	rb_scan_args(argc, argv, "20:", &rb_name, &rb_target, &rb_options);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 	Check_Type(rb_name, T_STRING);
+ 	Check_Type(rb_target, T_STRING);
+ 
+@@ -95,7 +97,7 @@ static VALUE rb_git_reference_collection_aref(VALUE self, VALUE rb_name) {
+ 	git_reference *ref;
+ 	int error;
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_lookup(&ref, repo, StringValueCStr(rb_name));
+ 
+@@ -119,7 +121,7 @@ static VALUE rb_git_reference_collection__each(int argc, VALUE *argv, VALUE self
+ 
+ 	rugged_check_repo(rb_repo);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!NIL_P(rb_glob)) {
+ 		Check_Type(rb_glob, T_STRING);
+@@ -210,7 +212,7 @@ static VALUE rb_git_reference_collection_exist_p(VALUE self, VALUE rb_name_or_re
+ 	if (TYPE(rb_name_or_ref) != T_STRING)
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Reference instance");
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_lookup(&ref, repo, StringValueCStr(rb_name_or_ref));
+ 	git_reference_free(ref);
+@@ -265,7 +267,7 @@ static VALUE rb_git_reference_collection_rename(int argc, VALUE *argv, VALUE sel
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Reference instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!NIL_P(rb_options)) {
+ 		VALUE rb_val = rb_hash_aref(rb_options, CSTR2SYM("message"));
+@@ -337,7 +339,7 @@ static VALUE rb_git_reference_collection_update(int argc, VALUE *argv, VALUE sel
+ 	}
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_lookup(&ref, repo, StringValueCStr(rb_name_or_ref));
+ 	rugged_exception_check(error);
+@@ -388,7 +390,7 @@ static VALUE rb_git_reference_collection_delete(VALUE self, VALUE rb_name_or_ref
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Reference instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_lookup(&ref, repo, StringValueCStr(rb_name_or_ref));
+ 	rugged_exception_check(error);
+diff --git a/ext/rugged/rugged_remote.c b/ext/rugged/rugged_remote.c
+index 943fc4fa6..7292c5822 100644
+--- a/ext/rugged/rugged_remote.c
++++ b/ext/rugged/rugged_remote.c
+@@ -12,6 +12,8 @@ extern VALUE rb_cRuggedRepo;
+ extern VALUE rb_eRuggedError;
+ VALUE rb_cRuggedRemote;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ static int progress_cb(const char *str, int len, void *data)
+ {
+ 	struct rugged_remote_cb_payload *payload = data;
+@@ -424,7 +426,7 @@ static VALUE rb_git_remote_set_push_url(VALUE self, VALUE rb_url)
+ 	git_repository *repo;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_url, T_STRING);
+ 	Data_Get_Struct(self, git_remote, remote);
+diff --git a/ext/rugged/rugged_remote_collection.c b/ext/rugged/rugged_remote_collection.c
+index 967f927d2..7751e432f 100644
+--- a/ext/rugged/rugged_remote_collection.c
++++ b/ext/rugged/rugged_remote_collection.c
+@@ -13,6 +13,8 @@ extern VALUE rb_eRuggedError;
+ extern VALUE rb_cRuggedRemote;
+ VALUE rb_cRuggedRemoteCollection;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ /*
+  *  call-seq:
+  *    RemoteCollection.new(repo) -> remotes
+@@ -45,7 +47,7 @@ static VALUE rb_git_remote_collection_create_anonymous(VALUE self, VALUE rb_url)
+ 	VALUE rb_repo = rugged_owner(self);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_url, T_STRING);
+ 
+@@ -80,7 +82,7 @@ static VALUE rb_git_remote_collection_create(VALUE self, VALUE rb_name, VALUE rb
+ 	VALUE rb_repo = rugged_owner(self);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 	Check_Type(rb_url, T_STRING);
+@@ -115,7 +117,7 @@ static VALUE rb_git_remote_collection_aref(VALUE self, VALUE rb_name)
+ 
+ 	VALUE rb_repo = rugged_owner(self);
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -143,7 +145,7 @@ static VALUE rb_git_remote_collection__each(VALUE self, int only_names)
+ 
+ 	rb_repo = rugged_owner(self);
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_remote_list(&remotes, repo);
+ 	rugged_exception_check(error);
+@@ -244,7 +246,7 @@ static VALUE rb_git_remote_collection_rename(VALUE self, VALUE rb_name_or_remote
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_remote_rename(&problems, repo, StringValueCStr(rb_name_or_remote), StringValueCStr(rb_new_name));
+ 	rugged_exception_check(error);
+@@ -283,7 +285,7 @@ static VALUE rb_git_remote_collection_delete(VALUE self, VALUE rb_name_or_remote
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	rugged_exception_check(
+ 		git_remote_delete(repo, StringValueCStr(rb_name_or_remote))
+@@ -314,7 +316,7 @@ static VALUE rb_git_remote_collection_set_url(VALUE self, VALUE rb_name_or_remot
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_url, T_STRING);
+ 
+@@ -347,7 +349,7 @@ static VALUE rb_git_remote_collection_set_push_url(VALUE self, VALUE rb_name_or_
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_url, T_STRING);
+ 
+@@ -371,7 +373,7 @@ static VALUE rb_git_remote_collection_add_refspec(VALUE self, VALUE rb_name_or_r
+ 		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance");
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_refspec, T_STRING);
+ 
+diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c
+index 8827d000a..b69be69d3 100644
+--- a/ext/rugged/rugged_repo.c
++++ b/ext/rugged/rugged_repo.c
+@@ -34,6 +34,8 @@ VALUE rb_cRuggedOdbObject;
+ 
+ static ID id_call;
+ 
++const rb_data_type_t rugged_repository_type;
++
+ extern const rb_data_type_t rugged_object_type;
+ static const rb_data_type_t rugged_odb_object_type;
+ 
+@@ -143,14 +145,23 @@ VALUE rugged_raw_read(git_repository *repo, const git_oid *oid)
+ 	return TypedData_Wrap_Struct(rb_cRuggedOdbObject, &rugged_odb_object_type, obj);
+ }
+ 
+-void rb_git_repo__free(git_repository *repo)
++void rb_git_repo__free(void *data)
+ {
++	git_repository *repo = (git_repository *) data;
+ 	git_repository_free(repo);
+ }
+ 
++const rb_data_type_t rugged_repository_type = {
++	.wrap_struct_name = "Rugged::Repository",
++	.function = {
++		.dfree = rb_git_repo__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_repo_new(VALUE klass, git_repository *repo)
+ {
+-	VALUE rb_repo = Data_Wrap_Struct(klass, NULL, &rb_git_repo__free, repo);
++	VALUE rb_repo = TypedData_Wrap_Struct(klass, &rugged_repository_type, repo);
+ 
+ #ifdef HAVE_RUBY_ENCODING_H
+ 	/* TODO: set this properly */
+@@ -613,7 +624,7 @@ static VALUE rb_git_repo_clone_at(int argc, VALUE *argv, VALUE klass)
+ 		git_repository *repo; \
+ 		git_##_object *data; \
+ 		int error; \
+-		Data_Get_Struct(self, git_repository, repo); \
++		TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo); \
+ 		error = git_repository_##_object(&data, repo); \
+ 		rugged_exception_check(error); \
+ 		rb_data = rugged_##_object##_new(_klass, self, data); \
+@@ -631,7 +642,7 @@ static VALUE rb_git_repo_clone_at(int argc, VALUE *argv, VALUE klass)
+ 	if (!NIL_P(rugged_owner(rb_data))) \
+ 		rb_raise(rb_eRuntimeError, \
+ 			"The given object is already owned by another repository"); \
+-	Data_Get_Struct(self, git_repository, repo); \
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo); \
+ 	Data_Get_Struct(rb_data, git_##_object, data); \
+ 	git_repository_set_##_object(repo, data); \
+ 	rb_old_data = rb_iv_get(self, "@" #_object); \
+@@ -712,7 +723,7 @@ static VALUE rb_git_repo_set_ident(VALUE self, VALUE rb_ident) {
+ 	git_repository *repo;
+ 	const char *name = NULL, *email = NULL;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!NIL_P(rb_ident)) {
+ 		Check_Type(rb_ident, T_HASH);
+@@ -750,7 +761,7 @@ static VALUE rb_git_repo_get_ident(VALUE self)
+ 	git_repository *repo;
+ 	const char *name = NULL, *email = NULL;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	rugged_exception_check(
+ 		git_repository_ident(&name, &email, repo)
+@@ -786,7 +797,7 @@ static VALUE rb_git_repo_merge_base(VALUE self, VALUE rb_args)
+ 	if (len < 2)
+ 		rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", len);
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	for (i = 0; !error && i < len; ++i) {
+ 		error = rugged_oid_get(&input_array[i], repo, rb_ary_entry(rb_args, i));
+@@ -830,7 +841,7 @@ static VALUE rb_git_repo_merge_bases(VALUE self, VALUE rb_args)
+ 	if (len < 2)
+ 		rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2+)", RARRAY_LEN(rb_args));
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	input_array = xmalloc(sizeof(git_oid) * len);
+ 
+@@ -898,7 +909,7 @@ static VALUE rb_git_repo_merge_analysis(int argc, VALUE *argv, VALUE self)
+ 
+ 	rb_scan_args(argc, argv, "10", &rb_their_commit);
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (TYPE(rb_their_commit) == T_STRING) {
+ 		rb_their_commit = rugged_object_rev_parse(self, rb_their_commit, 1);
+@@ -975,7 +986,7 @@ static VALUE rb_git_repo_revert_commit(int argc, VALUE *argv, VALUE self)
+ 		}
+ 	}
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	TypedData_Get_Struct(rb_revert_commit, git_commit, &rugged_object_type, revert_commit);
+ 	TypedData_Get_Struct(rb_our_commit, git_commit, &rugged_object_type, our_commit);
+ 
+@@ -1024,7 +1035,7 @@ static VALUE rb_git_repo_apply(int argc, VALUE *argv, VALUE self)
+ 	struct rugged_apply_cb_payload payload = { Qnil, Qnil, 0 };
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	if (git_repository_is_bare(repo)) {
+ 		location = GIT_APPLY_LOCATION_INDEX;
+ 	} else {
+@@ -1093,7 +1104,7 @@ static VALUE rb_git_repo_merge_commits(int argc, VALUE *argv, VALUE self)
+ 		rugged_parse_merge_options(&opts, rb_options);
+ 	}
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	TypedData_Get_Struct(rb_our_commit, git_commit, &rugged_object_type, our_commit);
+ 	TypedData_Get_Struct(rb_their_commit, git_commit, &rugged_object_type, their_commit);
+ 
+@@ -1124,7 +1135,7 @@ static VALUE rb_git_repo_exists(VALUE self, VALUE hex)
+ 	git_oid oid;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	Check_Type(hex, T_STRING);
+ 
+ 	error = git_oid_fromstrn(&oid, RSTRING_PTR(hex), RSTRING_LEN(hex));
+@@ -1154,7 +1165,7 @@ static VALUE rb_git_repo_read(VALUE self, VALUE hex)
+ 	git_oid oid;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	Check_Type(hex, T_STRING);
+ 
+ 	error = git_oid_fromstr(&oid, StringValueCStr(hex));
+@@ -1188,7 +1199,7 @@ static VALUE rb_git_repo_read_header(VALUE self, VALUE hex)
+ 	VALUE rb_hash;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	Check_Type(hex, T_STRING);
+ 
+ 	error = git_oid_fromstr(&oid, StringValueCStr(hex));
+@@ -1233,7 +1244,7 @@ static VALUE rb_git_repo_expand_oids(int argc, VALUE *argv, VALUE self)
+ 	long i, expand_count;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	rb_scan_args(argc, argv, "11", &rb_oids, &rb_expected_type);
+ 
+ 	Check_Type(rb_oids, T_ARRAY);
+@@ -1303,7 +1314,7 @@ static VALUE rb_git_repo_descendant_of(VALUE self, VALUE rb_commit, VALUE rb_anc
+ 	git_repository *repo;
+ 	git_oid commit, ancestor;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = rugged_oid_get(&commit, repo, rb_commit);
+ 	rugged_exception_check(error);
+@@ -1396,7 +1407,7 @@ static VALUE rb_git_repo_write(VALUE self, VALUE rb_buffer, VALUE rub_type)
+ 
+ 	git_otype type;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	Check_Type(rb_buffer, T_STRING);
+ 
+ 	error = git_repository_odb(&odb, repo);
+@@ -1421,7 +1432,7 @@ static VALUE rb_git_repo_write(VALUE self, VALUE rb_buffer, VALUE rub_type)
+ #define RB_GIT_REPO_GETTER(method) \
+ 	git_repository *repo; \
+ 	int error; \
+-	Data_Get_Struct(self, git_repository, repo); \
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo); \
+ 	error = git_repository_##method(repo); \
+ 	rugged_exception_check(error); \
+ 	return error ? Qtrue : Qfalse; \
+@@ -1497,7 +1508,7 @@ static VALUE rb_git_repo_set_head(VALUE self, VALUE rb_head)
+ 	git_repository *repo;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_head, T_STRING);
+ 	error = git_repository_set_head(repo, StringValueCStr(rb_head));
+@@ -1520,7 +1531,7 @@ static VALUE rb_git_repo_get_head(VALUE self)
+ 	git_reference *head;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_repository_head(&head, repo);
+ 	if (error == GIT_ENOTFOUND)
+@@ -1545,7 +1556,7 @@ static VALUE rb_git_repo_path(VALUE self)
+ 	git_repository *repo;
+ 	const char *path;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	path = git_repository_path(repo);
+ 
+ 	return path ? rb_str_new_utf8(path) : Qnil;
+@@ -1569,7 +1580,7 @@ static VALUE rb_git_repo_workdir(VALUE self)
+ 	git_repository *repo;
+ 	const char *workdir;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	workdir = git_repository_workdir(repo);
+ 
+ 	return workdir ? rb_str_new_utf8(workdir) : Qnil;
+@@ -1595,7 +1606,7 @@ static VALUE rb_git_repo_set_workdir(VALUE self, VALUE rb_workdir)
+ {
+ 	git_repository *repo;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	Check_Type(rb_workdir, T_STRING);
+ 
+ 	rugged_exception_check(
+@@ -1691,7 +1702,7 @@ static VALUE rb_git_repo_file_status(VALUE self, VALUE rb_path)
+ 	int error;
+ 	git_repository *repo;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	FilePathValue(rb_path);
+ 	error = git_status_file(&flags, repo, StringValueCStr(rb_path));
+ 	rugged_exception_check(error);
+@@ -1706,7 +1717,7 @@ static VALUE rb_git_repo_file_each_status(VALUE self)
+ 	git_repository *repo;
+ 	git_status_list *list;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!rb_block_given_p())
+ 		rb_raise(rb_eRuntimeError,
+@@ -1764,7 +1775,7 @@ static VALUE rb_git_repo_each_id(VALUE self)
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_repository_odb(&odb, repo);
+ 	rugged_exception_check(error);
+@@ -1828,7 +1839,7 @@ static VALUE rb_git_repo_reset(VALUE self, VALUE rb_target, VALUE rb_reset_type)
+ 	git_object *target = NULL;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	reset_type = parse_reset_type(rb_reset_type);
+ 	target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
+@@ -1869,7 +1880,7 @@ static VALUE rb_git_repo_reset_path(int argc, VALUE *argv, VALUE self)
+ 	pathspecs.strings = NULL;
+ 	pathspecs.count = 0;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	rb_scan_args(argc, argv, "11", &rb_paths, &rb_target);
+ 
+@@ -1901,7 +1912,7 @@ static VALUE rb_git_repo_reset_path(int argc, VALUE *argv, VALUE self)
+ static VALUE rb_git_repo_close(VALUE self)
+ {
+ 	git_repository *repo;
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	git_repository__cleanup(repo);
+ 
+@@ -1920,7 +1931,7 @@ static VALUE rb_git_repo_set_namespace(VALUE self, VALUE rb_namespace)
+ 	git_repository *repo;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!NIL_P(rb_namespace)) {
+ 		Check_Type(rb_namespace, T_STRING);
+@@ -1944,7 +1955,7 @@ static VALUE rb_git_repo_get_namespace(VALUE self)
+ 	git_repository *repo;
+ 	const char *namespace;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	namespace = git_repository_get_namespace(repo);
+ 	return namespace ? rb_str_new_utf8(namespace) : Qnil;
+@@ -1967,7 +1978,7 @@ static VALUE rb_git_repo_ahead_behind(VALUE self, VALUE rb_local, VALUE rb_upstr
+ 	size_t ahead, behind;
+ 	VALUE rb_result;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = rugged_oid_get(&local, repo, rb_local);
+ 	rugged_exception_check(error);
+@@ -2006,7 +2017,7 @@ static VALUE rb_git_repo_default_signature(VALUE self) {
+ 	git_signature *signature;
+ 	VALUE rb_signature;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_signature_default(&signature, repo);
+ 
+@@ -2372,7 +2383,7 @@ static VALUE rb_git_checkout_tree(int argc, VALUE *argv, VALUE self)
+ 		rb_raise(rb_eTypeError, "Expected Rugged::Commit, Rugged::Tag or Rugged::Tree");
+ 	}
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	TypedData_Get_Struct(rb_treeish, git_object, &rugged_object_type, treeish);
+ 
+ 	rugged_parse_checkout_options(&opts, rb_options);
+@@ -2420,7 +2431,7 @@ static VALUE rb_git_checkout_index(int argc, VALUE *argv, VALUE self)
+ 	if (!rb_obj_is_kind_of(rb_index, rb_cRuggedIndex))
+ 		rb_raise(rb_eTypeError, "Expected Rugged::Index");
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	Data_Get_Struct(rb_index, git_index, index);
+ 
+ 	rugged_parse_checkout_options(&opts, rb_options);
+@@ -2464,7 +2475,7 @@ static VALUE rb_git_checkout_head(int argc, VALUE *argv, VALUE self)
+ 
+ 	rb_scan_args(argc, argv, "00:", &rb_options);
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 
+ 	rugged_parse_checkout_options(&opts, rb_options);
+ 
+@@ -2501,7 +2512,7 @@ static VALUE rb_git_repo_is_path_ignored(VALUE self, VALUE rb_path) {
+ 	int error;
+ 	int ignored;
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	path = StringValueCStr(rb_path);
+ 	error = git_ignore_path_is_ignored(&ignored, repo, path);
+ 	rugged_exception_check(error);
+@@ -2557,7 +2568,7 @@ static VALUE rb_git_repo_attributes(int argc, VALUE *argv, VALUE self)
+ 
+ 	rb_scan_args(argc, argv, "12", &rb_path, &rb_names, &rb_options);
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	FilePathValue(rb_path);
+ 
+ 	if (!NIL_P(rb_options)) {
+@@ -2670,7 +2681,7 @@ static VALUE rb_git_repo_cherrypick(int argc, VALUE *argv, VALUE self)
+ 		rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
+ 	}
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	TypedData_Get_Struct(rb_commit, git_commit, &rugged_object_type, commit);
+ 
+ 	rugged_parse_cherrypick_options(&opts, rb_options);
+@@ -2723,7 +2734,7 @@ static VALUE rb_git_repo_cherrypick_commit(int argc, VALUE *argv, VALUE self)
+ 		rb_raise(rb_eArgError, "Expected a Rugged::Commit.");
+ 	}
+ 
+-	Data_Get_Struct(self, git_repository, repo);
++	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+ 	TypedData_Get_Struct(rb_commit, git_commit, &rugged_object_type, commit);
+ 	TypedData_Get_Struct(rb_our_commit, git_commit, &rugged_object_type, our_commit);
+ 
+diff --git a/ext/rugged/rugged_revwalk.c b/ext/rugged/rugged_revwalk.c
+index a58cc1b12..80c17ccef 100644
+--- a/ext/rugged/rugged_revwalk.c
++++ b/ext/rugged/rugged_revwalk.c
+@@ -12,6 +12,7 @@ extern VALUE rb_cRuggedObject;
+ VALUE rb_cRuggedWalker;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ static void rb_git_walk__free(git_revwalk *walk)
+ {
+@@ -90,7 +91,7 @@ static VALUE rb_git_walker_new(VALUE klass, VALUE rb_repo)
+ 	git_revwalk *walk;
+ 	int error;
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_revwalk_new(&walk, repo);
+ 	rugged_exception_check(error);
+@@ -370,7 +371,7 @@ static VALUE rb_git_walk(int argc, VALUE *argv, VALUE self)
+ 	RETURN_ENUMERATOR(self, argc, argv);
+ 	rb_scan_args(argc, argv, "10:", &rb_repo, &rb_options);
+ 
+-	Data_Get_Struct(rb_repo, git_repository, w.repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, w.repo);
+ 	rugged_exception_check(git_revwalk_new(&w.walk, w.repo));
+ 
+ 	w.rb_owner = rb_repo;
+diff --git a/ext/rugged/rugged_submodule.c b/ext/rugged/rugged_submodule.c
+index 5076a6b30..3eb44ec22 100644
+--- a/ext/rugged/rugged_submodule.c
++++ b/ext/rugged/rugged_submodule.c
+@@ -18,6 +18,8 @@ static ID id_ignore_none, id_ignore_untracked, id_ignore_dirty, id_ignore_all;
+ 
+ static ID id_update_checkout, id_update_rebase, id_update_merge, id_update_none;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ void init_status_list(void)
+ {
+ 	id_in_head            = CSTR2SYM("in_head");
+@@ -153,7 +155,7 @@ static VALUE rb_git_submodule_status(VALUE self)
+ 	unsigned int flags;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 	Data_Get_Struct(self, git_submodule, submodule);
+ 
+ 	rugged_exception_check(
+@@ -224,7 +226,7 @@ static VALUE rb_git_submodule_status_in_workdir(VALUE self)
+ 	git_submodule *submodule; \
+ 	unsigned int flags; \
+ 	rugged_check_repo(rb_repo); \
+-	Data_Get_Struct(rb_repo, git_repository, repo); \
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo); \
+ 	Data_Get_Struct(self, git_submodule, submodule); \
+ 	rugged_exception_check( \
+ 		git_submodule_status(&flags, repo, git_submodule_name(submodule), \
+@@ -348,7 +350,7 @@ static VALUE rb_git_submodule_status_untracked_files_in_workdir(VALUE self)
+ 	git_submodule *submodule; \
+ 	unsigned int flags; \
+ 	rugged_check_repo(rb_repo); \
+-	Data_Get_Struct(rb_repo, git_repository, repo); \
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo); \
+ 	Data_Get_Struct(self, git_submodule, submodule); \
+ 	rugged_exception_check( \
+ 		git_submodule_status(&flags, repo, git_submodule_name(submodule), \
+diff --git a/ext/rugged/rugged_submodule_collection.c b/ext/rugged/rugged_submodule_collection.c
+index ced2c01a2..6e6e24d89 100644
+--- a/ext/rugged/rugged_submodule_collection.c
++++ b/ext/rugged/rugged_submodule_collection.c
+@@ -11,6 +11,8 @@ extern VALUE rb_mRugged;
+ extern VALUE rb_cRuggedSubmodule;
+ VALUE rb_cRuggedSubmoduleCollection;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ /*
+  *  call-seq:
+  *    SubmoduleCollection.new(repo) -> submodules
+@@ -63,7 +65,7 @@ static VALUE rb_git_submodule_collection_aref(VALUE self, VALUE rb_name)
+ 	int error;
+ 
+ 	VALUE rb_repo = rugged_owner(self);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -89,7 +91,7 @@ static int cb_submodule__each(git_submodule *submodule, const char *name, void *
+ 	VALUE rb_repo;
+ 
+ 	rb_repo = payload->rb_data;
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	/* The submodule passed here has it's refcount decreased just after
+ 	 * the foreach finishes. The only way to increase that refcount is
+@@ -128,7 +130,7 @@ static VALUE rb_git_submodule_collection_each(VALUE self)
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+ 	rb_repo = rugged_owner(self);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	payload.exception = 0;
+ 	payload.rb_data = rb_repo;
+@@ -184,7 +186,7 @@ static VALUE rb_git_submodule_setup_add(int argc, VALUE *argv, VALUE self)
+ 	Check_Type(rb_path, T_STRING);
+ 
+ 	rb_repo = rugged_owner(self);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (!NIL_P(rb_options)) {
+ 		VALUE rb_val;
+@@ -281,7 +283,7 @@ static VALUE rb_git_submodule_update(VALUE self, VALUE rb_name_or_submodule, VAL
+ 	VALUE rb_url, rb_fetch_recurse_submodules, rb_ignore_rule, rb_update_rule;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if (rb_obj_is_kind_of(rb_name_or_submodule, rb_cRuggedSubmodule))
+ 		rb_name_or_submodule = rb_funcall(rb_name_or_submodule, rb_intern("name"), 0);
+diff --git a/ext/rugged/rugged_tag.c b/ext/rugged/rugged_tag.c
+index 060e78d6a..bf7a82666 100644
+--- a/ext/rugged/rugged_tag.c
++++ b/ext/rugged/rugged_tag.c
+@@ -16,6 +16,7 @@ VALUE rb_cRuggedTag;
+ VALUE rb_cRuggedTagAnnotation;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ /*
+  *  call-seq:
+@@ -161,7 +162,7 @@ static VALUE rb_git_tag_annotation(VALUE self)
+ 
+ 	rugged_check_repo(rb_repo);
+ 	Data_Get_Struct(self, git_reference, ref);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_resolve(&resolved_ref, ref);
+ 	rugged_exception_check(error);
+@@ -189,7 +190,7 @@ static VALUE rb_git_tag_target(VALUE self)
+ 
+ 	rugged_check_repo(rb_repo);
+ 	Data_Get_Struct(self, git_reference, ref);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_resolve(&resolved_ref, ref);
+ 	rugged_exception_check(error);
+diff --git a/ext/rugged/rugged_tag_collection.c b/ext/rugged/rugged_tag_collection.c
+index 8f5fd4bd5..f06711174 100644
+--- a/ext/rugged/rugged_tag_collection.c
++++ b/ext/rugged/rugged_tag_collection.c
+@@ -13,6 +13,8 @@ extern VALUE rb_cRuggedTag;
+ 
+ VALUE rb_cRuggedTagCollection;
+ 
++extern const rb_data_type_t rugged_repository_type;
++
+ /*
+  *  call-seq:
+  *    TagCollection.new(repo) -> refs
+@@ -42,7 +44,7 @@ static VALUE rb_git_tag_collection_aref(VALUE self, VALUE rb_name)
+ 	VALUE rb_repo = rugged_owner(self);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -76,7 +78,7 @@ static VALUE rb_git_tag_collection_delete(VALUE self, VALUE rb_name)
+ 	int error;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -116,7 +118,7 @@ static VALUE rb_git_tag_collection_create(int argc, VALUE *argv, VALUE self)
+ 	rb_scan_args(argc, argv, "21:", &rb_name, &rb_target, &rb_force, &rb_annotation);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -194,7 +196,7 @@ static VALUE rb_git_tag_collection_create_annotation(VALUE self, VALUE rb_name,
+ 
+ 	VALUE rb_repo = rugged_owner(self);
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_name, T_STRING);
+ 
+@@ -245,7 +247,7 @@ static VALUE each_tag(int argc, VALUE *argv, VALUE self, int tag_names_only)
+ 	}
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_tag_list_match(&tags, pattern ? pattern : "", repo);
+ 	rugged_exception_check(error);
+diff --git a/ext/rugged/rugged_tree.c b/ext/rugged/rugged_tree.c
+index 9d39f8cfa..ac26f370b 100644
+--- a/ext/rugged/rugged_tree.c
++++ b/ext/rugged/rugged_tree.c
+@@ -19,6 +19,7 @@ VALUE rb_cRuggedTree;
+ VALUE rb_cRuggedTreeBuilder;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_repository_type;
+ 
+ static VALUE rb_git_treeentry_fromC(const git_tree_entry *entry)
+ {
+@@ -348,7 +349,7 @@ static VALUE rb_git_diff_tree_to_index(VALUE self, VALUE rb_repo, VALUE rb_self,
+ 	git_index *index;
+ 	int error;
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 	Data_Get_Struct(rb_other, git_index, index);
+ 
+ 	rugged_parse_diff_options(&opts, rb_options);
+@@ -391,7 +392,7 @@ static VALUE rb_git_diff_tree_to_tree(VALUE self, VALUE rb_repo, VALUE rb_tree,
+ 	git_diff *diff = NULL;
+ 	struct nogvl_diff_args args;
+ 
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	if(RTEST(rb_tree))
+ 	    TypedData_Get_Struct(rb_tree, git_tree, &rugged_object_type, tree);
+@@ -439,7 +440,7 @@ static VALUE rb_git_tree_diff_workdir(int argc, VALUE *argv, VALUE self)
+ 
+ 	TypedData_Get_Struct(self, git_tree, &rugged_object_type, tree);
+ 	owner = rugged_owner(self);
+-	Data_Get_Struct(owner, git_repository, repo);
++	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_diff_tree_to_workdir(&diff, repo, tree, &opts);
+ 
+@@ -561,7 +562,7 @@ static VALUE rb_git_tree_merge(int argc, VALUE *argv, VALUE self)
+ 		rb_raise(rb_eTypeError, "Expecting a Rugged::Tree instance");
+ 
+ 	TypedData_Get_Struct(self, git_tree, &rugged_object_type, tree);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 	TypedData_Get_Struct(rb_other_tree, git_tree, &rugged_object_type, other_tree);
+ 
+ 	if (!NIL_P(rb_ancestor_tree))
+@@ -596,7 +597,7 @@ static VALUE rb_git_tree_empty(VALUE self, VALUE rb_repo)
+ 	git_tree *tree;
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	rugged_exception_check(git_tree_lookup(&tree, repo, &empty_tree));
+ 
+@@ -740,7 +741,7 @@ static VALUE rb_git_treebuilder_new(int argc, VALUE *argv, VALUE klass)
+ 	}
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(rb_repo, git_repository, repo);
++	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_treebuilder_new(&builder, repo, tree);
+ 	rugged_exception_check(error);
+
+From 77f25a547f9c2200863611f97409f918f32b4de1 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 18:40:03 +0100
+Subject: [PATCH 02/14] blame: use `TypedData` for `Blame`
+
+---
+ ext/rugged/rugged_blame.c | 24 +++++++++++++++++++-----
+ 1 file changed, 19 insertions(+), 5 deletions(-)
+
+diff --git a/ext/rugged/rugged_blame.c b/ext/rugged/rugged_blame.c
+index dba638925..5b9b8e117 100644
+--- a/ext/rugged/rugged_blame.c
++++ b/ext/rugged/rugged_blame.c
+@@ -84,6 +84,20 @@ static void rugged_parse_blame_options(git_blame_options *opts, git_repository *
+ 	}
+ }
+ 
++static void rb_git_blame__free(void *data)
++{
++	git_blame *blame = (git_blame *) data;
++	git_blame_free(blame);
++}
++
++const rb_data_type_t rugged_blame_type = {
++	.wrap_struct_name = "Rugged::Blame",
++	.function = {
++		.dfree = rb_git_blame__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ /*
+  *  call-seq:
+  *    Blame.new(repo, path, options = {}) -> blame
+@@ -147,7 +161,7 @@ static VALUE rb_git_blame_new(int argc, VALUE *argv, VALUE klass)
+ 		&blame, repo, StringValueCStr(rb_path), &opts
+ 	));
+ 
+-	return Data_Wrap_Struct(klass, NULL, &git_blame_free, blame);
++	return TypedData_Wrap_Struct(klass, &rugged_blame_type, blame);
+ }
+ 
+ /*
+@@ -162,7 +176,7 @@ static VALUE rb_git_blame_for_line(VALUE self, VALUE rb_line_no)
+ 	git_blame *blame;
+ 	int line_no;
+ 
+-	Data_Get_Struct(self, git_blame, blame);
++	TypedData_Get_Struct(self, git_blame, &rugged_blame_type, blame);
+ 	Check_Type(rb_line_no, T_FIXNUM);
+ 
+ 	line_no = NUM2INT(rb_line_no);
+@@ -186,7 +200,7 @@ static VALUE rb_git_blame_for_line(VALUE self, VALUE rb_line_no)
+ static VALUE rb_git_blame_count(VALUE self)
+ {
+ 	git_blame *blame;
+-	Data_Get_Struct(self, git_blame, blame);
++	TypedData_Get_Struct(self, git_blame, &rugged_blame_type, blame);
+ 	return UINT2NUM(git_blame_get_hunk_count(blame));
+ }
+ 
+@@ -212,7 +226,7 @@ static VALUE rb_git_blame_get_by_index(VALUE self, VALUE rb_index)
+ 	int index;
+ 	uint32_t blame_count;
+ 
+-	Data_Get_Struct(self, git_blame, blame);
++	TypedData_Get_Struct(self, git_blame, &rugged_blame_type, blame);
+ 	Check_Type(rb_index, T_FIXNUM);
+ 
+ 	index = NUM2INT(rb_index);
+@@ -251,7 +265,7 @@ static VALUE rb_git_blame_each(VALUE self)
+ 
+ 	RETURN_SIZED_ENUMERATOR(self, 0, 0, rugged_blame_enum_size);
+ 
+-	Data_Get_Struct(self, git_blame, blame);
++	TypedData_Get_Struct(self, git_blame, &rugged_blame_type, blame);
+ 
+ 	blame_count = git_blame_get_hunk_count(blame);
+ 	for (i = 0; i < blame_count; ++i) {
+
+From c11a68f2e0bc0c38de2ce34ed11fc1e0b7643944 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 18:45:38 +0100
+Subject: [PATCH 03/14] index: use `TypedData` for `Index`
+
+---
+ ext/rugged/rugged_index.c | 59 ++++++++++++++++++++++-----------------
+ ext/rugged/rugged_repo.c  |  4 +--
+ ext/rugged/rugged_tree.c  |  3 +-
+ 3 files changed, 38 insertions(+), 28 deletions(-)
+
+diff --git a/ext/rugged/rugged_index.c b/ext/rugged/rugged_index.c
+index 89afb4c08..7d549910b 100644
+--- a/ext/rugged/rugged_index.c
++++ b/ext/rugged/rugged_index.c
+@@ -23,14 +23,23 @@ static VALUE rb_git_indexentry_fromC(const git_index_entry *entry);
+  * Index
+  */
+ 
+-static void rb_git_index__free(git_index *index)
++static void rb_git_index__free(void *data)
+ {
++	git_index *index = (git_index *) data;
+ 	git_index_free(index);
+ }
+ 
++const rb_data_type_t rugged_index_type = {
++	.wrap_struct_name = "Rugged::Index",
++	.function = {
++		.dfree = rb_git_index__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index)
+ {
+-	VALUE rb_index = Data_Wrap_Struct(klass, NULL, &rb_git_index__free, index);
++	VALUE rb_index = TypedData_Wrap_Struct(klass, &rugged_index_type, index);
+ 	rugged_set_owner(rb_index, owner);
+ 	return rb_index;
+ }
+@@ -73,7 +82,7 @@ static VALUE rb_git_index_new(int argc, VALUE *argv, VALUE klass)
+ static VALUE rb_git_index_clear(VALUE self)
+ {
+ 	git_index *index;
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	git_index_clear(index);
+ 	return Qnil;
+ }
+@@ -90,7 +99,7 @@ static VALUE rb_git_index_read(VALUE self)
+ 	git_index *index;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	error = git_index_read(index, 0);
+ 	rugged_exception_check(error);
+@@ -109,7 +118,7 @@ static VALUE rb_git_index_write(VALUE self)
+ 	git_index *index;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	error = git_index_write(index);
+ 	rugged_exception_check(error);
+@@ -126,7 +135,7 @@ static VALUE rb_git_index_write(VALUE self)
+ static VALUE rb_git_index_count(VALUE self)
+ {
+ 	git_index *index;
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	return INT2FIX(git_index_entrycount(index));
+ }
+ 
+@@ -149,7 +158,7 @@ static VALUE rb_git_index_get(int argc, VALUE *argv, VALUE self)
+ 
+ 	VALUE rb_entry, rb_stage;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);
+ 
+@@ -194,7 +203,7 @@ static VALUE rb_git_index_each(VALUE self)
+ 	unsigned int i, count;
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	count = (unsigned int)git_index_entrycount(index);
+ 	for (i = 0; i < count; ++i) {
+@@ -220,7 +229,7 @@ static VALUE rb_git_index_remove(int argc, VALUE *argv, VALUE self)
+ 
+ 	VALUE rb_entry, rb_stage;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	if (rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage) > 1) {
+ 		Check_Type(rb_stage, T_FIXNUM);
+@@ -249,7 +258,7 @@ static VALUE rb_git_index_remove_directory(int argc, VALUE *argv, VALUE self)
+ 
+ 	VALUE rb_dir, rb_stage;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	if (rb_scan_args(argc, argv, "11", &rb_dir, &rb_stage) > 1) {
+ 		Check_Type(rb_stage, T_FIXNUM);
+@@ -293,7 +302,7 @@ static VALUE rb_git_index_add(VALUE self, VALUE rb_entry)
+ 	git_index *index;
+ 	int error = 0;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	if (TYPE(rb_entry) == T_HASH) {
+ 		git_index_entry entry;
+@@ -379,7 +388,7 @@ static VALUE rb_git_index_add_all(int argc, VALUE *argv, VALUE self)
+ 	int error, exception = 0;
+ 	unsigned int flags = GIT_INDEX_ADD_DEFAULT;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	if (rb_scan_args(argc, argv, "02", &rb_pathspecs, &rb_options) > 1) {
+ 		Check_Type(rb_options, T_HASH);
+@@ -440,7 +449,7 @@ static VALUE rb_git_index_update_all(int argc, VALUE *argv, VALUE self)
+ 	git_strarray pathspecs;
+ 	int error, exception = 0;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	rb_scan_args(argc, argv, "01", &rb_pathspecs);
+ 
+@@ -483,7 +492,7 @@ static VALUE rb_git_index_remove_all(int argc, VALUE *argv, VALUE self)
+ 	git_strarray pathspecs;
+ 	int error, exception = 0;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	rb_scan_args(argc, argv, "01", &rb_pathspecs);
+ 
+@@ -629,7 +638,7 @@ static VALUE rb_git_index_writetree(int argc, VALUE *argv, VALUE self)
+ 	int error;
+ 	VALUE rb_repo;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	if (rb_scan_args(argc, argv, "01", &rb_repo) == 1) {
+ 		git_repository *repo = NULL;
+@@ -660,7 +669,7 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
+ 	git_tree *tree;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	TypedData_Get_Struct(rb_tree, git_tree, &rugged_object_type, tree);
+ 
+ 	if (!rb_obj_is_kind_of(rb_tree, rb_cRuggedTree)) {
+@@ -685,7 +694,7 @@ static VALUE rb_git_diff_tree_to_index(VALUE self, VALUE rb_other, VALUE rb_opti
+ 
+ 	rugged_parse_diff_options(&opts, rb_options);
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	owner = rugged_owner(self);
+ 	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+@@ -713,7 +722,7 @@ static VALUE rb_git_diff_index_to_workdir(VALUE self, VALUE rb_options)
+ 
+ 	rugged_parse_diff_options(&opts, rb_options);
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	owner = rugged_owner(self);
+ 	TypedData_Get_Struct(owner, git_repository, &rugged_repository_type, repo);
+ 
+@@ -734,7 +743,7 @@ static VALUE rb_git_diff_index_to_workdir(VALUE self, VALUE rb_options)
+ static VALUE rb_git_index_conflicts_p(VALUE self)
+ {
+ 	git_index *index;
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	return git_index_has_conflicts(index) ? Qtrue : Qfalse;
+ }
+ 
+@@ -771,7 +780,7 @@ static VALUE rb_git_conflict_add(VALUE self, VALUE rb_conflict)
+ 	if (!NIL_P(rb_theirs))
+ 		rb_git_indexentry_toC(&theirs, rb_theirs);
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	error = git_index_conflict_add(index,
+ 		NIL_P(rb_ancestor) ? NULL : &ancestor,
+@@ -795,7 +804,7 @@ static VALUE rb_git_conflict_remove(VALUE self, VALUE rb_path)
+ 
+ 	Check_Type(rb_path, T_STRING);
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	error = git_index_conflict_remove(index, StringValueCStr(rb_path));
+ 	rugged_exception_check(error);
+@@ -824,7 +833,7 @@ static VALUE rb_git_conflict_get(VALUE self, VALUE rb_path)
+ 
+ 	Check_Type(rb_path, T_STRING);
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	error = git_index_conflict_get(&ancestor, &ours, &theirs, index, StringValueCStr(rb_path));
+ 	if (error == GIT_ENOTFOUND)
+@@ -895,7 +904,7 @@ static VALUE rb_git_merge_file(int argc, VALUE *argv, VALUE self)
+ 
+ 	Check_Type(rb_path, T_STRING);
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	rugged_check_repo(rb_repo);
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+@@ -931,7 +940,7 @@ static VALUE rb_git_conflict_cleanup(VALUE self)
+ {
+ 	git_index *index;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 	git_index_conflict_cleanup(index);
+ 
+ 	return Qnil;
+@@ -957,7 +966,7 @@ static VALUE rb_git_index_conflicts(VALUE self)
+ 	const git_index_entry *ancestor, *ours, *theirs;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_index, index);
++	TypedData_Get_Struct(self, git_index, &rugged_index_type, index);
+ 
+ 	error = git_index_conflict_iterator_new(&iter, index);
+ 	rugged_exception_check(error);
+diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c
+index b69be69d3..2055bb2cb 100644
+--- a/ext/rugged/rugged_repo.c
++++ b/ext/rugged/rugged_repo.c
+@@ -34,8 +34,8 @@ VALUE rb_cRuggedOdbObject;
+ 
+ static ID id_call;
+ 
++extern const rb_data_type_t rugged_index_type;
+ const rb_data_type_t rugged_repository_type;
+-
+ extern const rb_data_type_t rugged_object_type;
+ static const rb_data_type_t rugged_odb_object_type;
+ 
+@@ -2432,7 +2432,7 @@ static VALUE rb_git_checkout_index(int argc, VALUE *argv, VALUE self)
+ 		rb_raise(rb_eTypeError, "Expected Rugged::Index");
+ 
+ 	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo);
+-	Data_Get_Struct(rb_index, git_index, index);
++	TypedData_Get_Struct(rb_index, git_index, &rugged_index_type, index);
+ 
+ 	rugged_parse_checkout_options(&opts, rb_options);
+ 
+diff --git a/ext/rugged/rugged_tree.c b/ext/rugged/rugged_tree.c
+index ac26f370b..5fdada954 100644
+--- a/ext/rugged/rugged_tree.c
++++ b/ext/rugged/rugged_tree.c
+@@ -18,6 +18,7 @@ extern VALUE rb_cRuggedCommit;
+ VALUE rb_cRuggedTree;
+ VALUE rb_cRuggedTreeBuilder;
+ 
++extern const rb_data_type_t rugged_index_type;
+ extern const rb_data_type_t rugged_object_type;
+ extern const rb_data_type_t rugged_repository_type;
+ 
+@@ -350,7 +351,7 @@ static VALUE rb_git_diff_tree_to_index(VALUE self, VALUE rb_repo, VALUE rb_self,
+ 	int error;
+ 
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+-	Data_Get_Struct(rb_other, git_index, index);
++	TypedData_Get_Struct(rb_other, git_index, &rugged_index_type, index);
+ 
+ 	rugged_parse_diff_options(&opts, rb_options);
+ 
+
+From e3ad4e40c808e6982dd3f4c9784e4a7a27894cf8 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 18:51:40 +0100
+Subject: [PATCH 04/14] revwalk: use `TypedData` for `Walker`
+
+---
+ ext/rugged/rugged_revwalk.c | 29 +++++++++++++++++++----------
+ 1 file changed, 19 insertions(+), 10 deletions(-)
+
+diff --git a/ext/rugged/rugged_revwalk.c b/ext/rugged/rugged_revwalk.c
+index 80c17ccef..11bbe3d67 100644
+--- a/ext/rugged/rugged_revwalk.c
++++ b/ext/rugged/rugged_revwalk.c
+@@ -14,14 +14,23 @@ VALUE rb_cRuggedWalker;
+ extern const rb_data_type_t rugged_object_type;
+ extern const rb_data_type_t rugged_repository_type;
+ 
+-static void rb_git_walk__free(git_revwalk *walk)
++static void rb_git_walk__free(void *data)
+ {
++	git_revwalk *walk = (git_revwalk *) data;
+ 	git_revwalk_free(walk);
+ }
+ 
++const rb_data_type_t rugged_walk_type = {
++	.wrap_struct_name = "Rugged::Walker",
++	.function = {
++		.dfree = rb_git_walk__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_walker_new(VALUE klass, VALUE owner, git_revwalk *walk)
+ {
+-	VALUE rb_walk = Data_Wrap_Struct(klass, NULL, &rb_git_walk__free, walk);
++	VALUE rb_walk = TypedData_Wrap_Struct(klass, &rugged_walk_type, walk);
+ 	rugged_set_owner(rb_walk, owner);
+ 	return rb_walk;
+ }
+@@ -118,7 +127,7 @@ static VALUE rb_git_walker_new(VALUE klass, VALUE rb_repo)
+ static VALUE rb_git_walker_push(VALUE self, VALUE rb_commit)
+ {
+ 	git_revwalk *walk;
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 	push_commit(walk, rb_commit, 0);
+ 	return Qnil;
+ }
+@@ -126,7 +135,7 @@ static VALUE rb_git_walker_push(VALUE self, VALUE rb_commit)
+ static VALUE rb_git_walker_push_range(VALUE self, VALUE range)
+ {
+ 	git_revwalk *walk;
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 	rugged_exception_check(git_revwalk_push_range(walk, StringValueCStr(range)));
+ 	return Qnil;
+ }
+@@ -141,7 +150,7 @@ static VALUE rb_git_walker_push_range(VALUE self, VALUE range)
+ static VALUE rb_git_walker_hide(VALUE self, VALUE rb_commit)
+ {
+ 	git_revwalk *walk;
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 	push_commit(walk, rb_commit, 1);
+ 	return Qnil;
+ }
+@@ -157,7 +166,7 @@ static VALUE rb_git_walker_hide(VALUE self, VALUE rb_commit)
+ static VALUE rb_git_walker_sorting(VALUE self, VALUE ruby_sort_mode)
+ {
+ 	git_revwalk *walk;
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 	git_revwalk_sorting(walk, FIX2INT(ruby_sort_mode));
+ 	return Qnil;
+ }
+@@ -171,7 +180,7 @@ static VALUE rb_git_walker_sorting(VALUE self, VALUE ruby_sort_mode)
+ static VALUE rb_git_walker_simplify_first_parent(VALUE self)
+ {
+ 	git_revwalk *walk;
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 	git_revwalk_simplify_first_parent(walk);
+ 	return Qnil;
+ }
+@@ -193,7 +202,7 @@ static VALUE rb_git_walker_count(int argc, VALUE *argv, VALUE self)
+ 	if (argc > 0 || rb_block_given_p())
+ 		return rb_call_super(argc, argv);
+ 
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 
+ 	while (((error = git_revwalk_next(&commit_oid, walk)) == 0) && ++count != UINT64_MAX);
+ 
+@@ -213,7 +222,7 @@ static VALUE rb_git_walker_count(int argc, VALUE *argv, VALUE self)
+ static VALUE rb_git_walker_reset(VALUE self)
+ {
+ 	git_revwalk *walk;
+-	Data_Get_Struct(self, git_revwalk, walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, walk);
+ 	git_revwalk_reset(walk);
+ 	return Qnil;
+ }
+@@ -403,7 +412,7 @@ static VALUE rb_git_walk_with_opts(int argc, VALUE *argv, VALUE self, int oid_on
+ 	RETURN_ENUMERATOR(self, argc, argv);
+ 	rb_scan_args(argc, argv, "01", &rb_options);
+ 
+-	Data_Get_Struct(self, git_revwalk, w.walk);
++	TypedData_Get_Struct(self, git_revwalk, &rugged_walk_type, w.walk);
+ 	w.repo = git_revwalk_repository(w.walk);
+ 
+ 	w.rb_owner = rugged_owner(self);
+
+From d33761a5c1e1b37ee74f817b556d819430ddef65 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 18:53:46 +0100
+Subject: [PATCH 05/14] config: use `TypedData` for `Config`
+
+---
+ ext/rugged/rugged_config.c | 31 ++++++++++++++++++++-----------
+ 1 file changed, 20 insertions(+), 11 deletions(-)
+
+diff --git a/ext/rugged/rugged_config.c b/ext/rugged/rugged_config.c
+index 3e0bad40c..bf4f9838c 100644
+--- a/ext/rugged/rugged_config.c
++++ b/ext/rugged/rugged_config.c
+@@ -10,14 +10,23 @@
+ extern VALUE rb_mRugged;
+ VALUE rb_cRuggedConfig;
+ 
+-void rb_git_config__free(git_config *config)
++void rb_git_config__free(void *data)
+ {
++	git_config *config = (git_config *) data;
+ 	git_config_free(config);
+ }
+ 
++const rb_data_type_t rugged_config_type = {
++	.wrap_struct_name = "Rugged::config",
++	.function = {
++		.dfree = rb_git_config__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg)
+ {
+-	VALUE rb_config = Data_Wrap_Struct(klass, NULL, &rb_git_config__free, cfg);
++	VALUE rb_config = TypedData_Wrap_Struct(klass, &rugged_config_type, cfg);
+ 	rugged_set_owner(rb_config, owner);
+ 	return rb_config;
+ }
+@@ -80,7 +89,7 @@ static VALUE rb_git_config_get(VALUE self, VALUE rb_key)
+ 	int error;
+ 	VALUE rb_result;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 	Check_Type(rb_key, T_STRING);
+ 
+ 	error = git_config_get_string_buf(&buf, config, StringValueCStr(rb_key));
+@@ -115,7 +124,7 @@ static VALUE rb_git_config_store(VALUE self, VALUE rb_key, VALUE rb_val)
+ 	const char *key;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 	Check_Type(rb_key, T_STRING);
+ 
+ 	key = StringValueCStr(rb_key);
+@@ -158,7 +167,7 @@ static VALUE rb_git_config_delete(VALUE self, VALUE rb_key)
+ 	git_config *config;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 	Check_Type(rb_key, T_STRING);
+ 
+ 	error = git_config_delete_entry(config, StringValueCStr(rb_key));
+@@ -220,7 +229,7 @@ static VALUE rb_git_config_each_key(VALUE self)
+ 	int error, exception;
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 
+ 	error = git_config_foreach(config, &cb_config__each_key, &exception);
+ 	if (error == GIT_EUSER)
+@@ -250,7 +259,7 @@ static VALUE rb_git_config_each_pair(VALUE self)
+ 	int error, exception;
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 
+ 	error = git_config_foreach(config, &cb_config__each_pair, &exception);
+ 	if (error == GIT_EUSER)
+@@ -276,7 +285,7 @@ static VALUE rb_git_config_to_hash(VALUE self)
+ 	int error;
+ 	VALUE hash;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 	hash = rb_hash_new();
+ 
+ 	error = git_config_foreach(config, &cb_config__to_hash, (void *)hash);
+@@ -317,7 +326,7 @@ static VALUE rb_git_config_snapshot(VALUE self)
+ {
+ 	git_config *config, *snapshot;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 
+ 	rugged_exception_check(
+ 		git_config_snapshot(&snapshot, config)
+@@ -348,7 +357,7 @@ static VALUE rb_git_config_transaction(VALUE self)
+ 	VALUE rb_result;
+ 	int error = 0, exception = 0;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 
+ 	git_config_lock(&tx, config);
+ 
+@@ -392,7 +401,7 @@ static VALUE rb_git_config_get_all(VALUE self, VALUE key)
+ 	VALUE list;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_config, config);
++	TypedData_Get_Struct(self, git_config, &rugged_config_type, config);
+ 
+ 	list = rb_ary_new();
+ 	error = git_config_get_multivar_foreach(
+
+From e1168088aa6dc28384b36f7901ee2ebff682b8ea Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 18:58:01 +0100
+Subject: [PATCH 06/14] reference: use `TypedData` for `Reference`
+
+---
+ ext/rugged/rugged_branch.c    | 13 +++++++------
+ ext/rugged/rugged_rebase.c    |  3 ++-
+ ext/rugged/rugged_reference.c | 35 ++++++++++++++++++++++-------------
+ ext/rugged/rugged_tag.c       |  5 +++--
+ 4 files changed, 34 insertions(+), 22 deletions(-)
+
+diff --git a/ext/rugged/rugged_branch.c b/ext/rugged/rugged_branch.c
+index fd0e5d49f..1c6126095 100644
+--- a/ext/rugged/rugged_branch.c
++++ b/ext/rugged/rugged_branch.c
+@@ -13,6 +13,7 @@ extern VALUE rb_cRuggedObject;
+ extern VALUE rb_cRuggedReference;
+ VALUE rb_cRuggedBranch;
+ 
++extern const rb_data_type_t rugged_reference_type;
+ extern const rb_data_type_t rugged_repository_type;
+ 
+ static inline VALUE rugged_branch_new(VALUE owner, git_reference *ref)
+@@ -29,7 +30,7 @@ static inline VALUE rugged_branch_new(VALUE owner, git_reference *ref)
+ static VALUE rb_git_branch_head_p(VALUE self)
+ {
+ 	git_reference *branch;
+-	Data_Get_Struct(self, git_reference, branch);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, branch);
+ 	return git_branch_is_head(branch) ? Qtrue : Qfalse;
+ }
+ 
+@@ -46,7 +47,7 @@ static VALUE rb_git_branch_name(VALUE self)
+ {
+ 	git_reference *branch;
+ 	const char *branch_name;
+-	Data_Get_Struct(self, git_reference, branch);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, branch);
+ 
+ 	rugged_exception_check(git_branch_name(&branch_name, branch));
+ 
+@@ -88,7 +89,7 @@ static VALUE rb_git_branch_remote_name(VALUE self)
+ 	git_reference *branch, *remote_ref;
+ 	int error = 0;
+ 
+-	Data_Get_Struct(self, git_reference, branch);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, branch);
+ 
+ 	if (git_reference_is_remote(branch)) {
+ 		remote_ref = branch;
+@@ -118,7 +119,7 @@ static VALUE rb_git_branch_upstream(VALUE self)
+ 	git_reference *branch, *upstream_branch;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_reference, branch);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, branch);
+ 
+ 	if (git_reference_is_remote(branch))
+ 		return Qnil;
+@@ -147,12 +148,12 @@ static VALUE rb_git_branch_set_upstream(VALUE self, VALUE rb_branch)
+ 	git_reference *branch, *target_branch;
+ 	const char *target_branch_name;
+ 
+-	Data_Get_Struct(self, git_reference, branch);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, branch);
+ 	if (!NIL_P(rb_branch)) {
+ 		if (!rb_obj_is_kind_of(rb_branch, rb_cRuggedReference))
+ 			rb_raise(rb_eTypeError, "Expecting a Rugged::Reference instance");
+ 
+-		Data_Get_Struct(rb_branch, git_reference, target_branch);
++		TypedData_Get_Struct(rb_branch, git_reference, &rugged_reference_type, target_branch);
+ 
+ 		rugged_exception_check(
+ 			git_branch_name(&target_branch_name, target_branch)
+diff --git a/ext/rugged/rugged_rebase.c b/ext/rugged/rugged_rebase.c
+index f65cc4653..47df5b2ec 100644
+--- a/ext/rugged/rugged_rebase.c
++++ b/ext/rugged/rugged_rebase.c
+@@ -16,6 +16,7 @@ extern VALUE rb_cRuggedReference;
+ VALUE rb_cRuggedRebase;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_reference_type;
+ extern const rb_data_type_t rugged_repository_type;
+ 
+ static VALUE rebase_operation_type(git_rebase_operation *operation);
+@@ -80,7 +81,7 @@ static void get_annotated_commit(git_annotated_commit **annotated_commit, VALUE
+ 	} else if (rb_obj_is_kind_of(rb_value, rb_cRuggedReference)) {
+ 		const git_reference * ref;
+ 
+-		Data_Get_Struct(rb_value, git_reference, ref);
++		TypedData_Get_Struct(rb_value, git_reference, &rugged_reference_type, ref);
+ 
+ 		error = git_annotated_commit_from_ref(annotated_commit, repo, ref);
+ 	} else if (TYPE(rb_value) == T_STRING) {
+diff --git a/ext/rugged/rugged_reference.c b/ext/rugged/rugged_reference.c
+index 4303405f9..58b024b03 100644
+--- a/ext/rugged/rugged_reference.c
++++ b/ext/rugged/rugged_reference.c
+@@ -12,14 +12,23 @@ extern VALUE rb_cRuggedRepo;
+ 
+ VALUE rb_cRuggedReference;
+ 
+-void rb_git_ref__free(git_reference *ref)
++void rb_git_ref__free(void *data)
+ {
++	git_reference *ref = (git_reference *) data;
+ 	git_reference_free(ref);
+ }
+ 
++const rb_data_type_t rugged_reference_type = {
++	.wrap_struct_name = "Rugged::Reference",
++	.function = {
++		.dfree = rb_git_ref__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref)
+ {
+-	VALUE rb_ref = Data_Wrap_Struct(klass, NULL, &rb_git_ref__free, ref);
++	VALUE rb_ref = TypedData_Wrap_Struct(klass, &rugged_reference_type, ref);
+ 	rugged_set_owner(rb_ref, owner);
+ 	return rb_ref;
+ }
+@@ -73,7 +82,7 @@ static VALUE rb_git_ref_peel(VALUE self)
+ 	char oid[GIT_OID_HEXSZ + 1];
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 
+ 	error = git_reference_peel(&object, ref, GIT_OBJ_ANY);
+ 	if (error == GIT_ENOTFOUND)
+@@ -114,7 +123,7 @@ static VALUE rb_git_ref_target(VALUE self)
+ {
+ 	git_reference *ref;
+ 
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 
+ 	if (git_reference_type(ref) == GIT_REF_OID) {
+ 		git_object *target;
+@@ -155,7 +164,7 @@ static VALUE rb_git_ref_target(VALUE self)
+ static VALUE rb_git_ref_target_id(VALUE self)
+ {
+ 	git_reference *ref;
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 
+ 	if (git_reference_type(ref) == GIT_REF_OID) {
+ 		return rugged_create_oid(git_reference_target(ref));
+@@ -173,7 +182,7 @@ static VALUE rb_git_ref_target_id(VALUE self)
+ static VALUE rb_git_ref_type(VALUE self)
+ {
+ 	git_reference *ref;
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 
+ 	switch (git_reference_type(ref)) {
+ 		case GIT_REF_OID:
+@@ -201,7 +210,7 @@ static VALUE rb_git_ref_type(VALUE self)
+ static VALUE rb_git_ref_name(VALUE self)
+ {
+ 	git_reference *ref;
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	return rb_str_new_utf8(git_reference_name(ref));
+ }
+ 
+@@ -224,7 +233,7 @@ static VALUE rb_git_ref_resolve(VALUE self)
+ 	git_reference *resolved;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 
+ 	error = git_reference_resolve(&resolved, ref);
+ 	rugged_exception_check(error);
+@@ -290,7 +299,7 @@ static VALUE rb_git_reflog(VALUE self)
+ 	VALUE rb_log;
+ 	size_t i, ref_count;
+ 
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 
+ 	error = git_reflog_read(&reflog, git_reference_owner(ref), git_reference_name(ref));
+ 	rugged_exception_check(error);
+@@ -320,7 +329,7 @@ static VALUE rb_git_has_reflog(VALUE self)
+ 	git_reference *ref;
+ 	git_repository *repo;
+ 
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	repo = git_reference_owner(ref);
+ 
+ 	return git_reference_has_log(repo, git_reference_name(ref)) ? Qtrue : Qfalse;
+@@ -335,7 +344,7 @@ static VALUE rb_git_has_reflog(VALUE self)
+ static VALUE rb_git_ref_is_branch(VALUE self)
+ {
+ 	git_reference *ref;
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	return git_reference_is_branch(ref) ? Qtrue : Qfalse;
+ }
+ 
+@@ -348,7 +357,7 @@ static VALUE rb_git_ref_is_branch(VALUE self)
+ static VALUE rb_git_ref_is_remote(VALUE self)
+ {
+ 	git_reference *ref;
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	return git_reference_is_remote(ref) ? Qtrue : Qfalse;
+ }
+ 
+@@ -361,7 +370,7 @@ static VALUE rb_git_ref_is_remote(VALUE self)
+ static VALUE rb_git_ref_is_tag(VALUE self)
+ {
+ 	git_reference *ref;
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	return git_reference_is_tag(ref) ? Qtrue : Qfalse;
+ }
+ 
+diff --git a/ext/rugged/rugged_tag.c b/ext/rugged/rugged_tag.c
+index bf7a82666..f86eb4684 100644
+--- a/ext/rugged/rugged_tag.c
++++ b/ext/rugged/rugged_tag.c
+@@ -16,6 +16,7 @@ VALUE rb_cRuggedTag;
+ VALUE rb_cRuggedTagAnnotation;
+ 
+ extern const rb_data_type_t rugged_object_type;
++extern const rb_data_type_t rugged_reference_type;
+ extern const rb_data_type_t rugged_repository_type;
+ 
+ /*
+@@ -161,7 +162,7 @@ static VALUE rb_git_tag_annotation(VALUE self)
+ 	VALUE rb_repo = rugged_owner(self);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_resolve(&resolved_ref, ref);
+@@ -189,7 +190,7 @@ static VALUE rb_git_tag_target(VALUE self)
+ 	VALUE rb_repo = rugged_owner(self);
+ 
+ 	rugged_check_repo(rb_repo);
+-	Data_Get_Struct(self, git_reference, ref);
++	TypedData_Get_Struct(self, git_reference, &rugged_reference_type, ref);
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	error = git_reference_resolve(&resolved_ref, ref);
+
+From 37b47fd965425b8a35ad03a7949769190230289b Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:00:12 +0100
+Subject: [PATCH 07/14] remote: use `TypedData` for `Remote`
+
+---
+ ext/rugged/rugged_remote.c | 31 ++++++++++++++++++++-----------
+ 1 file changed, 20 insertions(+), 11 deletions(-)
+
+diff --git a/ext/rugged/rugged_remote.c b/ext/rugged/rugged_remote.c
+index 7292c5822..30ab6c2f4 100644
+--- a/ext/rugged/rugged_remote.c
++++ b/ext/rugged/rugged_remote.c
+@@ -245,16 +245,25 @@ static int parse_prune_type(VALUE rb_prune_type)
+ 	}
+ }
+ 
+-static void rb_git_remote__free(git_remote *remote)
++static void rb_git_remote__free(void *data)
+ {
++	git_remote *remote = (git_remote *) data;
+ 	git_remote_free(remote);
+ }
+ 
++const rb_data_type_t rugged_remote_type = {
++	.wrap_struct_name = "Rugged::Remote",
++	.function = {
++		.dfree = rb_git_remote__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_remote_new(VALUE owner, git_remote *remote)
+ {
+ 	VALUE rb_remote;
+ 
+-	rb_remote = Data_Wrap_Struct(rb_cRuggedRemote, NULL, &rb_git_remote__free, remote);
++	rb_remote = TypedData_Wrap_Struct(rb_cRuggedRemote, &rugged_remote_type, remote);
+ 	rugged_set_owner(rb_remote, owner);
+ 	return rb_remote;
+ }
+@@ -328,7 +337,7 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
+ 	size_t heads_len, i;
+ 
+ 	RETURN_ENUMERATOR(self, argc, argv);
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 	rb_scan_args(argc, argv, ":", &rb_options);
+ 
+ 	rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
+@@ -367,7 +376,7 @@ static VALUE rb_git_remote_name(VALUE self)
+ {
+ 	git_remote *remote;
+ 	const char * name;
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	name = git_remote_name(remote);
+ 
+@@ -385,7 +394,7 @@ static VALUE rb_git_remote_name(VALUE self)
+ static VALUE rb_git_remote_url(VALUE self)
+ {
+ 	git_remote *remote;
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	return rb_str_new_utf8(git_remote_url(remote));
+ }
+@@ -404,7 +413,7 @@ static VALUE rb_git_remote_push_url(VALUE self)
+ 	git_remote *remote;
+ 	const char * push_url;
+ 
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	push_url = git_remote_pushurl(remote);
+ 	return push_url ? rb_str_new_utf8(push_url) : Qnil;
+@@ -429,7 +438,7 @@ static VALUE rb_git_remote_set_push_url(VALUE self, VALUE rb_url)
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+ 
+ 	Check_Type(rb_url, T_STRING);
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	rugged_exception_check(
+ 		git_remote_set_pushurl(repo, git_remote_name(remote), StringValueCStr(rb_url))
+@@ -445,7 +454,7 @@ static VALUE rb_git_remote_refspecs(VALUE self, git_direction direction)
+ 	git_strarray refspecs;
+ 	VALUE rb_refspec_array;
+ 
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	if (direction == GIT_DIRECTION_FETCH)
+ 		error = git_remote_get_fetch_refspecs(&refspecs, remote);
+@@ -524,7 +533,7 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
+ 	ID id_direction;
+ 	int error, direction;
+ 
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 	rb_scan_args(argc, argv, "01:", &rb_direction, &rb_options);
+ 
+ 	Check_Type(rb_direction, T_SYMBOL);
+@@ -627,7 +636,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
+ 
+ 	rugged_rb_ary_to_strarray(rb_refspecs, &refspecs);
+ 
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
+ 	rugged_remote_init_custom_headers(rb_options, &opts.custom_headers);
+@@ -722,7 +731,7 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
+ 
+ 	rugged_rb_ary_to_strarray(rb_refspecs, &refspecs);
+ 
+-	Data_Get_Struct(self, git_remote, remote);
++	TypedData_Get_Struct(self, git_remote, &rugged_remote_type, remote);
+ 
+ 	rugged_remote_init_callbacks_and_payload_from_options(rb_options, &opts.callbacks, &payload);
+ 	rugged_remote_init_custom_headers(rb_options, &opts.custom_headers);
+
+From ae4cc79de0f0ea714646f8b11631cd48911d8266 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:09:51 +0100
+Subject: [PATCH 08/14] submodule: use `TypedData` for `Submodule`
+
+---
+ ext/rugged/rugged_submodule.c            | 35 ++++++++++++------------
+ ext/rugged/rugged_submodule_collection.c | 17 +++++++++---
+ 2 files changed, 31 insertions(+), 21 deletions(-)
+
+diff --git a/ext/rugged/rugged_submodule.c b/ext/rugged/rugged_submodule.c
+index 3eb44ec22..c47231cd2 100644
+--- a/ext/rugged/rugged_submodule.c
++++ b/ext/rugged/rugged_submodule.c
+@@ -19,6 +19,7 @@ static ID id_ignore_none, id_ignore_untracked, id_ignore_dirty, id_ignore_all;
+ static ID id_update_checkout, id_update_rebase, id_update_merge, id_update_none;
+ 
+ extern const rb_data_type_t rugged_repository_type;
++extern const rb_data_type_t rugged_submodule_type;
+ 
+ void init_status_list(void)
+ {
+@@ -156,7 +157,7 @@ static VALUE rb_git_submodule_status(VALUE self)
+ 
+ 	rugged_check_repo(rb_repo);
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo);
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rugged_exception_check(
+ 		git_submodule_status(&flags, repo, git_submodule_name(submodule),
+@@ -170,7 +171,7 @@ static VALUE rb_git_submodule_status(VALUE self)
+ #define RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(flag) \
+ 	git_submodule *submodule; \
+ 	unsigned int flags; \
+-	Data_Get_Struct(self, git_submodule, submodule); \
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule); \
+ 	rugged_exception_check( \
+ 		git_submodule_location(&flags, submodule) \
+ 	); \
+@@ -227,7 +228,7 @@ static VALUE rb_git_submodule_status_in_workdir(VALUE self)
+ 	unsigned int flags; \
+ 	rugged_check_repo(rb_repo); \
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo); \
+-	Data_Get_Struct(self, git_submodule, submodule); \
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule); \
+ 	rugged_exception_check( \
+ 		git_submodule_status(&flags, repo, git_submodule_name(submodule), \
+ 			GIT_SUBMODULE_IGNORE_UNSPECIFIED) \
+@@ -351,7 +352,7 @@ static VALUE rb_git_submodule_status_untracked_files_in_workdir(VALUE self)
+ 	unsigned int flags; \
+ 	rugged_check_repo(rb_repo); \
+ 	TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, repo); \
+-	Data_Get_Struct(self, git_submodule, submodule); \
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule); \
+ 	rugged_exception_check( \
+ 		git_submodule_status(&flags, repo, git_submodule_name(submodule), \
+ 			GIT_SUBMODULE_IGNORE_UNSPECIFIED) \
+@@ -403,7 +404,7 @@ static VALUE rb_git_submodule_add_to_index(int argc, VALUE *argv, VALUE self)
+ 	VALUE rb_options;
+ 	int write_index = 1;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rb_scan_args(argc, argv, ":", &rb_options);
+ 
+@@ -433,7 +434,7 @@ static VALUE rb_git_submodule_add_to_index(int argc, VALUE *argv, VALUE self)
+ static VALUE rb_git_submodule_reload(VALUE self)
+ {
+ 	git_submodule *submodule;
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rugged_exception_check(
+ 		git_submodule_reload(submodule, 1)
+@@ -456,7 +457,7 @@ static VALUE rb_git_submodule_reload(VALUE self)
+ static VALUE rb_git_submodule_sync(VALUE self)
+ {
+ 	git_submodule *submodule;
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rugged_exception_check(
+ 		git_submodule_sync(submodule)
+@@ -487,7 +488,7 @@ static VALUE rb_git_submodule_init(int argc, VALUE *argv, VALUE self)
+ 	VALUE rb_options;
+ 	int overwrite = 0;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rb_scan_args(argc, argv, ":", &rb_options);
+ 
+@@ -516,7 +517,7 @@ static VALUE rb_git_submodule_name(VALUE self)
+ 	git_submodule *submodule;
+ 	const char *name;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	name = git_submodule_name(submodule);
+ 
+@@ -535,7 +536,7 @@ static VALUE rb_git_submodule_url(VALUE self)
+ 	git_submodule *submodule;
+ 	const char *url;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	url = git_submodule_url(submodule);
+ 
+@@ -556,7 +557,7 @@ static VALUE rb_git_submodule_path(VALUE self)
+ 	git_submodule *submodule;
+ 	const char *path;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	path = git_submodule_path(submodule);
+ 
+@@ -566,7 +567,7 @@ static VALUE rb_git_submodule_path(VALUE self)
+ #define RB_GIT_OID_GETTER(_klass, _attribute) \
+ 	git_##_klass *object; \
+ 	const git_oid * oid; \
+-	Data_Get_Struct(self, git_##_klass, object); \
++	TypedData_Get_Struct(self, git_##_klass, &rugged_##_klass##_type, object);	\
+ 	oid = git_##_klass##_##_attribute(object); \
+ 	return oid ? rugged_create_oid(oid) : Qnil; \
+ 
+@@ -627,7 +628,7 @@ static VALUE rb_git_submodule_wd_id(VALUE self)
+ static VALUE rb_git_submodule_fetch_recurse_submodules(VALUE self)
+ {
+ 	git_submodule *submodule;
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	return git_submodule_fetch_recurse_submodules(submodule) ? Qtrue : Qfalse;
+ }
+@@ -678,7 +679,7 @@ static VALUE rb_git_submodule_ignore_rule(VALUE self)
+ 	git_submodule *submodule;
+ 	git_submodule_ignore_t ignore;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 	ignore = git_submodule_ignore(submodule);
+ 
+ 	return rb_git_subm_ignore_rule_fromC(ignore);
+@@ -725,7 +726,7 @@ static VALUE rb_git_submodule_update_rule(VALUE self)
+ 	git_submodule *submodule;
+ 	git_submodule_update_t update;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 	update = git_submodule_update_strategy(submodule);
+ 
+ 	return rb_git_subm_update_rule_fromC(update);
+@@ -746,7 +747,7 @@ static VALUE rb_git_submodule_repository(VALUE self)
+ 	git_submodule *submodule;
+ 	git_repository *repo;
+ 
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rugged_exception_check(
+ 		git_submodule_open(&repo, submodule)
+@@ -771,7 +772,7 @@ static VALUE rb_git_submodule_repository(VALUE self)
+ static VALUE rb_git_submodule_finalize_add(VALUE self)
+ {
+ 	git_submodule *submodule;
+-	Data_Get_Struct(self, git_submodule, submodule);
++	TypedData_Get_Struct(self, git_submodule, &rugged_submodule_type, submodule);
+ 
+ 	rugged_exception_check(
+ 		git_submodule_add_finalize(submodule)
+diff --git a/ext/rugged/rugged_submodule_collection.c b/ext/rugged/rugged_submodule_collection.c
+index 6e6e24d89..7e2384742 100644
+--- a/ext/rugged/rugged_submodule_collection.c
++++ b/ext/rugged/rugged_submodule_collection.c
+@@ -26,19 +26,28 @@ static VALUE rb_git_submodule_collection_initialize(VALUE self, VALUE rb_repo)
+ 	return self;
+ }
+ 
+-static void rb_git_submodule__free(git_submodule *submodule)
++static void rb_git_submodule__free(void *data)
+ {
++	git_submodule *submodule = (git_submodule *) data;
+ 	git_submodule_free(submodule);
+ }
+ 
++const rb_data_type_t rugged_submodule_type = {
++	.wrap_struct_name = "Rugged::Submodule",
++	.function = {
++		.dfree = rb_git_submodule__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
++
+ VALUE rugged_submodule_new(VALUE owner, git_submodule *submodule)
+ {
+ 	VALUE rb_submodule;
+ 
+-	rb_submodule = Data_Wrap_Struct(
++	rb_submodule = TypedData_Wrap_Struct(
+ 			rb_cRuggedSubmodule,
+-			NULL,
+-			&rb_git_submodule__free,
++			&rugged_submodule_type,
+ 			submodule);
+ 	rugged_set_owner(rb_submodule, owner);
+ 
+
+From dcf36adf3d841a6b5aa02f87b465e5c1a8a75fe5 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:14:55 +0100
+Subject: [PATCH 09/14] diff: use `TypedData` for `Diff`
+
+---
+ ext/rugged/rugged_diff.c | 38 ++++++++++++++++++++++++++------------
+ ext/rugged/rugged_repo.c |  3 ++-
+ 2 files changed, 28 insertions(+), 13 deletions(-)
+
+diff --git a/ext/rugged/rugged_diff.c b/ext/rugged/rugged_diff.c
+index c5eb91abd..900f86fce 100644
+--- a/ext/rugged/rugged_diff.c
++++ b/ext/rugged/rugged_diff.c
+@@ -10,9 +10,23 @@
+ extern VALUE rb_mRugged;
+ VALUE rb_cRuggedDiff;
+ 
++static void rb_git_diff__free(void *data)
++{
++	git_diff *diff = (git_diff *) data;
++	git_diff_free(diff);
++}
++
++const rb_data_type_t rugged_diff_type = {
++	.wrap_struct_name = "Rugged::Diff",
++	.function = {
++		.dfree = rb_git_diff__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_diff_new(VALUE klass, VALUE owner, git_diff *diff)
+ {
+-	VALUE rb_diff = Data_Wrap_Struct(klass, NULL, git_diff_free, diff);
++	VALUE rb_diff = TypedData_Wrap_Struct(klass, &rugged_diff_type, diff);
+ 	rugged_set_owner(rb_diff, owner);
+ 	return rb_diff;
+ }
+@@ -212,7 +226,7 @@ static VALUE rb_git_diff_patch(int argc, VALUE *argv, VALUE self)
+ 
+ 	rb_scan_args(argc, argv, "00:", &rb_opts);
+ 
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	if (!NIL_P(rb_opts)) {
+ 		if (rb_hash_aref(rb_opts, CSTR2SYM("compact")) == Qtrue)
+@@ -256,7 +270,7 @@ static VALUE rb_git_diff_write_patch(int argc, VALUE *argv, VALUE self)
+ 	if (!rb_respond_to(rb_io, rb_intern("write")))
+ 		rb_raise(rb_eArgError, "Expected io to respond to \"write\"");
+ 
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	if (!NIL_P(rb_opts)) {
+ 		if (rb_hash_aref(rb_opts, CSTR2SYM("compact")) == Qtrue)
+@@ -285,8 +299,8 @@ static VALUE rb_git_diff_merge(VALUE self, VALUE rb_other)
+ 	if (!rb_obj_is_kind_of(rb_other, rb_cRuggedDiff))
+ 		rb_raise(rb_eTypeError, "A Rugged::Diff instance is required");
+ 
+-	Data_Get_Struct(self, git_diff, diff);
+-	Data_Get_Struct(rb_other, git_diff, other);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
++	TypedData_Get_Struct(rb_other, git_diff, &rugged_diff_type, other);
+ 
+ 	error = git_diff_merge(diff, other);
+ 	rugged_exception_check(error);
+@@ -358,7 +372,7 @@ static VALUE rb_git_diff_find_similar(int argc, VALUE *argv, VALUE self)
+ 	VALUE rb_options;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	rb_scan_args(argc, argv, "00:", &rb_options);
+ 
+@@ -448,7 +462,7 @@ static VALUE rb_git_diff_each_patch(VALUE self)
+ 	size_t d, delta_count;
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	delta_count = git_diff_num_deltas(diff);
+ 	for (d = 0; d < delta_count; ++d) {
+@@ -481,7 +495,7 @@ static VALUE rb_git_diff_each_delta(VALUE self)
+ 	size_t d, delta_count;
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	delta_count = git_diff_num_deltas(diff);
+ 	for (d = 0; d < delta_count; ++d) {
+@@ -516,7 +530,7 @@ static VALUE rb_git_diff_each_line(int argc, VALUE *argv, VALUE self)
+ 	int exception = 0, error;
+ 
+ 	RETURN_ENUMERATOR(self, argc, argv);
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	if (rb_scan_args(argc, argv, "01", &rb_format) == 1) {
+ 		Check_Type(rb_format, T_SYMBOL);
+@@ -557,7 +571,7 @@ static VALUE rb_git_diff_size(VALUE self)
+ {
+ 	git_diff *diff;
+ 
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	return INT2FIX(git_diff_num_deltas(diff));
+ }
+@@ -616,7 +630,7 @@ static VALUE rb_git_diff_stat(VALUE self)
+ 	git_diff *diff;
+ 	struct diff_stats stats = { 0, 0, 0 };
+ 
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 
+ 	git_diff_foreach(
+ 		diff, diff_file_stats_cb, NULL, NULL, diff_line_stats_cb, &stats);
+@@ -633,7 +647,7 @@ static VALUE rb_git_diff_stat(VALUE self)
+ static VALUE rb_git_diff_sorted_icase_p(VALUE self)
+ {
+ 	git_diff *diff;
+-	Data_Get_Struct(self, git_diff, diff);
++	TypedData_Get_Struct(self, git_diff, &rugged_diff_type, diff);
+ 	return git_diff_is_sorted_icase(diff) ? Qtrue : Qfalse;
+ }
+ 
+diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c
+index 2055bb2cb..cbd30be00 100644
+--- a/ext/rugged/rugged_repo.c
++++ b/ext/rugged/rugged_repo.c
+@@ -34,6 +34,7 @@ VALUE rb_cRuggedOdbObject;
+ 
+ static ID id_call;
+ 
++extern const rb_data_type_t rugged_diff_type;
+ extern const rb_data_type_t rugged_index_type;
+ const rb_data_type_t rugged_repository_type;
+ extern const rb_data_type_t rugged_object_type;
+@@ -1053,7 +1054,7 @@ static VALUE rb_git_repo_apply(int argc, VALUE *argv, VALUE self)
+ 		rugged_parse_apply_options(&opts, &location, rb_options, &payload);
+ 	}
+ 
+-	Data_Get_Struct(rb_diff, git_diff, diff);
++	TypedData_Get_Struct(rb_diff, git_diff, &rugged_diff_type, diff);
+ 
+ 	error = git_apply(repo, diff, location, &opts);
+ 
+
+From b392bb6d7eb84affcb06696cdabe36558569b99b Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:18:32 +0100
+Subject: [PATCH 10/14] patch: use `TypedData` for `Patch`
+
+---
+ ext/rugged/rugged_diff_hunk.c |  3 ++-
+ ext/rugged/rugged_patch.c     | 32 +++++++++++++++++++++++---------
+ 2 files changed, 25 insertions(+), 10 deletions(-)
+
+diff --git a/ext/rugged/rugged_diff_hunk.c b/ext/rugged/rugged_diff_hunk.c
+index 37878e05d..00fe886de 100644
+--- a/ext/rugged/rugged_diff_hunk.c
++++ b/ext/rugged/rugged_diff_hunk.c
+@@ -10,6 +10,7 @@
+ extern VALUE rb_cRuggedDiff;
+ VALUE rb_cRuggedDiffHunk;
+ 
++extern const rb_data_type_t rugged_patch_type;
+ 
+ VALUE rugged_diff_hunk_new(VALUE owner, size_t hunk_idx, const git_diff_hunk *hunk, size_t lines_in_hunk)
+ {
+@@ -44,7 +45,7 @@ static VALUE rb_git_diff_hunk_each_line(VALUE self)
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+ 
+-	Data_Get_Struct(rugged_owner(self), git_patch, patch);
++	TypedData_Get_Struct(rugged_owner(self), git_patch, &rugged_patch_type, patch);
+ 
+ 	lines_count = FIX2INT(rb_iv_get(self, "@line_count"));
+ 	hunk_idx = FIX2INT(rb_iv_get(self, "@hunk_index"));
+diff --git a/ext/rugged/rugged_patch.c b/ext/rugged/rugged_patch.c
+index 7a9a87512..f04a01115 100644
+--- a/ext/rugged/rugged_patch.c
++++ b/ext/rugged/rugged_patch.c
+@@ -69,9 +69,23 @@ VALUE rb_git_patch_from_strings(int argc, VALUE *argv, VALUE self)
+ 	return rugged_patch_new(self, patch);
+ }
+ 
++static void rb_git_patch__free(void *data)
++{
++	git_patch *patch = (git_patch *) data;
++	git_patch_free(patch);
++}
++
++const rb_data_type_t rugged_patch_type = {
++	.wrap_struct_name = "Rugged::Patch",
++	.function = {
++		.dfree = rb_git_patch__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ VALUE rugged_patch_new(VALUE owner, git_patch *patch)
+ {
+-	VALUE rb_patch = Data_Wrap_Struct(rb_cRuggedPatch, NULL, &git_patch_free, patch);
++	VALUE rb_patch = TypedData_Wrap_Struct(rb_cRuggedPatch, &rugged_patch_type, patch);
+ 	rugged_set_owner(rb_patch, owner);
+ 	return rb_patch;
+ }
+@@ -94,7 +108,7 @@ static VALUE rb_git_diff_patch_each_hunk(VALUE self)
+ 	size_t hunks_count, h;
+ 
+ 	RETURN_ENUMERATOR(self, 0, 0);
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	hunks_count = git_patch_num_hunks(patch);
+ 	for (h = 0; h < hunks_count; ++h) {
+@@ -117,7 +131,7 @@ static VALUE rb_git_diff_patch_each_hunk(VALUE self)
+ static VALUE rb_git_diff_patch_hunk_count(VALUE self)
+ {
+ 	git_patch *patch;
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	return INT2FIX(git_patch_num_hunks(patch));
+ }
+@@ -131,7 +145,7 @@ static VALUE rb_git_diff_patch_hunk_count(VALUE self)
+ static VALUE rb_git_diff_patch_delta(VALUE self)
+ {
+ 	git_patch *patch;
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	return rugged_diff_delta_new(rugged_owner(self), git_patch_get_delta(patch));
+ }
+@@ -146,7 +160,7 @@ static VALUE rb_git_diff_patch_stat(VALUE self)
+ {
+ 	git_patch *patch;
+ 	size_t additions, deletions;
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	git_patch_line_stats(NULL, &additions, &deletions, patch);
+ 
+@@ -191,7 +205,7 @@ static VALUE rb_git_diff_patch_lines(int argc, VALUE *argv, VALUE self)
+ 	size_t lines = 0;
+ 	int options = 0;
+ 	VALUE rb_options;
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	rb_scan_args(argc, argv, "0:", &rb_options);
+ 	if (!NIL_P(rb_options)) {
+@@ -282,7 +296,7 @@ static VALUE rb_git_diff_patch_bytesize(int argc, VALUE *argv, VALUE self)
+ 	size_t bytesize;
+ 	VALUE rb_options;
+ 	int include_context, include_hunk_headers, include_file_headers;
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	include_context = include_hunk_headers = include_file_headers = 1;
+ 
+@@ -352,7 +366,7 @@ static VALUE rb_git_diff_patch_to_s(VALUE self)
+ {
+ 	git_patch *patch;
+ 	VALUE rb_buffer = rb_ary_new();
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	rugged_exception_check(git_patch_print(patch, patch_print_cb, (void*)rb_buffer));
+ 
+@@ -370,7 +384,7 @@ static VALUE rb_git_diff_patch_header(VALUE self)
+ 	git_patch *patch;
+ 	int error = 0;
+ 	VALUE rb_buffer = rb_ary_new();
+-	Data_Get_Struct(self, git_patch, patch);
++	TypedData_Get_Struct(self, git_patch, &rugged_patch_type, patch);
+ 
+ 	error = git_patch_print(patch, patch_print_header_cb, (void*)rb_buffer);
+ 	if (error && error != GIT_ITEROVER)
+
+From db878af0b893afedaf70c84027d16c57c00ebec4 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:22:40 +0100
+Subject: [PATCH 11/14] rebase: use `TypedData` for `Rebase`
+
+---
+ ext/rugged/rugged_rebase.c | 24 +++++++++++++++++-------
+ 1 file changed, 17 insertions(+), 7 deletions(-)
+
+diff --git a/ext/rugged/rugged_rebase.c b/ext/rugged/rugged_rebase.c
+index 47df5b2ec..3ca5c97cf 100644
+--- a/ext/rugged/rugged_rebase.c
++++ b/ext/rugged/rugged_rebase.c
+@@ -44,14 +44,24 @@ static void parse_rebase_options(git_rebase_options *ret, VALUE rb_options)
+ 	rugged_parse_merge_options(&ret->merge_options, rb_options);
+ }
+ 
+-void rb_git_rebase__free(git_rebase *rebase)
++static void rb_git_rebase__free(void *data)
+ {
++	git_rebase *rebase = (git_rebase *) data;
+ 	git_rebase_free(rebase);
+ }
+ 
++const rb_data_type_t rugged_rebase_type = {
++	.wrap_struct_name = "Rugged::Rebase",
++	.function = {
++		.dfree = rb_git_rebase__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
++
+ VALUE rugged_rebase_new(VALUE klass, VALUE owner, git_rebase *rebase)
+ {
+-	VALUE rb_rebase = Data_Wrap_Struct(klass, NULL, &rb_git_rebase__free, rebase);
++	VALUE rb_rebase = TypedData_Wrap_Struct(klass, &rugged_rebase_type, rebase);
+ 	rugged_set_owner(rb_rebase, owner);
+ 	return rb_rebase;
+ }
+@@ -211,7 +221,7 @@ static VALUE rb_git_rebase_next(VALUE self)
+ 	git_rebase_operation *operation;
+ 	VALUE hash, val;
+ 
+-	Data_Get_Struct(self, git_rebase, rebase);
++	TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
+ 	error = git_rebase_next(&operation, rebase);
+ 	if (error == GIT_ITEROVER)
+ 		return Qnil;
+@@ -254,7 +264,7 @@ static VALUE rb_git_rebase_inmemory_index(VALUE self)
+ 	git_rebase *rebase;
+ 	git_index *index;
+ 
+-	Data_Get_Struct(self, git_rebase, rebase);
++	TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
+ 	rugged_exception_check(git_rebase_inmemory_index(&index, rebase));
+ 
+ 	return rugged_index_new(rb_cRuggedIndex, self, index);
+@@ -281,7 +291,7 @@ static VALUE rb_git_rebase_commit(int argc, VALUE *argv, VALUE self)
+ 	const char *message = NULL;
+ 	VALUE rb_options, rb_author, rb_committer, rb_message;
+ 
+-	Data_Get_Struct(self, git_rebase, rebase);
++	TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
+ 	rb_scan_args(argc, argv, ":", &rb_options);
+ 
+ 	Check_Type(rb_options, T_HASH);
+@@ -328,7 +338,7 @@ static VALUE rb_git_rebase_abort(VALUE self)
+ {
+ 	git_rebase *rebase;
+ 
+-	Data_Get_Struct(self, git_rebase, rebase);
++	TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
+ 	rugged_exception_check(git_rebase_abort(rebase));
+ 
+ 	return Qnil;
+@@ -347,7 +357,7 @@ static VALUE rb_git_rebase_finish(VALUE self, VALUE rb_sig)
+ 	git_signature *sig;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_rebase, rebase);
++	TypedData_Get_Struct(self, git_rebase, &rugged_rebase_type, rebase);
+ 	sig = rugged_signature_get(rb_sig, NULL);
+ 	error = git_rebase_finish(rebase, sig);
+ 	git_signature_free(sig);
+
+From 8a89068cc7097ebd2a79350e57cadeb73cedbdd7 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:27:52 +0100
+Subject: [PATCH 12/14] tree: use `TypedData` for `Tree::Builder`
+
+---
+ ext/rugged/rugged_tree.c | 26 ++++++++++++++++++--------
+ 1 file changed, 18 insertions(+), 8 deletions(-)
+
+diff --git a/ext/rugged/rugged_tree.c b/ext/rugged/rugged_tree.c
+index 5fdada954..f2faa3317 100644
+--- a/ext/rugged/rugged_tree.c
++++ b/ext/rugged/rugged_tree.c
+@@ -710,11 +710,21 @@ static VALUE rb_git_tree_update(VALUE self, VALUE rb_updates)
+ 	return rugged_create_oid(&id);
+ }
+ 
+-static void rb_git_treebuilder_free(git_treebuilder *bld)
++static void rb_git_treebuilder__free(void *data)
+ {
++	git_treebuilder *bld = (git_treebuilder *) data;
+ 	git_treebuilder_free(bld);
+ }
+ 
++const rb_data_type_t rugged_treebuilder_type = {
++	.wrap_struct_name = "Rugged::Tree::Builder",
++	.function = {
++		.dfree = rb_git_treebuilder__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
++
+ /*
+  *  call-seq:
+  *    Tree::Builder.new(repository, [tree])
+@@ -747,7 +757,7 @@ static VALUE rb_git_treebuilder_new(int argc, VALUE *argv, VALUE klass)
+ 	error = git_treebuilder_new(&builder, repo, tree);
+ 	rugged_exception_check(error);
+ 
+-	rb_builder = Data_Wrap_Struct(klass, NULL, &rb_git_treebuilder_free, builder);
++	rb_builder = TypedData_Wrap_Struct(klass, &rugged_treebuilder_type, builder);
+ 	rugged_set_owner(rb_builder, rb_repo);
+ 
+ 	return rb_builder;
+@@ -762,7 +772,7 @@ static VALUE rb_git_treebuilder_new(int argc, VALUE *argv, VALUE klass)
+ static VALUE rb_git_treebuilder_clear(VALUE self)
+ {
+ 	git_treebuilder *builder;
+-	Data_Get_Struct(self, git_treebuilder, builder);
++	TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
+ 	git_treebuilder_clear(builder);
+ 	return Qnil;
+ }
+@@ -776,7 +786,7 @@ static VALUE rb_git_treebuilder_clear(VALUE self)
+ static VALUE rb_git_treebuilder_get(VALUE self, VALUE path)
+ {
+ 	git_treebuilder *builder;
+-	Data_Get_Struct(self, git_treebuilder, builder);
++	TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
+ 
+ 	Check_Type(path, T_STRING);
+ 
+@@ -797,7 +807,7 @@ static VALUE rb_git_treebuilder_insert(VALUE self, VALUE rb_entry)
+ 	git_oid oid;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_treebuilder, builder);
++	TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
+ 	Check_Type(rb_entry, T_HASH);
+ 
+ 	rb_path = rb_hash_aref(rb_entry, CSTR2SYM("name"));
+@@ -834,7 +844,7 @@ static VALUE rb_git_treebuilder_remove(VALUE self, VALUE path)
+ 	git_treebuilder *builder;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_treebuilder, builder);
++	TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
+ 	Check_Type(path, T_STRING);
+ 
+ 	error = git_treebuilder_remove(builder, StringValueCStr(path));
+@@ -862,7 +872,7 @@ static VALUE rb_git_treebuilder_write(VALUE self)
+ 	git_oid written_id;
+ 	int error;
+ 
+-	Data_Get_Struct(self, git_treebuilder, builder);
++	TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
+ 
+ 	error = git_treebuilder_write(&written_id, builder);
+ 	rugged_exception_check(error);
+@@ -889,7 +899,7 @@ static VALUE rb_git_treebuilder_filter(VALUE self)
+ 	git_treebuilder *builder;
+ 
+ 	rb_need_block();
+-	Data_Get_Struct(self, git_treebuilder, builder);
++	TypedData_Get_Struct(self, git_treebuilder, &rugged_treebuilder_type, builder);
+ 
+ 	git_treebuilder_filter(builder, &treebuilder_cb, (void *)rb_block_proc());
+ 	return Qnil;
+
+From c1e550895c3de0844a9b366661d356f8f3bcc147 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:32:36 +0100
+Subject: [PATCH 13/14] blob: use `TypedData` for `Blob::HashSignature`
+
+---
+ ext/rugged/rugged_blob.c | 20 +++++++++++++++++---
+ 1 file changed, 17 insertions(+), 3 deletions(-)
+
+diff --git a/ext/rugged/rugged_blob.c b/ext/rugged/rugged_blob.c
+index 7a0d2dd02..c6f539457 100644
+--- a/ext/rugged/rugged_blob.c
++++ b/ext/rugged/rugged_blob.c
+@@ -639,6 +639,20 @@ static VALUE rb_git_blob_merge_files(int argc, VALUE *argv, VALUE klass)
+ 	return rb_result;
+ }
+ 
++static void rb_git_hashsig__free(void *data)
++{
++	git_hashsig *sig = (git_hashsig *) data;
++	git_hashsig_free(sig);
++}
++
++const rb_data_type_t rugged_hashsig_type = {
++	.wrap_struct_name = "Rugged::Blob::HashSignature",
++	.function = {
++		.dfree = rb_git_hashsig__free,
++	},
++	.flags = RUBY_TYPED_FREE_IMMEDIATELY,
++};
++
+ static VALUE rb_git_blob_sig_new(int argc, VALUE *argv, VALUE klass)
+ {
+ 	int error, opts = 0;
+@@ -665,7 +679,7 @@ static VALUE rb_git_blob_sig_new(int argc, VALUE *argv, VALUE klass)
+ 
+ 	rugged_exception_check(error);
+ 
+-	return Data_Wrap_Struct(klass, NULL, &git_hashsig_free, sig);
++	return TypedData_Wrap_Struct(klass, &rugged_hashsig_type, sig);
+ }
+ 
+ static VALUE rb_git_blob_sig_compare(VALUE self, VALUE rb_sig_a, VALUE rb_sig_b)
+@@ -679,8 +693,8 @@ static VALUE rb_git_blob_sig_compare(VALUE self, VALUE rb_sig_a, VALUE rb_sig_b)
+ 		rb_raise(rb_eTypeError, "Expected Rugged::Blob::HashSignature");
+ 	}
+ 
+-	Data_Get_Struct(rb_sig_a, git_hashsig, sig_a);
+-	Data_Get_Struct(rb_sig_b, git_hashsig, sig_b);
++	TypedData_Get_Struct(rb_sig_a, git_hashsig, &rugged_hashsig_type, sig_a);
++	TypedData_Get_Struct(rb_sig_b, git_hashsig, &rugged_hashsig_type, sig_b);
+ 
+ 	result = git_hashsig_compare(sig_a, sig_b);
+ 
+
+From 0dc35341b54e78310dfe2df280aef61f9490d264 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@dwim.me>
+Date: Sun, 22 Feb 2026 19:45:04 +0100
+Subject: [PATCH 14/14] repository: use `TypedData` when setting owners
+
+---
+ ext/rugged/rugged_repo.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/ext/rugged/rugged_repo.c b/ext/rugged/rugged_repo.c
+index cbd30be00..44bc8276f 100644
+--- a/ext/rugged/rugged_repo.c
++++ b/ext/rugged/rugged_repo.c
+@@ -34,6 +34,7 @@ VALUE rb_cRuggedOdbObject;
+ 
+ static ID id_call;
+ 
++extern const rb_data_type_t rugged_config_type;
+ extern const rb_data_type_t rugged_diff_type;
+ extern const rb_data_type_t rugged_index_type;
+ const rb_data_type_t rugged_repository_type;
+@@ -644,7 +645,7 @@ static VALUE rb_git_repo_clone_at(int argc, VALUE *argv, VALUE klass)
+ 		rb_raise(rb_eRuntimeError, \
+ 			"The given object is already owned by another repository"); \
+ 	TypedData_Get_Struct(self, git_repository, &rugged_repository_type, repo); \
+-	Data_Get_Struct(rb_data, git_##_object, data); \
++	TypedData_Get_Struct(rb_data, git_##_object, &rugged_##_object##_type, data);			\
+ 	git_repository_set_##_object(repo, data); \
+ 	rb_old_data = rb_iv_get(self, "@" #_object); \
+ 	if (!NIL_P(rb_old_data)) rugged_set_owner(rb_old_data, Qnil); \

diff --git a/rubygem-rugged.spec b/rubygem-rugged.spec
index 26efc13..1a8c0c0 100644
--- a/rubygem-rugged.spec
+++ b/rubygem-rugged.spec
@@ -3,13 +3,18 @@
 Summary:       Rugged is a Ruby binding to the libgit2 library
 Name:          rubygem-%{gem_name}
 Version:       1.9.0
-Release:       7%{?dist}
+Release:       8%{?dist}
 
 License:       MIT
 URL:           https://github.com/libgit2/rugged
 Source0:       https://rubygems.org/gems/%{gem_name}-%{version}.gem
 # https://github.com/libgit2/rugged/pull/985
 Patch:         985.patch
+# Use TypedData API, needed for ruby4.1
+# https://github.com/libgit2/rugged/pull/998
+Patch:         %{name}-pr998-TypedData-api.patch
+# https://github.com/libgit2/rugged/pull/1003/
+Patch:         %{name}-pr1003-TypedData-api.patch
 
 Requires:      ruby(rubygems)
 Requires:      ruby
@@ -75,6 +80,9 @@ rm -rf %{buildroot}%{gem_instdir}/ext/
 %doc %{gem_docdir}
 
 %changelog
+* Sun Oct 25 2026 Mamoru TASAKA <mtasaka@fedoraproject.org> - 1.9.0-8
+- Backport upstream patch to use TypedData API needed for ruby4.1
+
 * Fri Jul 17 2026 Fedora Release Engineering <releng@fedoraproject.org> - 1.9.0-7
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
 

                 reply	other threads:[~2026-10-25 10:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179292554495.1.11238685277189331023.rpms-rubygem-rugged-6e8105ee7341@fedoraproject.org \
    --to=mtasaka@fedoraproject.org \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox