rugged 0.17.0.b6 → 0.17.0.b7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. data/README.md +3 -3
  2. data/Rakefile +3 -1
  3. data/ext/rugged/rugged.c +30 -0
  4. data/ext/rugged/rugged.h +9 -0
  5. data/ext/rugged/rugged_branch.c +306 -0
  6. data/ext/rugged/rugged_config.c +16 -13
  7. data/ext/rugged/rugged_index.c +25 -0
  8. data/ext/rugged/rugged_object.c +6 -2
  9. data/ext/rugged/rugged_reference.c +11 -18
  10. data/ext/rugged/rugged_revwalk.c +1 -1
  11. data/lib/rugged.rb +1 -0
  12. data/lib/rugged/branch.rb +28 -0
  13. data/lib/rugged/commit.rb +5 -5
  14. data/lib/rugged/repository.rb +32 -7
  15. data/lib/rugged/tag.rb +5 -1
  16. data/lib/rugged/version.rb +1 -1
  17. data/test/branch_test.rb +227 -0
  18. data/test/config_test.rb +1 -1
  19. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  20. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  21. data/test/index_test.rb +31 -0
  22. data/test/index_test.rb~ +218 -0
  23. data/test/lib_test.rb +22 -0
  24. data/test/reference_test.rb +5 -3
  25. data/vendor/libgit2/Makefile.embed +1 -1
  26. data/vendor/libgit2/include/git2.h +1 -0
  27. data/vendor/libgit2/include/git2/branch.h +17 -13
  28. data/vendor/libgit2/include/git2/checkout.h +83 -22
  29. data/vendor/libgit2/include/git2/clone.h +6 -3
  30. data/vendor/libgit2/include/git2/common.h +1 -8
  31. data/vendor/libgit2/include/git2/config.h +185 -26
  32. data/vendor/libgit2/include/git2/diff.h +229 -17
  33. data/vendor/libgit2/include/git2/errors.h +39 -1
  34. data/vendor/libgit2/include/git2/ignore.h +6 -3
  35. data/vendor/libgit2/include/git2/indexer.h +1 -0
  36. data/vendor/libgit2/include/git2/merge.h +1 -1
  37. data/vendor/libgit2/include/git2/object.h +7 -4
  38. data/vendor/libgit2/include/git2/odb.h +4 -2
  39. data/vendor/libgit2/include/git2/odb_backend.h +6 -0
  40. data/vendor/libgit2/include/git2/oid.h +2 -0
  41. data/vendor/libgit2/include/git2/pack.h +89 -0
  42. data/vendor/libgit2/include/git2/refs.h +88 -0
  43. data/vendor/libgit2/include/git2/refspec.h +0 -8
  44. data/vendor/libgit2/include/git2/remote.h +34 -1
  45. data/vendor/libgit2/include/git2/repository.h +238 -6
  46. data/vendor/libgit2/include/git2/reset.h +4 -1
  47. data/vendor/libgit2/include/git2/revwalk.h +1 -1
  48. data/vendor/libgit2/include/git2/status.h +19 -14
  49. data/vendor/libgit2/include/git2/strarray.h +54 -0
  50. data/vendor/libgit2/include/git2/submodule.h +451 -45
  51. data/vendor/libgit2/include/git2/tag.h +16 -0
  52. data/vendor/libgit2/include/git2/tree.h +2 -2
  53. data/vendor/libgit2/include/git2/types.h +4 -0
  54. data/vendor/libgit2/src/amiga/map.c +4 -7
  55. data/vendor/libgit2/src/attr.c +21 -13
  56. data/vendor/libgit2/src/attr.h +3 -1
  57. data/vendor/libgit2/src/attr_file.c +14 -14
  58. data/vendor/libgit2/src/attr_file.h +6 -5
  59. data/vendor/libgit2/src/blob.c +22 -12
  60. data/vendor/libgit2/src/branch.c +62 -66
  61. data/vendor/libgit2/src/buffer.c +63 -14
  62. data/vendor/libgit2/src/buffer.h +4 -0
  63. data/vendor/libgit2/src/cache.c +5 -4
  64. data/vendor/libgit2/src/checkout.c +381 -159
  65. data/vendor/libgit2/src/clone.c +221 -94
  66. data/vendor/libgit2/src/common.h +13 -3
  67. data/vendor/libgit2/src/compress.c +53 -0
  68. data/vendor/libgit2/src/compress.h +16 -0
  69. data/vendor/libgit2/src/config.c +380 -175
  70. data/vendor/libgit2/src/config.h +2 -5
  71. data/vendor/libgit2/src/config_file.c +63 -46
  72. data/vendor/libgit2/src/config_file.h +16 -4
  73. data/vendor/libgit2/src/crlf.c +4 -3
  74. data/vendor/libgit2/src/delta.c +491 -0
  75. data/vendor/libgit2/src/delta.h +112 -0
  76. data/vendor/libgit2/src/diff.c +310 -67
  77. data/vendor/libgit2/src/diff.h +10 -1
  78. data/vendor/libgit2/src/diff_output.c +1030 -337
  79. data/vendor/libgit2/src/diff_output.h +86 -0
  80. data/vendor/libgit2/src/errors.c +10 -1
  81. data/vendor/libgit2/src/fetch.c +108 -24
  82. data/vendor/libgit2/src/filebuf.c +8 -2
  83. data/vendor/libgit2/src/fileops.c +342 -177
  84. data/vendor/libgit2/src/fileops.h +84 -7
  85. data/vendor/libgit2/src/filter.c +0 -35
  86. data/vendor/libgit2/src/filter.h +0 -12
  87. data/vendor/libgit2/src/{compat/fnmatch.c → fnmatch.c} +16 -4
  88. data/vendor/libgit2/src/{compat/fnmatch.h → fnmatch.h} +4 -3
  89. data/vendor/libgit2/src/global.c +4 -0
  90. data/vendor/libgit2/src/ignore.c +122 -23
  91. data/vendor/libgit2/src/ignore.h +1 -0
  92. data/vendor/libgit2/src/index.c +56 -10
  93. data/vendor/libgit2/src/index.h +2 -0
  94. data/vendor/libgit2/src/indexer.c +8 -9
  95. data/vendor/libgit2/src/iterator.c +244 -31
  96. data/vendor/libgit2/src/iterator.h +30 -1
  97. data/vendor/libgit2/src/message.c +1 -1
  98. data/vendor/libgit2/src/netops.c +44 -4
  99. data/vendor/libgit2/src/object.c +80 -69
  100. data/vendor/libgit2/src/object.h +39 -0
  101. data/vendor/libgit2/src/odb.c +79 -15
  102. data/vendor/libgit2/src/odb.h +20 -5
  103. data/vendor/libgit2/src/odb_pack.c +65 -33
  104. data/vendor/libgit2/src/oid.c +0 -3
  105. data/vendor/libgit2/src/pack-objects.c +1315 -0
  106. data/vendor/libgit2/src/pack-objects.h +87 -0
  107. data/vendor/libgit2/src/pack.c +36 -12
  108. data/vendor/libgit2/src/pack.h +1 -0
  109. data/vendor/libgit2/src/path.c +42 -9
  110. data/vendor/libgit2/src/path.h +14 -0
  111. data/vendor/libgit2/src/pkt.c +52 -2
  112. data/vendor/libgit2/src/pkt.h +10 -0
  113. data/vendor/libgit2/src/pool.h +11 -0
  114. data/vendor/libgit2/src/posix.h +8 -0
  115. data/vendor/libgit2/src/protocol.c +24 -2
  116. data/vendor/libgit2/src/protocol.h +4 -0
  117. data/vendor/libgit2/src/reflog.c +1 -1
  118. data/vendor/libgit2/src/refs.c +292 -124
  119. data/vendor/libgit2/src/refs.h +4 -2
  120. data/vendor/libgit2/src/refspec.c +117 -19
  121. data/vendor/libgit2/src/refspec.h +19 -0
  122. data/vendor/libgit2/src/remote.c +152 -48
  123. data/vendor/libgit2/src/remote.h +4 -1
  124. data/vendor/libgit2/src/repo_template.h +58 -0
  125. data/vendor/libgit2/src/repository.c +594 -179
  126. data/vendor/libgit2/src/repository.h +23 -22
  127. data/vendor/libgit2/src/reset.c +71 -29
  128. data/vendor/libgit2/src/revparse.c +26 -17
  129. data/vendor/libgit2/src/revwalk.c +36 -19
  130. data/vendor/libgit2/src/sha1.h +7 -0
  131. data/vendor/libgit2/src/{sha1.c → sha1/sha1.c} +0 -0
  132. data/vendor/libgit2/src/signature.c +12 -10
  133. data/vendor/libgit2/src/status.c +52 -6
  134. data/vendor/libgit2/src/submodule.c +1363 -255
  135. data/vendor/libgit2/src/submodule.h +102 -0
  136. data/vendor/libgit2/src/tag.c +42 -26
  137. data/vendor/libgit2/src/thread-utils.h +7 -7
  138. data/vendor/libgit2/src/transport.h +15 -1
  139. data/vendor/libgit2/src/transports/git.c +1 -1
  140. data/vendor/libgit2/src/transports/http.c +197 -36
  141. data/vendor/libgit2/src/tree.c +3 -3
  142. data/vendor/libgit2/src/unix/map.c +2 -0
  143. data/vendor/libgit2/src/unix/posix.h +1 -8
  144. data/vendor/libgit2/src/util.c +6 -1
  145. data/vendor/libgit2/src/util.h +7 -0
  146. data/vendor/libgit2/src/vector.c +16 -0
  147. data/vendor/libgit2/src/vector.h +1 -0
  148. data/vendor/libgit2/src/win32/dir.c +8 -21
  149. data/vendor/libgit2/src/win32/findfile.c +149 -0
  150. data/vendor/libgit2/src/win32/findfile.h +23 -0
  151. data/vendor/libgit2/src/win32/posix.h +3 -7
  152. data/vendor/libgit2/src/win32/posix_w32.c +44 -102
  153. data/vendor/libgit2/src/win32/pthread.c +68 -0
  154. data/vendor/libgit2/src/win32/pthread.h +7 -0
  155. data/vendor/libgit2/src/win32/utf-conv.c +60 -71
  156. data/vendor/libgit2/src/win32/utf-conv.h +4 -3
  157. metadata +70 -71
  158. data/vendor/libgit2/include/git2/windows.h +0 -59
data/README.md CHANGED
@@ -126,7 +126,7 @@ these methods should be useful in their derived classes.
126
126
  ```ruby
127
127
  obj = repo.lookup(sha)
128
128
  obj.oid # object sha
129
- obj.type [OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, OBJ_TAG]
129
+ obj.type # One of :commit, :tree, :blob or :tag
130
130
 
131
131
  robj = obj.read_raw
132
132
  str = robj.data
@@ -196,7 +196,7 @@ tree.count
196
196
  tree[0] # or...
197
197
  tree.first # or...
198
198
  tree.get_entry(0)
199
- # => {:type=>:blob, :oid=>"99e7edb53db9355f10c6f2dfaa5a183f205d93bf", :attributes=>33188, :name=>".gitignore"}
199
+ # => {:type=>:blob, :oid=>"99e7edb53db9355f10c6f2dfaa5a183f205d93bf", :filemode=>33188, :name=>".gitignore"}
200
200
  ```
201
201
 
202
202
  The tree object is an Enumerable, so you can also do stuff like this:
@@ -219,7 +219,7 @@ You can also write trees with the `TreeBuilder`:
219
219
  entry = {:type => :blob,
220
220
  :name => "README.txt",
221
221
  :oid => "1385f264afb75a56a5bec74243be9b367ba4ca08",
222
- :attributes => 33188}
222
+ :filemode => 33188}
223
223
 
224
224
  builder = Rugged::Tree::Builder.new
225
225
  builder << entry
data/Rakefile CHANGED
@@ -16,7 +16,9 @@ end
16
16
 
17
17
  desc "checkout libgit2 source"
18
18
  task :checkout do
19
- sh "git submodule update --init"
19
+ if !ENV['LIBGIT2_DEV']
20
+ sh "git submodule update --init"
21
+ end
20
22
  end
21
23
  Rake::Task[:compile].prerequisites.insert(0, :checkout)
22
24
 
@@ -96,6 +96,34 @@ static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
96
96
  return rugged_str_new(out, 40, NULL);
97
97
  }
98
98
 
99
+ /*
100
+ * call-seq:
101
+ * Rugged.prettify_message(message, strip_comments) -> clean_message
102
+ *
103
+ * Process a commit or tag message into standard form, by stripping trailing spaces and
104
+ * comments, and making sure that the message has a proper header line.
105
+ */
106
+ static VALUE rb_git_prettify_message(VALUE self, VALUE rb_message, VALUE rb_strip_comments)
107
+ {
108
+ char *message;
109
+ int strip_comments, message_len;
110
+ VALUE result;
111
+
112
+ Check_Type(rb_message, T_STRING);
113
+ strip_comments = rugged_parse_bool(rb_strip_comments);
114
+
115
+ message_len = (int)RSTRING_LEN(rb_message) + 2;
116
+ message = xmalloc(message_len);
117
+
118
+ message_len = git_message_prettify(message, message_len, StringValueCStr(rb_message), strip_comments);
119
+ rugged_exception_check(message_len);
120
+
121
+ result = rugged_str_new(message, message_len - 1, rb_utf8_encoding());
122
+ xfree(message);
123
+
124
+ return result;
125
+ }
126
+
99
127
  static VALUE minimize_cb(VALUE rb_oid, git_oid_shorten *shortener)
100
128
  {
101
129
  Check_Type(rb_oid, T_STRING);
@@ -232,6 +260,7 @@ void Init_rugged()
232
260
  rb_define_module_function(rb_mRugged, "hex_to_raw", rb_git_hex_to_raw, 1);
233
261
  rb_define_module_function(rb_mRugged, "raw_to_hex", rb_git_raw_to_hex, 1);
234
262
  rb_define_module_function(rb_mRugged, "minimize_oid", rb_git_minimize_oid, -1);
263
+ rb_define_module_function(rb_mRugged, "prettify_message", rb_git_prettify_message, 2);
235
264
 
236
265
  Init_rugged_object();
237
266
  Init_rugged_commit();
@@ -243,6 +272,7 @@ void Init_rugged()
243
272
  Init_rugged_repo();
244
273
  Init_rugged_revwalk();
245
274
  Init_rugged_reference();
275
+ Init_rugged_branch();
246
276
  Init_rugged_config();
247
277
  Init_rugged_remote();
248
278
 
@@ -46,6 +46,7 @@
46
46
  * Initialization functions
47
47
  */
48
48
  void Init_rugged_object();
49
+ void Init_rugged_branch();
49
50
  void Init_rugged_commit();
50
51
  void Init_rugged_tree();
51
52
  void Init_rugged_tag();
@@ -66,6 +67,7 @@ VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);
66
67
  VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
67
68
  VALUE rugged_object_new(VALUE owner, git_object *object);
68
69
  VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
70
+ VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref);
69
71
 
70
72
  VALUE rugged_otype_new(git_otype t);
71
73
  git_otype rugged_otype_get(VALUE rb_type);
@@ -118,4 +120,11 @@ static inline VALUE rugged_create_oid(const git_oid *oid)
118
120
  return rugged_str_new(out, 40, NULL);
119
121
  }
120
122
 
123
+ #define RUGGED_UNPACK_REFERENCE(_rb_obj, _rugged_obj) {\
124
+ if (DATA_PTR(_rb_obj) == NULL)\
125
+ rb_raise(rb_eRuntimeError,\
126
+ "This Git Reference has been deleted and no longer exists on the repository");\
127
+ Data_Get_Struct(_rb_obj, git_reference, _rugged_obj);\
128
+ }
129
+
121
130
  #endif
@@ -0,0 +1,306 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2012 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
+ extern VALUE rb_cRuggedObject;
30
+ extern VALUE rb_cRuggedReference;
31
+ VALUE rb_cRuggedBranch;
32
+
33
+ static inline VALUE rugged_branch_new(VALUE owner, git_reference *ref)
34
+ {
35
+ return rugged_ref_new(rb_cRuggedBranch, owner, ref);
36
+ }
37
+
38
+ static int parse_branch_type(VALUE rb_filter)
39
+ {
40
+ ID id_filter;
41
+
42
+ Check_Type(rb_filter, T_SYMBOL);
43
+ id_filter = SYM2ID(rb_filter);
44
+
45
+ if (id_filter == rb_intern("local")) {
46
+ return GIT_BRANCH_LOCAL;
47
+ } else if (id_filter == rb_intern("remote")) {
48
+ return GIT_BRANCH_REMOTE;
49
+ } else {
50
+ rb_raise(rb_eTypeError,
51
+ "Invalid branch filter. Expected `:remote`, `:local` or `nil`");
52
+ }
53
+ }
54
+
55
+ /*
56
+ * call-seq:
57
+ * Branch.create(repository, name, target, force = false) -> branch
58
+ *
59
+ * Create a new branch in +repository+, with the given +name+, and pointing
60
+ * to the +target+.
61
+ *
62
+ * +name+ needs to be a branch name, not an absolute reference path
63
+ * (e.g. 'development' instead of '/refs/heads/development')
64
+ *
65
+ * +target+ needs to be an existing object (of any type) in the given +repository+.
66
+ *
67
+ * If +force+ is +true+, any existing branches will be overwritten.
68
+ *
69
+ * Returns a Rugged::Branch object with the newly created branch.
70
+ */
71
+ static VALUE rb_git_branch_create(int argc, VALUE *argv, VALUE self)
72
+ {
73
+ git_reference *branch;
74
+ git_object *target = NULL;
75
+ git_repository *repo = NULL;
76
+ int error, force = 0;
77
+
78
+ VALUE rb_repo, rb_name, rb_target, rb_force;
79
+
80
+ rb_scan_args(argc, argv, "31", &rb_repo, &rb_name, &rb_target, &rb_force);
81
+
82
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo)) {
83
+ rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
84
+ }
85
+
86
+ Data_Get_Struct(rb_repo, git_repository, repo);
87
+
88
+ Check_Type(rb_name, T_STRING);
89
+
90
+ target = rugged_object_load(repo, rb_target, GIT_OBJ_ANY);
91
+
92
+ if (!NIL_P(rb_force)) {
93
+ force = rugged_parse_bool(rb_force);
94
+ }
95
+
96
+ error = git_branch_create(&branch, repo, StringValueCStr(rb_name), target, force);
97
+ git_object_free(target);
98
+
99
+ rugged_exception_check(error);
100
+
101
+ return rugged_branch_new(rb_repo, branch);
102
+ }
103
+
104
+ /*
105
+ * call-seq:
106
+ * Branch.lookup(repository, name, branch_type = :local) -> branch
107
+ *
108
+ * Lookup a branch in +repository+, with the given +name+.
109
+ *
110
+ * +name+ needs to be a branch name, not an absolute reference path
111
+ * (e.g. 'development' instead of '/refs/heads/development')
112
+ *
113
+ * +branch_type+ specifies whether the looked up branch is a local branch
114
+ * or a remote one. It defaults to looking up local branches.
115
+ *
116
+ * Returns the looked up branch, or +nil+ if the branch doesn't exist.
117
+ */
118
+ static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
119
+ {
120
+ git_reference *branch;
121
+ git_repository *repo;
122
+
123
+ VALUE rb_repo, rb_name, rb_type;
124
+ int error;
125
+ int branch_type = GIT_BRANCH_LOCAL;
126
+
127
+ rb_scan_args(argc, argv, "21", &rb_repo, &rb_name, &rb_type);
128
+
129
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo)) {
130
+ rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
131
+ }
132
+
133
+ Data_Get_Struct(rb_repo, git_repository, repo);
134
+
135
+ Check_Type(rb_name, T_STRING);
136
+
137
+ if (!NIL_P(rb_type))
138
+ branch_type = parse_branch_type(rb_type);
139
+
140
+ error = git_branch_lookup(&branch, repo, StringValueCStr(rb_name), branch_type);
141
+ if (error == GIT_ENOTFOUND)
142
+ return Qnil;
143
+
144
+ rugged_exception_check(error);
145
+
146
+ return rugged_branch_new(rb_repo, branch);
147
+ }
148
+
149
+ /*
150
+ * call-seq:
151
+ * branch.delete!
152
+ *
153
+ * Remove a branch from the repository. The branch object will become invalidated
154
+ * and won't be able to be used for any other operations.
155
+ */
156
+ static VALUE rb_git_branch_delete(VALUE self)
157
+ {
158
+ git_reference *branch = NULL;
159
+
160
+ RUGGED_UNPACK_REFERENCE(self, branch);
161
+
162
+ rugged_exception_check(
163
+ git_branch_delete(branch)
164
+ );
165
+
166
+ DATA_PTR(self) = NULL; /* this reference has been free'd */
167
+ rugged_set_owner(self, Qnil); /* and is no longer owned */
168
+ return Qnil;
169
+ }
170
+
171
+ static int cb_branch__each_name(const char *branch_name, git_branch_t branch_type, void *payload)
172
+ {
173
+ rb_yield(rugged_str_new2(branch_name, rb_utf8_encoding()));
174
+ return GIT_OK;
175
+ }
176
+
177
+ static int cb_branch__each_obj(const char *branch_name, git_branch_t branch_type, void *payload)
178
+ {
179
+ VALUE rb_repo = (VALUE)payload;
180
+
181
+ git_reference *branch;
182
+ git_repository *repo;
183
+
184
+ Data_Get_Struct(rb_repo, git_repository, repo);
185
+
186
+ rugged_exception_check(
187
+ git_branch_lookup(&branch, repo, branch_name, branch_type)
188
+ );
189
+
190
+ rb_yield(rugged_branch_new(rb_repo, branch));
191
+ return GIT_OK;
192
+ }
193
+
194
+ static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_only)
195
+ {
196
+ VALUE rb_repo, rb_filter;
197
+ git_repository *repo;
198
+ int error;
199
+ int filter = (GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE);
200
+
201
+ rb_scan_args(argc, argv, "11", &rb_repo, &rb_filter);
202
+
203
+ if (!rb_block_given_p()) {
204
+ VALUE symbol = branch_names_only ? CSTR2SYM("each_name") : CSTR2SYM("each");
205
+ return rb_funcall(self, rb_intern("to_enum"), 3, symbol, rb_repo, rb_filter);
206
+ }
207
+
208
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo)) {
209
+ rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
210
+ }
211
+
212
+ if (!NIL_P(rb_filter))
213
+ filter = parse_branch_type(rb_filter);
214
+
215
+ Data_Get_Struct(rb_repo, git_repository, repo);
216
+
217
+ if (branch_names_only) {
218
+ error = git_branch_foreach(repo, filter, &cb_branch__each_name, NULL);
219
+ } else {
220
+ error = git_branch_foreach(repo, filter, &cb_branch__each_obj, (void *)rb_repo);
221
+ }
222
+
223
+ rugged_exception_check(error);
224
+ return Qnil;
225
+ }
226
+
227
+ /*
228
+ * call-seq:
229
+ * Branch.each_name(repository, filter = :all) { |branch_name| block }
230
+ * Branch.each_name(repository, filter = :all) -> Iterator
231
+ *
232
+ * Iterate through the names of the branches in +repository+. Iteration can be
233
+ * optionally filtered to yield only +:local+ or +:remote+ branches.
234
+ *
235
+ * The given block will be called once with the name of each branch as a +String+.
236
+ * If no block is given, an iterator will be returned.
237
+ */
238
+ static VALUE rb_git_branch_each_name(int argc, VALUE *argv, VALUE self)
239
+ {
240
+ return each_branch(argc, argv, self, 1);
241
+ }
242
+
243
+
244
+ /*
245
+ * call-seq:
246
+ * Branch.each(repository, filter = :all) { |branch| block }
247
+ * Branch.each(repository, filter = :all) -> Iterator
248
+ *
249
+ * Iterate through the branches in +repository+. Iteration can be
250
+ * optionally filtered to yield only +:local+ or +:remote+ branches.
251
+ *
252
+ * The given block will be called once with a +Rugged::Branch+ object
253
+ * for each branch in the repository. If no block is given, an iterator
254
+ * will be returned.
255
+ */
256
+ static VALUE rb_git_branch_each(int argc, VALUE *argv, VALUE self)
257
+ {
258
+ return each_branch(argc, argv, self, 0);
259
+ }
260
+
261
+ /*
262
+ * call-seq:
263
+ * branch.move(new_name, force = false)
264
+ * branch.rename(new_name, force = false)
265
+ *
266
+ * Rename a branch to +new_name+.
267
+ *
268
+ * +new_name+ needs to be a branch name, not an absolute reference path
269
+ * (e.g. 'development' instead of '/refs/heads/development')
270
+ *
271
+ * If +force+ is +true+, the branch will be renamed even if a branch
272
+ * with +new_name+ already exists.
273
+ */
274
+ static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
275
+ {
276
+ VALUE rb_new_branch_name, rb_force;
277
+ git_reference *old_branch = NULL;
278
+ int error, force = 0;
279
+
280
+ rb_scan_args(argc, argv, "11", &rb_new_branch_name, &rb_force);
281
+
282
+ RUGGED_UNPACK_REFERENCE(self, old_branch);
283
+ Check_Type(rb_new_branch_name, T_STRING);
284
+
285
+ if (!NIL_P(rb_force))
286
+ force = rugged_parse_bool(rb_force);
287
+
288
+ error = git_branch_move(old_branch, StringValueCStr(rb_new_branch_name), force);
289
+ rugged_exception_check(error);
290
+
291
+ return Qnil;
292
+ }
293
+
294
+ void Init_rugged_branch()
295
+ {
296
+ rb_cRuggedBranch = rb_define_class_under(rb_mRugged, "Branch", rb_cRuggedReference);
297
+
298
+ rb_define_singleton_method(rb_cRuggedBranch, "create", rb_git_branch_create, -1);
299
+ rb_define_singleton_method(rb_cRuggedBranch, "lookup", rb_git_branch_lookup, -1);
300
+ rb_define_singleton_method(rb_cRuggedBranch, "each_name", rb_git_branch_each_name, -1);
301
+ rb_define_singleton_method(rb_cRuggedBranch, "each", rb_git_branch_each, -1);
302
+
303
+ rb_define_method(rb_cRuggedBranch, "delete!", rb_git_branch_delete, 0);
304
+ rb_define_method(rb_cRuggedBranch, "rename", rb_git_branch_move, -1);
305
+ rb_define_method(rb_cRuggedBranch, "move", rb_git_branch_move, -1);
306
+ }
@@ -59,7 +59,7 @@ static VALUE rb_git_config_new(VALUE klass, VALUE rb_path)
59
59
  for (i = 0; i < RARRAY_LEN(rb_path); ++i) {
60
60
  VALUE f = rb_ary_entry(rb_path, i);
61
61
  Check_Type(f, T_STRING);
62
- error = git_config_add_file_ondisk(config, StringValueCStr(f), i + 1);
62
+ error = git_config_add_file_ondisk(config, StringValueCStr(f), i + 1, 1);
63
63
  rugged_exception_check(error);
64
64
  }
65
65
  } else if (TYPE(rb_path) == T_STRING) {
@@ -178,26 +178,26 @@ static VALUE rb_git_config_delete(VALUE self, VALUE rb_key)
178
178
  return Qtrue;
179
179
  }
180
180
 
181
- static int cb_config__each_key(const char *key, const char *value, void *opaque)
181
+ static int cb_config__each_key(const git_config_entry *entry, void *opaque)
182
182
  {
183
- rb_funcall((VALUE)opaque, rb_intern("call"), 1, rugged_str_new2(key, NULL));
183
+ rb_funcall((VALUE)opaque, rb_intern("call"), 1, rugged_str_new2(entry->name, NULL));
184
184
  return GIT_OK;
185
185
  }
186
186
 
187
- static int cb_config__each_pair(const char *key, const char *value, void *opaque)
187
+ static int cb_config__each_pair(const git_config_entry *entry, void *opaque)
188
188
  {
189
189
  rb_funcall((VALUE)opaque, rb_intern("call"), 2,
190
- rugged_str_new2(key, NULL),
191
- rugged_str_new2(value, NULL));
190
+ rugged_str_new2(entry->name, NULL),
191
+ rugged_str_new2(entry->value, NULL));
192
192
 
193
193
  return GIT_OK;
194
194
  }
195
195
 
196
- static int cb_config__to_hash(const char *key, const char *value, void *opaque)
196
+ static int cb_config__to_hash(const git_config_entry *entry, void *opaque)
197
197
  {
198
198
  rb_hash_aset((VALUE)opaque,
199
- rugged_str_new2(key, NULL),
200
- rugged_str_new2(value, NULL));
199
+ rugged_str_new2(entry->name, NULL),
200
+ rugged_str_new2(entry->value, NULL));
201
201
 
202
202
  return GIT_OK;
203
203
  }
@@ -284,18 +284,19 @@ static VALUE rb_git_config_to_hash(VALUE self)
284
284
 
285
285
  /*
286
286
  * call-seq:
287
+ * Config.global() -> new_config
287
288
  * Config.open_global() -> new_config
288
289
  *
289
- * Open the global config file as a new +Rugged::Config+ object.
290
+ * Open the default global config file as a new +Rugged::Config+ object.
290
291
  * An exception will be raised if the global config file doesn't
291
292
  * exist.
292
293
  */
293
- static VALUE rb_git_config_open_global(VALUE klass)
294
+ static VALUE rb_git_config_open_default(VALUE klass)
294
295
  {
295
296
  git_config *cfg;
296
297
  int error;
297
298
 
298
- error = git_config_open_global(&cfg);
299
+ error = git_config_open_default(&cfg);
299
300
  rugged_exception_check(error);
300
301
 
301
302
  return rugged_config_new(klass, Qnil, cfg);
@@ -308,7 +309,9 @@ void Init_rugged_config()
308
309
  */
309
310
  rb_cRuggedConfig = rb_define_class_under(rb_mRugged, "Config", rb_cObject);
310
311
  rb_define_singleton_method(rb_cRuggedConfig, "new", rb_git_config_new, 1);
311
- rb_define_singleton_method(rb_cRuggedConfig, "open_global", rb_git_config_open_global, 0);
312
+
313
+ rb_define_singleton_method(rb_cRuggedConfig, "global", rb_git_config_open_default, 0);
314
+ rb_define_singleton_method(rb_cRuggedConfig, "open_global", rb_git_config_open_default, 0);
312
315
 
313
316
  rb_define_method(rb_cRuggedConfig, "delete", rb_git_config_delete, 1);
314
317