Skip to content

Commit 3a50a48

Browse files
Add Pack and OnePack ODB backend wrapping.
1 parent 86f0f31 commit 3a50a48

File tree

5 files changed

+121
-1
lines changed

5 files changed

+121
-1
lines changed

ext/rugged/rugged.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ void Init_rugged(void)
490490
Init_rugged_odb();
491491
Init_rugged_odb_backend();
492492
Init_rugged_odb_backend_loose();
493+
Init_rugged_odb_backend_one_pack();
494+
Init_rugged_odb_backend_pack();
493495

494496
/*
495497
* Sort the repository contents in no particular ordering;

ext/rugged/rugged.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ void Init_rugged_refdb_backend_fs(void);
8484
void Init_rugged_odb(void);
8585
void Init_rugged_odb_backend(void);
8686
void Init_rugged_odb_backend_loose(void);
87+
void Init_rugged_odb_backend_one_pack(void);
88+
void Init_rugged_odb_backend_pack(void);
8789

8890
VALUE rb_git_object_init(git_otype type, int argc, VALUE *argv, VALUE self);
8991

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2015 GitHub, Inc
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "rugged.h"
26+
27+
extern VALUE rb_cRuggedOdbBackend;
28+
VALUE rb_cRuggedOdbBackendOnePack;
29+
30+
static void rb_git_odb_backend__free(git_odb_backend *backend)
31+
{
32+
if (backend) backend->free(backend);
33+
}
34+
35+
static VALUE rb_git_odb_backend_one_pack_new(VALUE self, VALUE rb_path)
36+
{
37+
git_odb_backend *backend;
38+
39+
rugged_exception_check(git_odb_backend_one_pack(&backend, StringValueCStr(rb_path)));
40+
41+
return Data_Wrap_Struct(self, NULL, rb_git_odb_backend__free, backend);
42+
}
43+
44+
void Init_rugged_odb_backend_one_pack(void)
45+
{
46+
rb_cRuggedOdbBackendOnePack = rb_define_class_under(rb_cRuggedOdbBackend, "OnePack", rb_cRuggedOdbBackend);
47+
48+
rb_define_singleton_method(rb_cRuggedOdbBackendOnePack, "new", rb_git_odb_backend_one_pack_new, 1);
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2015 GitHub, Inc
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "rugged.h"
26+
27+
extern VALUE rb_cRuggedOdbBackend;
28+
VALUE rb_cRuggedOdbBackendPack;
29+
30+
static void rb_git_odb_backend__free(git_odb_backend *backend)
31+
{
32+
if (backend) backend->free(backend);
33+
}
34+
35+
static VALUE rb_git_odb_backend_pack_new(VALUE self, VALUE rb_path)
36+
{
37+
git_odb_backend *backend;
38+
39+
rugged_exception_check(git_odb_backend_pack(&backend, StringValueCStr(rb_path)));
40+
41+
return Data_Wrap_Struct(self, NULL, rb_git_odb_backend__free, backend);
42+
}
43+
44+
void Init_rugged_odb_backend_pack(void)
45+
{
46+
rb_cRuggedOdbBackendPack = rb_define_class_under(rb_cRuggedOdbBackend, "Pack", rb_cRuggedOdbBackend);
47+
48+
rb_define_singleton_method(rb_cRuggedOdbBackendPack, "new", rb_git_odb_backend_pack_new, 1);
49+
}

test/odb_test.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,30 @@ def test_add_backend
1515
refdb.add_backend(Rugged::Odb::Backend::Loose.new(File.join(@repo.path, "objects"), -1, 0, 0, 0), 1)
1616
end
1717

18-
def test_each
18+
def test_each_loose
1919
refdb = Rugged::Odb.new()
2020
refdb.add_backend(Rugged::Odb::Backend::Loose.new(File.join(@repo.path, "objects"), -1, 0, 0, 0), 1)
2121

2222
ids = []
2323
refdb.each { |id| ids << id }
2424
assert_equal 31, ids.length
2525
end
26+
27+
def test_each_pack
28+
refdb = Rugged::Odb.new()
29+
refdb.add_backend(Rugged::Odb::Backend::Pack.new(File.join(@repo.path, "objects")), 1)
30+
31+
ids = []
32+
refdb.each { |id| ids << id }
33+
assert_equal 6, ids.length
34+
end
35+
36+
def test_each_one_pack
37+
refdb = Rugged::Odb.new()
38+
refdb.add_backend(Rugged::Odb::Backend::OnePack.new(File.join(@repo.path, "objects", "pack", "pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx")), 1)
39+
40+
ids = []
41+
refdb.each { |id| ids << id }
42+
assert_equal 6, ids.length
43+
end
2644
end

0 commit comments

Comments
 (0)