rdavila-rugged 0.24.0b13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +619 -0
- data/ext/rugged/extconf.rb +105 -0
- data/ext/rugged/rugged.c +527 -0
- data/ext/rugged/rugged.h +185 -0
- data/ext/rugged/rugged_backend.c +34 -0
- data/ext/rugged/rugged_blame.c +292 -0
- data/ext/rugged/rugged_blob.c +638 -0
- data/ext/rugged/rugged_branch.c +195 -0
- data/ext/rugged/rugged_branch_collection.c +408 -0
- data/ext/rugged/rugged_commit.c +691 -0
- data/ext/rugged/rugged_config.c +404 -0
- data/ext/rugged/rugged_cred.c +148 -0
- data/ext/rugged/rugged_diff.c +686 -0
- data/ext/rugged/rugged_diff_delta.c +105 -0
- data/ext/rugged/rugged_diff_hunk.c +103 -0
- data/ext/rugged/rugged_diff_line.c +83 -0
- data/ext/rugged/rugged_index.c +1255 -0
- data/ext/rugged/rugged_note.c +376 -0
- data/ext/rugged/rugged_object.c +383 -0
- data/ext/rugged/rugged_patch.c +245 -0
- data/ext/rugged/rugged_reference.c +396 -0
- data/ext/rugged/rugged_reference_collection.c +446 -0
- data/ext/rugged/rugged_remote.c +691 -0
- data/ext/rugged/rugged_remote_collection.c +457 -0
- data/ext/rugged/rugged_repo.c +2669 -0
- data/ext/rugged/rugged_revwalk.c +495 -0
- data/ext/rugged/rugged_settings.c +155 -0
- data/ext/rugged/rugged_signature.c +106 -0
- data/ext/rugged/rugged_submodule.c +852 -0
- data/ext/rugged/rugged_submodule_collection.c +384 -0
- data/ext/rugged/rugged_tag.c +251 -0
- data/ext/rugged/rugged_tag_collection.c +347 -0
- data/ext/rugged/rugged_tree.c +919 -0
- data/lib/rugged.rb +23 -0
- data/lib/rugged/attributes.rb +41 -0
- data/lib/rugged/blob.rb +28 -0
- data/lib/rugged/branch.rb +19 -0
- data/lib/rugged/commit.rb +54 -0
- data/lib/rugged/console.rb +9 -0
- data/lib/rugged/credentials.rb +43 -0
- data/lib/rugged/diff.rb +20 -0
- data/lib/rugged/diff/delta.rb +53 -0
- data/lib/rugged/diff/hunk.rb +18 -0
- data/lib/rugged/diff/line.rb +47 -0
- data/lib/rugged/index.rb +13 -0
- data/lib/rugged/object.rb +7 -0
- data/lib/rugged/patch.rb +36 -0
- data/lib/rugged/reference.rb +7 -0
- data/lib/rugged/remote.rb +4 -0
- data/lib/rugged/repository.rb +227 -0
- data/lib/rugged/submodule_collection.rb +48 -0
- data/lib/rugged/tag.rb +50 -0
- data/lib/rugged/tree.rb +38 -0
- data/lib/rugged/version.rb +3 -0
- data/lib/rugged/walker.rb +5 -0
- metadata +146 -0
@@ -0,0 +1,245 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright (c) 2014 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_mRugged;
|
28
|
+
extern VALUE rb_cRuggedDiffDelta;
|
29
|
+
VALUE rb_cRuggedPatch;
|
30
|
+
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* Patch.from_strings(old_content = nil, new_content = nil, options = {}) -> patch
|
34
|
+
*
|
35
|
+
* Directly generate a Rugged::Patch from the difference between the content of
|
36
|
+
* the two strings `old_content` and `new_content`.
|
37
|
+
*
|
38
|
+
* The following options can be passed in the +options+ Hash:
|
39
|
+
*
|
40
|
+
* :old_path ::
|
41
|
+
* An optional string to treat +blob+ as if it had this filename.
|
42
|
+
*
|
43
|
+
* :new_path ::
|
44
|
+
* An optional string to treat +other+ as if it had this filename.
|
45
|
+
*
|
46
|
+
* Additionally, `options` can also contain all other valid diff options
|
47
|
+
* (see Rugged::Tree#diff for a complete list).
|
48
|
+
*/
|
49
|
+
VALUE rb_git_patch_from_strings(int argc, VALUE *argv, VALUE self)
|
50
|
+
{
|
51
|
+
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
52
|
+
git_patch *patch;
|
53
|
+
char * old_path = NULL, * new_path = NULL;
|
54
|
+
VALUE rb_old_buffer, rb_new_buffer, rb_options;
|
55
|
+
|
56
|
+
rb_scan_args(argc, argv, "02:", &rb_old_buffer, &rb_new_buffer, &rb_options);
|
57
|
+
|
58
|
+
if (!NIL_P(rb_options)) {
|
59
|
+
VALUE rb_value;
|
60
|
+
|
61
|
+
rb_value = rb_hash_aref(rb_options, CSTR2SYM("old_path"));
|
62
|
+
if (!NIL_P(rb_value)) {
|
63
|
+
Check_Type(rb_value, T_STRING);
|
64
|
+
old_path = StringValueCStr(rb_value);
|
65
|
+
}
|
66
|
+
|
67
|
+
rb_value = rb_hash_aref(rb_options, CSTR2SYM("new_path"));
|
68
|
+
if (!NIL_P(rb_value)) {
|
69
|
+
Check_Type(rb_value, T_STRING);
|
70
|
+
new_path = StringValueCStr(rb_value);
|
71
|
+
}
|
72
|
+
|
73
|
+
rugged_parse_diff_options(&opts, rb_options);
|
74
|
+
}
|
75
|
+
|
76
|
+
rugged_exception_check(git_patch_from_buffers(&patch,
|
77
|
+
NIL_P(rb_old_buffer) ? NULL : StringValuePtr(rb_old_buffer),
|
78
|
+
NIL_P(rb_old_buffer) ? 0 : RSTRING_LEN(rb_old_buffer),
|
79
|
+
old_path,
|
80
|
+
NIL_P(rb_new_buffer) ? NULL : StringValuePtr(rb_new_buffer),
|
81
|
+
NIL_P(rb_new_buffer) ? 0 : RSTRING_LEN(rb_new_buffer),
|
82
|
+
new_path,
|
83
|
+
&opts
|
84
|
+
));
|
85
|
+
|
86
|
+
return rugged_patch_new(self, patch);
|
87
|
+
}
|
88
|
+
|
89
|
+
VALUE rugged_patch_new(VALUE owner, git_patch *patch)
|
90
|
+
{
|
91
|
+
VALUE rb_patch = Data_Wrap_Struct(rb_cRuggedPatch, NULL, &git_patch_free, patch);
|
92
|
+
rugged_set_owner(rb_patch, owner);
|
93
|
+
return rb_patch;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* call-seq:
|
98
|
+
* patch.each_hunk { |hunk| } -> self
|
99
|
+
* patch.each_hunk -> enumerator
|
100
|
+
*
|
101
|
+
* If given a block, yields each hunk that is part of the patch.
|
102
|
+
*
|
103
|
+
* If no block is given, an enumerator is returned instead.
|
104
|
+
*/
|
105
|
+
static VALUE rb_git_diff_patch_each_hunk(VALUE self)
|
106
|
+
{
|
107
|
+
git_patch *patch;
|
108
|
+
const git_diff_hunk *hunk;
|
109
|
+
size_t lines_in_hunk;
|
110
|
+
int error = 0;
|
111
|
+
size_t hunks_count, h;
|
112
|
+
|
113
|
+
if (!rb_block_given_p()) {
|
114
|
+
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_hunk"), self);
|
115
|
+
}
|
116
|
+
|
117
|
+
Data_Get_Struct(self, git_patch, patch);
|
118
|
+
|
119
|
+
hunks_count = git_patch_num_hunks(patch);
|
120
|
+
for (h = 0; h < hunks_count; ++h) {
|
121
|
+
error = git_patch_get_hunk(&hunk, &lines_in_hunk, patch, h);
|
122
|
+
if (error) break;
|
123
|
+
|
124
|
+
rb_yield(rugged_diff_hunk_new(self, h, hunk, lines_in_hunk));
|
125
|
+
}
|
126
|
+
rugged_exception_check(error);
|
127
|
+
|
128
|
+
return self;
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
* call-seq:
|
133
|
+
* patch.hunk_count -> int
|
134
|
+
*
|
135
|
+
* Returns the number of hunks in the patch.
|
136
|
+
*/
|
137
|
+
static VALUE rb_git_diff_patch_hunk_count(VALUE self)
|
138
|
+
{
|
139
|
+
git_patch *patch;
|
140
|
+
Data_Get_Struct(self, git_patch, patch);
|
141
|
+
|
142
|
+
return INT2FIX(git_patch_num_hunks(patch));
|
143
|
+
}
|
144
|
+
|
145
|
+
/*
|
146
|
+
* call-seq:
|
147
|
+
* patch.delta -> delta
|
148
|
+
*
|
149
|
+
* Returns the delta object associated with the patch.
|
150
|
+
*/
|
151
|
+
static VALUE rb_git_diff_patch_delta(VALUE self)
|
152
|
+
{
|
153
|
+
git_patch *patch;
|
154
|
+
Data_Get_Struct(self, git_patch, patch);
|
155
|
+
|
156
|
+
return rugged_diff_delta_new(rugged_owner(self), git_patch_get_delta(patch));
|
157
|
+
}
|
158
|
+
|
159
|
+
/*
|
160
|
+
* call-seq:
|
161
|
+
* patch.stat -> int, int
|
162
|
+
*
|
163
|
+
* Returns the number of additions and deletions in the patch.
|
164
|
+
*/
|
165
|
+
static VALUE rb_git_diff_patch_stat(VALUE self)
|
166
|
+
{
|
167
|
+
git_patch *patch;
|
168
|
+
size_t additions, deletions;
|
169
|
+
Data_Get_Struct(self, git_patch, patch);
|
170
|
+
|
171
|
+
git_patch_line_stats(NULL, &additions, &deletions, patch);
|
172
|
+
|
173
|
+
return rb_ary_new3(2, INT2FIX(additions), INT2FIX(deletions));
|
174
|
+
}
|
175
|
+
|
176
|
+
/*
|
177
|
+
* call-seq:
|
178
|
+
* patch.lines -> int
|
179
|
+
*
|
180
|
+
* Returns the total number of lines in the patch.
|
181
|
+
*/
|
182
|
+
static VALUE rb_git_diff_patch_lines(VALUE self)
|
183
|
+
{
|
184
|
+
git_patch *patch;
|
185
|
+
size_t context, adds, dels;
|
186
|
+
Data_Get_Struct(self, git_patch, patch);
|
187
|
+
|
188
|
+
git_patch_line_stats(&context, &adds, &dels, patch);
|
189
|
+
|
190
|
+
return INT2FIX(context + adds + dels);
|
191
|
+
}
|
192
|
+
|
193
|
+
static int patch_print_cb(
|
194
|
+
const git_diff_delta *delta,
|
195
|
+
const git_diff_hunk *hunk,
|
196
|
+
const git_diff_line *line,
|
197
|
+
void *payload)
|
198
|
+
{
|
199
|
+
VALUE rb_str = (VALUE)payload;
|
200
|
+
|
201
|
+
switch (line->origin) {
|
202
|
+
case GIT_DIFF_LINE_CONTEXT:
|
203
|
+
case GIT_DIFF_LINE_ADDITION:
|
204
|
+
case GIT_DIFF_LINE_DELETION:
|
205
|
+
rb_str_cat(rb_str, &line->origin, 1);
|
206
|
+
}
|
207
|
+
|
208
|
+
rb_str_cat(rb_str, line->content, line->content_len);
|
209
|
+
|
210
|
+
return GIT_OK;
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* call-seq:
|
215
|
+
* patch.to_s -> str
|
216
|
+
*
|
217
|
+
* Returns the contents of the patch as a single diff string.
|
218
|
+
*/
|
219
|
+
static VALUE rb_git_diff_patch_to_s(VALUE self)
|
220
|
+
{
|
221
|
+
git_patch *patch;
|
222
|
+
VALUE rb_str = rb_str_new(NULL, 0);
|
223
|
+
Data_Get_Struct(self, git_patch, patch);
|
224
|
+
|
225
|
+
rugged_exception_check(git_patch_print(patch, patch_print_cb, (void*)rb_str));
|
226
|
+
|
227
|
+
return rb_str;
|
228
|
+
}
|
229
|
+
|
230
|
+
void Init_rugged_patch(void)
|
231
|
+
{
|
232
|
+
rb_cRuggedPatch = rb_define_class_under(rb_mRugged, "Patch", rb_cObject);
|
233
|
+
|
234
|
+
rb_define_singleton_method(rb_cRuggedPatch, "from_strings", rb_git_patch_from_strings, -1);
|
235
|
+
|
236
|
+
rb_define_method(rb_cRuggedPatch, "stat", rb_git_diff_patch_stat, 0);
|
237
|
+
rb_define_method(rb_cRuggedPatch, "lines", rb_git_diff_patch_lines, 0);
|
238
|
+
|
239
|
+
rb_define_method(rb_cRuggedPatch, "delta", rb_git_diff_patch_delta, 0);
|
240
|
+
|
241
|
+
rb_define_method(rb_cRuggedPatch, "to_s", rb_git_diff_patch_to_s, 0);
|
242
|
+
|
243
|
+
rb_define_method(rb_cRuggedPatch, "each_hunk", rb_git_diff_patch_each_hunk, 0);
|
244
|
+
rb_define_method(rb_cRuggedPatch, "hunk_count", rb_git_diff_patch_hunk_count, 0);
|
245
|
+
}
|
@@ -0,0 +1,396 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright (c) 2014 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_mRugged;
|
28
|
+
extern VALUE rb_cRuggedRepo;
|
29
|
+
|
30
|
+
VALUE rb_cRuggedReference;
|
31
|
+
|
32
|
+
void rb_git_ref__free(git_reference *ref)
|
33
|
+
{
|
34
|
+
git_reference_free(ref);
|
35
|
+
}
|
36
|
+
|
37
|
+
VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref)
|
38
|
+
{
|
39
|
+
VALUE rb_ref = Data_Wrap_Struct(klass, NULL, &rb_git_ref__free, ref);
|
40
|
+
rugged_set_owner(rb_ref, owner);
|
41
|
+
return rb_ref;
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* call-seq:
|
46
|
+
* Reference.valid_name?(ref_name) -> true or false
|
47
|
+
*
|
48
|
+
* Check if a reference name is well-formed.
|
49
|
+
*
|
50
|
+
* Valid reference names must follow one of two patterns:
|
51
|
+
*
|
52
|
+
* 1. Top-level names must contain only capital letters and underscores,
|
53
|
+
* and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
|
54
|
+
* 2. Names prefixed with "refs/" can be almost anything. You must avoid
|
55
|
+
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
|
56
|
+
* sequences ".." and "@{" which have special meaning to revparse.
|
57
|
+
*
|
58
|
+
* Returns true if the reference name is valid, false if not.
|
59
|
+
*/
|
60
|
+
static VALUE rb_git_ref_valid_name(VALUE klass, VALUE rb_name)
|
61
|
+
{
|
62
|
+
Check_Type(rb_name, T_STRING);
|
63
|
+
return git_reference_is_valid_name(StringValueCStr(rb_name)) == 1 ? Qtrue : Qfalse;
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq:
|
68
|
+
* ref.peel -> oid
|
69
|
+
*
|
70
|
+
* Peels tag objects to the sha that they point at. Replicates
|
71
|
+
* +git show-ref --dereference+.
|
72
|
+
*/
|
73
|
+
static VALUE rb_git_ref_peel(VALUE self)
|
74
|
+
{
|
75
|
+
/* Leave room for \0 */
|
76
|
+
git_reference *ref;
|
77
|
+
git_object *object;
|
78
|
+
char oid[GIT_OID_HEXSZ + 1];
|
79
|
+
int error;
|
80
|
+
|
81
|
+
Data_Get_Struct(self, git_reference, ref);
|
82
|
+
|
83
|
+
error = git_reference_peel(&object, ref, GIT_OBJ_ANY);
|
84
|
+
if (error == GIT_ENOTFOUND)
|
85
|
+
return Qnil;
|
86
|
+
else
|
87
|
+
rugged_exception_check(error);
|
88
|
+
|
89
|
+
if (git_reference_type(ref) == GIT_REF_OID &&
|
90
|
+
!git_oid_cmp(git_object_id(object), git_reference_target(ref))) {
|
91
|
+
git_object_free(object);
|
92
|
+
return Qnil;
|
93
|
+
} else {
|
94
|
+
git_oid_tostr(oid, sizeof(oid), git_object_id(object));
|
95
|
+
git_object_free(object);
|
96
|
+
return rb_str_new_utf8(oid);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* call-seq:
|
102
|
+
* reference.target_id -> id
|
103
|
+
* reference.target_id -> ref_name
|
104
|
+
*
|
105
|
+
* Return the target of +reference+.
|
106
|
+
*
|
107
|
+
* If +reference+ is a symbolic reference, it returns the target
|
108
|
+
* reference object.
|
109
|
+
*
|
110
|
+
* If +reference+ is a direct reference, it returns the target object.
|
111
|
+
*
|
112
|
+
* ref1.type #=> :symbolic
|
113
|
+
* ref1.target #=> #<Rugged::Reference ...>
|
114
|
+
*
|
115
|
+
* ref2.type #=> :direct
|
116
|
+
* ref2.target #=> #<Rugged::Commit ...>
|
117
|
+
*/
|
118
|
+
static VALUE rb_git_ref_target(VALUE self)
|
119
|
+
{
|
120
|
+
git_reference *ref;
|
121
|
+
|
122
|
+
Data_Get_Struct(self, git_reference, ref);
|
123
|
+
|
124
|
+
if (git_reference_type(ref) == GIT_REF_OID) {
|
125
|
+
git_object *target;
|
126
|
+
|
127
|
+
rugged_exception_check(
|
128
|
+
git_object_lookup(&target, git_reference_owner(ref), git_reference_target(ref), GIT_OBJ_ANY)
|
129
|
+
);
|
130
|
+
return rugged_object_new(rugged_owner(self), target);
|
131
|
+
} else {
|
132
|
+
git_reference *target;
|
133
|
+
|
134
|
+
rugged_exception_check(
|
135
|
+
git_reference_lookup(&target, git_reference_owner(ref), git_reference_symbolic_target(ref))
|
136
|
+
);
|
137
|
+
|
138
|
+
return rugged_ref_new(rb_cRuggedReference, rugged_owner(self), target);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
/*
|
143
|
+
* call-seq:
|
144
|
+
* reference.target_id -> id
|
145
|
+
* reference.target_id -> ref_name
|
146
|
+
*
|
147
|
+
* Return the target identifier of +reference+.
|
148
|
+
*
|
149
|
+
* If +reference+ is a symbolic reference, it returns the canonical
|
150
|
+
* name of the target reference.
|
151
|
+
*
|
152
|
+
* If +reference+ is a direct reference, it returns the sha id of the target.
|
153
|
+
*
|
154
|
+
* ref1.type #=> :symbolic
|
155
|
+
* ref1.target_id #=> "refs/heads/master"
|
156
|
+
*
|
157
|
+
* ref2.type #=> :direct
|
158
|
+
* ref2.target_id #=> "de5ba987198bcf2518885f0fc1350e5172cded78"
|
159
|
+
*/
|
160
|
+
static VALUE rb_git_ref_target_id(VALUE self)
|
161
|
+
{
|
162
|
+
git_reference *ref;
|
163
|
+
Data_Get_Struct(self, git_reference, ref);
|
164
|
+
|
165
|
+
if (git_reference_type(ref) == GIT_REF_OID) {
|
166
|
+
return rugged_create_oid(git_reference_target(ref));
|
167
|
+
} else {
|
168
|
+
return rb_str_new_utf8(git_reference_symbolic_target(ref));
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
/*
|
173
|
+
* call-seq:
|
174
|
+
* reference.type -> :symbolic or :direct
|
175
|
+
*
|
176
|
+
* Return whether the reference is +:symbolic+ or +:direct+
|
177
|
+
*/
|
178
|
+
static VALUE rb_git_ref_type(VALUE self)
|
179
|
+
{
|
180
|
+
git_reference *ref;
|
181
|
+
Data_Get_Struct(self, git_reference, ref);
|
182
|
+
|
183
|
+
switch (git_reference_type(ref)) {
|
184
|
+
case GIT_REF_OID:
|
185
|
+
return CSTR2SYM("direct");
|
186
|
+
case GIT_REF_SYMBOLIC:
|
187
|
+
return CSTR2SYM("symbolic");
|
188
|
+
default:
|
189
|
+
return Qnil;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
/*
|
194
|
+
* call-seq:
|
195
|
+
* reference.name -> name
|
196
|
+
* reference.canonical_name -> name
|
197
|
+
*
|
198
|
+
* Returns the fully qualified name of the reference.
|
199
|
+
*
|
200
|
+
* +name+ gets overwritten in subclasess like Rugged::Branch or Rugged::Tag
|
201
|
+
* to return "nicer" names for presentational purposes, while +canonical_name+
|
202
|
+
* is always supposed to return the fully qualified reference path.
|
203
|
+
*
|
204
|
+
* reference.name #=> 'HEAD'
|
205
|
+
*/
|
206
|
+
static VALUE rb_git_ref_name(VALUE self)
|
207
|
+
{
|
208
|
+
git_reference *ref;
|
209
|
+
Data_Get_Struct(self, git_reference, ref);
|
210
|
+
return rb_str_new_utf8(git_reference_name(ref));
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* call-seq:
|
215
|
+
* reference.resolve -> peeled_ref
|
216
|
+
*
|
217
|
+
* Peel a symbolic reference to its target reference.
|
218
|
+
*
|
219
|
+
* r1.type #=> :symbolic
|
220
|
+
* r1.name #=> 'HEAD'
|
221
|
+
* r1.target #=> 'refs/heads/master'
|
222
|
+
*
|
223
|
+
* r2 = r1.resolve #=> #<Rugged::Reference:0x401b3948>
|
224
|
+
* r2.target #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
|
225
|
+
*/
|
226
|
+
static VALUE rb_git_ref_resolve(VALUE self)
|
227
|
+
{
|
228
|
+
git_reference *ref;
|
229
|
+
git_reference *resolved;
|
230
|
+
int error;
|
231
|
+
|
232
|
+
Data_Get_Struct(self, git_reference, ref);
|
233
|
+
|
234
|
+
error = git_reference_resolve(&resolved, ref);
|
235
|
+
rugged_exception_check(error);
|
236
|
+
|
237
|
+
return rugged_ref_new(rb_cRuggedReference, rugged_owner(self), resolved);
|
238
|
+
}
|
239
|
+
|
240
|
+
static VALUE reflog_entry_new(const git_reflog_entry *entry)
|
241
|
+
{
|
242
|
+
VALUE rb_entry = rb_hash_new();
|
243
|
+
const char *message;
|
244
|
+
|
245
|
+
rb_hash_aset(rb_entry,
|
246
|
+
CSTR2SYM("id_old"),
|
247
|
+
rugged_create_oid(git_reflog_entry_id_old(entry))
|
248
|
+
);
|
249
|
+
|
250
|
+
rb_hash_aset(rb_entry,
|
251
|
+
CSTR2SYM("id_new"),
|
252
|
+
rugged_create_oid(git_reflog_entry_id_new(entry))
|
253
|
+
);
|
254
|
+
|
255
|
+
rb_hash_aset(rb_entry,
|
256
|
+
CSTR2SYM("committer"),
|
257
|
+
rugged_signature_new(git_reflog_entry_committer(entry), NULL)
|
258
|
+
);
|
259
|
+
|
260
|
+
if ((message = git_reflog_entry_message(entry)) != NULL) {
|
261
|
+
rb_hash_aset(rb_entry, CSTR2SYM("message"), rb_str_new_utf8(message));
|
262
|
+
}
|
263
|
+
|
264
|
+
return rb_entry;
|
265
|
+
}
|
266
|
+
|
267
|
+
/*
|
268
|
+
* call-seq:
|
269
|
+
* reference.log -> [reflog_entry, ...]
|
270
|
+
*
|
271
|
+
* Return an array with the log of all modifications to this reference
|
272
|
+
*
|
273
|
+
* Each +reflog_entry+ is a hash with the following keys:
|
274
|
+
*
|
275
|
+
* - +:id_old+: previous OID before the change
|
276
|
+
* - +:id_new+: OID after the change
|
277
|
+
* - +:committer+: author of the change
|
278
|
+
* - +:message+: message for the change
|
279
|
+
*
|
280
|
+
* Example:
|
281
|
+
*
|
282
|
+
* reference.log #=> [
|
283
|
+
* # {
|
284
|
+
* # :id_old => nil,
|
285
|
+
* # :id_new => '9d09060c850defbc7711d08b57def0d14e742f4e',
|
286
|
+
* # :committer => {:name => 'Vicent Marti', :email => {'vicent@github.com'}},
|
287
|
+
* # :message => 'created reference'
|
288
|
+
* # }, ... ]
|
289
|
+
*/
|
290
|
+
static VALUE rb_git_reflog(VALUE self)
|
291
|
+
{
|
292
|
+
git_reflog *reflog;
|
293
|
+
git_reference *ref;
|
294
|
+
int error;
|
295
|
+
VALUE rb_log;
|
296
|
+
size_t i, ref_count;
|
297
|
+
|
298
|
+
Data_Get_Struct(self, git_reference, ref);
|
299
|
+
|
300
|
+
error = git_reflog_read(&reflog, git_reference_owner(ref), git_reference_name(ref));
|
301
|
+
rugged_exception_check(error);
|
302
|
+
|
303
|
+
ref_count = git_reflog_entrycount(reflog);
|
304
|
+
rb_log = rb_ary_new2(ref_count);
|
305
|
+
|
306
|
+
for (i = 0; i < ref_count; ++i) {
|
307
|
+
const git_reflog_entry *entry =
|
308
|
+
git_reflog_entry_byindex(reflog, ref_count - i - 1);
|
309
|
+
|
310
|
+
rb_ary_push(rb_log, reflog_entry_new(entry));
|
311
|
+
}
|
312
|
+
|
313
|
+
git_reflog_free(reflog);
|
314
|
+
return rb_log;
|
315
|
+
}
|
316
|
+
|
317
|
+
/*
|
318
|
+
* call-seq:
|
319
|
+
* reference.log? -> true or false
|
320
|
+
*
|
321
|
+
* Return +true+ if the reference has a reflog, +false+ otherwise.
|
322
|
+
*/
|
323
|
+
static VALUE rb_git_has_reflog(VALUE self)
|
324
|
+
{
|
325
|
+
git_reference *ref;
|
326
|
+
git_repository *repo;
|
327
|
+
|
328
|
+
Data_Get_Struct(self, git_reference, ref);
|
329
|
+
repo = git_reference_owner(ref);
|
330
|
+
|
331
|
+
return git_reference_has_log(repo, git_reference_name(ref)) ? Qtrue : Qfalse;
|
332
|
+
}
|
333
|
+
|
334
|
+
/*
|
335
|
+
* call-seq:
|
336
|
+
* reference.branch? -> true or false
|
337
|
+
*
|
338
|
+
* Returns +true+ if +reference+ is a local branch, false otherwise.
|
339
|
+
*/
|
340
|
+
static VALUE rb_git_ref_is_branch(VALUE self)
|
341
|
+
{
|
342
|
+
git_reference *ref;
|
343
|
+
Data_Get_Struct(self, git_reference, ref);
|
344
|
+
return git_reference_is_branch(ref) ? Qtrue : Qfalse;
|
345
|
+
}
|
346
|
+
|
347
|
+
/*
|
348
|
+
* call-seq:
|
349
|
+
* reference.remote? -> true or false
|
350
|
+
*
|
351
|
+
* Returns +true+ if +reference+ is a remote branch, false otherwise.
|
352
|
+
*/
|
353
|
+
static VALUE rb_git_ref_is_remote(VALUE self)
|
354
|
+
{
|
355
|
+
git_reference *ref;
|
356
|
+
Data_Get_Struct(self, git_reference, ref);
|
357
|
+
return git_reference_is_remote(ref) ? Qtrue : Qfalse;
|
358
|
+
}
|
359
|
+
|
360
|
+
/*
|
361
|
+
* call-seq:
|
362
|
+
* reference.tag? -> true or false
|
363
|
+
*
|
364
|
+
* Returns +true+ if +reference+ is a tag, false otherwise.
|
365
|
+
*/
|
366
|
+
static VALUE rb_git_ref_is_tag(VALUE self)
|
367
|
+
{
|
368
|
+
git_reference *ref;
|
369
|
+
Data_Get_Struct(self, git_reference, ref);
|
370
|
+
return git_reference_is_tag(ref) ? Qtrue : Qfalse;
|
371
|
+
}
|
372
|
+
|
373
|
+
void Init_rugged_reference(void)
|
374
|
+
{
|
375
|
+
rb_cRuggedReference = rb_define_class_under(rb_mRugged, "Reference", rb_cObject);
|
376
|
+
|
377
|
+
rb_define_singleton_method(rb_cRuggedReference, "valid_name?", rb_git_ref_valid_name, 1);
|
378
|
+
|
379
|
+
rb_define_method(rb_cRuggedReference, "target", rb_git_ref_target, 0);
|
380
|
+
rb_define_method(rb_cRuggedReference, "target_id", rb_git_ref_target_id, 0);
|
381
|
+
rb_define_method(rb_cRuggedReference, "peel", rb_git_ref_peel, 0);
|
382
|
+
|
383
|
+
rb_define_method(rb_cRuggedReference, "type", rb_git_ref_type, 0);
|
384
|
+
|
385
|
+
rb_define_method(rb_cRuggedReference, "name", rb_git_ref_name, 0);
|
386
|
+
rb_define_method(rb_cRuggedReference, "canonical_name", rb_git_ref_name, 0);
|
387
|
+
|
388
|
+
rb_define_method(rb_cRuggedReference, "resolve", rb_git_ref_resolve, 0);
|
389
|
+
|
390
|
+
rb_define_method(rb_cRuggedReference, "branch?", rb_git_ref_is_branch, 0);
|
391
|
+
rb_define_method(rb_cRuggedReference, "remote?", rb_git_ref_is_remote, 0);
|
392
|
+
rb_define_method(rb_cRuggedReference, "tag?", rb_git_ref_is_tag, 0);
|
393
|
+
|
394
|
+
rb_define_method(rb_cRuggedReference, "log", rb_git_reflog, 0);
|
395
|
+
rb_define_method(rb_cRuggedReference, "log?", rb_git_has_reflog, 0);
|
396
|
+
}
|