Skip to content

Commit cc60001

Browse files
committed
Switch to array-based trailers API
Also bump libgit2 submodule to include-array based api
1 parent cb2b0f2 commit cc60001

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

ext/rugged/rugged_commit.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,6 @@ static VALUE rb_git_commit_message_GET(VALUE self)
4545
return rb_enc_str_new(message, strlen(message), encoding);
4646
}
4747

48-
struct trailer_cb_info {
49-
VALUE trailers;
50-
rb_encoding *encoding;
51-
};
52-
53-
static int rb_each_trailer(const char *key, const char *value, void *payload)
54-
{
55-
struct trailer_cb_info *cb_info = (struct trailer_cb_info *)payload;
56-
57-
VALUE pair = rb_ary_new();
58-
59-
// trailer key
60-
rb_ary_push(pair, rb_enc_str_new(key, strlen(key), cb_info->encoding));
61-
62-
// trailer value
63-
rb_ary_push(pair, rb_enc_str_new(value, strlen(value), cb_info->encoding));
64-
65-
// add it to the list
66-
rb_ary_push(cb_info->trailers, pair);
67-
68-
return GIT_OK;
69-
}
70-
7148
/*
7249
* call-seq:
7350
* commit.trailers -> [["Trailer-name", "trailer value"], ...]
@@ -86,6 +63,7 @@ static VALUE rb_git_commit_trailers_GET(VALUE self)
8663
const char *message;
8764
rb_encoding *encoding = rb_utf8_encoding();
8865
const char *encoding_name;
66+
git_message_trailer_array arr;
8967
VALUE trailers = rb_ary_new();
9068
int error;
9169

@@ -95,16 +73,28 @@ static VALUE rb_git_commit_trailers_GET(VALUE self)
9573
if (encoding_name != NULL)
9674
encoding = rb_enc_find(encoding_name);
9775

98-
struct trailer_cb_info cb_info = {
99-
.trailers = trailers,
100-
.encoding = encoding,
101-
};
102-
10376
message = git_commit_message(commit);
10477

105-
error = git_message_trailers(message, rb_each_trailer, &cb_info);
78+
error = git_message_trailers(&arr, message);
10679
rugged_exception_check(error);
10780

81+
for(size_t i=0; i<arr.count; i++) {
82+
VALUE pair = rb_ary_new();
83+
const char *key = arr.trailers[i].key;
84+
const char *value = arr.trailers[i].value;
85+
86+
// trailer key
87+
rb_ary_push(pair, rb_enc_str_new(key, strlen(key), encoding));
88+
89+
// trailer value
90+
rb_ary_push(pair, rb_enc_str_new(value, strlen(value), encoding));
91+
92+
// add it to the list
93+
rb_ary_push(trailers, pair);
94+
}
95+
96+
git_message_trailer_array_free(&arr);
97+
10898
return trailers;
10999
}
110100

vendor/libgit2

Submodule libgit2 updated 65 files

0 commit comments

Comments
 (0)