rugged 0.18.0.gh.de28323 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -4
- data/Rakefile +1 -1
- data/ext/rugged/extconf.rb +10 -0
- data/ext/rugged/rugged.c +153 -86
- data/ext/rugged/rugged.h +44 -33
- data/ext/rugged/rugged_blob.c +288 -60
- data/ext/rugged/rugged_branch.c +82 -57
- data/ext/rugged/rugged_commit.c +83 -86
- data/ext/rugged/rugged_config.c +68 -68
- data/ext/rugged/rugged_diff.c +509 -0
- data/ext/rugged/rugged_diff_delta.c +94 -0
- data/ext/rugged/rugged_diff_hunk.c +100 -0
- data/ext/rugged/rugged_diff_line.c +79 -0
- data/ext/rugged/rugged_diff_patch.c +169 -0
- data/ext/rugged/rugged_index.c +539 -8
- data/ext/rugged/rugged_note.c +74 -80
- data/ext/rugged/rugged_object.c +63 -8
- data/ext/rugged/rugged_reference.c +231 -145
- data/ext/rugged/rugged_remote.c +509 -53
- data/ext/rugged/rugged_repo.c +572 -236
- data/ext/rugged/rugged_revwalk.c +59 -36
- data/ext/rugged/rugged_settings.c +7 -9
- data/ext/rugged/rugged_signature.c +7 -11
- data/ext/rugged/rugged_tag.c +93 -39
- data/ext/rugged/rugged_tree.c +321 -58
- data/lib/rugged.rb +1 -0
- data/lib/rugged/commit.rb +16 -1
- data/lib/rugged/console.rb +9 -0
- data/lib/rugged/diff.rb +19 -0
- data/lib/rugged/diff/delta.rb +54 -0
- data/lib/rugged/diff/hunk.rb +23 -0
- data/lib/rugged/diff/line.rb +29 -0
- data/lib/rugged/diff/patch.rb +28 -0
- data/lib/rugged/repository.rb +36 -39
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +308 -1
- data/test/branch_test.rb +7 -0
- data/test/commit_test.rb +7 -10
- data/test/coverage/cover.rb +9 -1
- data/test/diff_test.rb +777 -0
- data/test/fixtures/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +1 -0
- data/test/fixtures/attr/attr1 +29 -0
- data/test/fixtures/attr/attr2 +21 -0
- data/test/fixtures/attr/attr3 +4 -0
- data/test/fixtures/attr/binfile +1 -0
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +1 -0
- data/test/fixtures/attr/gitattributes +29 -0
- data/test/fixtures/attr/gitignore +2 -0
- data/test/fixtures/attr/ign +1 -0
- data/test/fixtures/attr/macro_bad +1 -0
- data/test/fixtures/attr/macro_test +1 -0
- data/test/fixtures/attr/root_test1 +1 -0
- data/test/fixtures/attr/root_test2 +6 -0
- data/test/fixtures/attr/root_test3 +19 -0
- data/test/fixtures/attr/root_test4.txt +14 -0
- data/test/fixtures/attr/sub/abc +37 -0
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +1 -0
- data/test/fixtures/attr/sub/ign/file +1 -0
- data/test/fixtures/attr/sub/ign/sub/file +1 -0
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +1 -0
- data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
- data/test/fixtures/attr/sub/subdir_test1 +2 -0
- data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
- data/test/fixtures/diff/another.txt +38 -0
- data/test/fixtures/diff/readme.txt +36 -0
- data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
- data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
- data/test/fixtures/mergedrepo/one.txt +10 -0
- data/test/fixtures/mergedrepo/two.txt +12 -0
- data/test/fixtures/status/current_file +1 -0
- data/test/fixtures/status/ignored_file +1 -0
- data/test/fixtures/status/modified_file +2 -0
- data/test/fixtures/status/new_file +1 -0
- data/test/fixtures/status/staged_changes +2 -0
- data/test/fixtures/status/staged_changes_modified_file +3 -0
- data/test/fixtures/status/staged_delete_modified_file +1 -0
- data/test/fixtures/status/staged_new_file +1 -0
- data/test/fixtures/status/staged_new_file_modified_file +2 -0
- data/test/fixtures/status/subdir.txt +2 -0
- data/test/fixtures/status/subdir/current_file +1 -0
- data/test/fixtures/status/subdir/modified_file +2 -0
- data/test/fixtures/status/subdir/new_file +1 -0
- data/test/fixtures/status//350/277/231 +1 -0
- data/test/fixtures/testrepo.git/config +5 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/text_file.md +464 -0
- data/test/fixtures/unsymlinked.git/HEAD +1 -0
- data/test/fixtures/unsymlinked.git/config +6 -0
- data/test/fixtures/unsymlinked.git/description +1 -0
- data/test/fixtures/unsymlinked.git/info/exclude +2 -0
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
- data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
- data/test/index_test.rb +120 -0
- data/test/reference_test.rb +38 -3
- data/test/remote_test.rb +224 -3
- data/test/repo_reset_test.rb +2 -0
- data/test/repo_test.rb +147 -10
- data/test/test_helper.rb +5 -2
- data/vendor/libgit2/include/git2/attr.h +3 -3
- data/vendor/libgit2/include/git2/blob.h +11 -17
- data/vendor/libgit2/include/git2/branch.h +3 -2
- data/vendor/libgit2/include/git2/checkout.h +7 -0
- data/vendor/libgit2/include/git2/clone.h +3 -0
- data/vendor/libgit2/include/git2/commit.h +61 -66
- data/vendor/libgit2/include/git2/common.h +73 -42
- data/vendor/libgit2/include/git2/config.h +57 -71
- data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
- data/vendor/libgit2/include/git2/diff.h +179 -30
- data/vendor/libgit2/include/git2/errors.h +3 -3
- data/vendor/libgit2/include/git2/index.h +225 -146
- data/vendor/libgit2/include/git2/indexer.h +2 -22
- data/vendor/libgit2/include/git2/inttypes.h +9 -9
- data/vendor/libgit2/include/git2/merge.h +123 -5
- data/vendor/libgit2/include/git2/odb.h +59 -38
- data/vendor/libgit2/include/git2/odb_backend.h +45 -104
- data/vendor/libgit2/include/git2/oid.h +30 -19
- data/vendor/libgit2/include/git2/pack.h +21 -3
- data/vendor/libgit2/include/git2/refdb.h +0 -35
- data/vendor/libgit2/include/git2/refs.h +93 -31
- data/vendor/libgit2/include/git2/refspec.h +17 -0
- data/vendor/libgit2/include/git2/remote.h +60 -20
- data/vendor/libgit2/include/git2/repository.h +48 -70
- data/vendor/libgit2/include/git2/reset.h +3 -3
- data/vendor/libgit2/include/git2/revparse.h +22 -0
- data/vendor/libgit2/include/git2/stash.h +1 -1
- data/vendor/libgit2/include/git2/status.h +131 -56
- data/vendor/libgit2/include/git2/strarray.h +2 -2
- data/vendor/libgit2/include/git2/submodule.h +16 -16
- data/vendor/libgit2/include/git2/sys/commit.h +46 -0
- data/vendor/libgit2/include/git2/sys/config.h +71 -0
- data/vendor/libgit2/include/git2/sys/index.h +179 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
- data/vendor/libgit2/include/git2/sys/refs.h +38 -0
- data/vendor/libgit2/include/git2/sys/repository.h +106 -0
- data/vendor/libgit2/include/git2/tag.h +44 -18
- data/vendor/libgit2/include/git2/trace.h +1 -2
- data/vendor/libgit2/include/git2/transport.h +74 -0
- data/vendor/libgit2/include/git2/tree.h +12 -22
- data/vendor/libgit2/include/git2/types.h +33 -0
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/src/array.h +66 -0
- data/vendor/libgit2/src/attr.c +26 -13
- data/vendor/libgit2/src/attr_file.c +3 -2
- data/vendor/libgit2/src/attr_file.h +3 -3
- data/vendor/libgit2/src/attrcache.h +4 -4
- data/vendor/libgit2/src/blob.c +13 -9
- data/vendor/libgit2/src/blob.h +2 -2
- data/vendor/libgit2/src/branch.c +67 -49
- data/vendor/libgit2/src/cache.c +224 -54
- data/vendor/libgit2/src/cache.h +33 -20
- data/vendor/libgit2/src/checkout.c +145 -85
- data/vendor/libgit2/src/clone.c +62 -50
- data/vendor/libgit2/src/commit.c +74 -40
- data/vendor/libgit2/src/commit.h +2 -3
- data/vendor/libgit2/src/commit_list.c +14 -8
- data/vendor/libgit2/src/config.c +119 -36
- data/vendor/libgit2/src/config.h +3 -0
- data/vendor/libgit2/src/config_cache.c +24 -7
- data/vendor/libgit2/src/config_file.c +9 -6
- data/vendor/libgit2/src/crlf.c +4 -2
- data/vendor/libgit2/src/date.c +3 -3
- data/vendor/libgit2/src/delta.c +1 -1
- data/vendor/libgit2/src/diff.c +681 -303
- data/vendor/libgit2/src/diff.h +34 -2
- data/vendor/libgit2/src/diff_driver.c +405 -0
- data/vendor/libgit2/src/diff_driver.h +49 -0
- data/vendor/libgit2/src/diff_file.c +447 -0
- data/vendor/libgit2/src/diff_file.h +58 -0
- data/vendor/libgit2/src/diff_patch.c +995 -0
- data/vendor/libgit2/src/diff_patch.h +46 -0
- data/vendor/libgit2/src/diff_print.c +430 -0
- data/vendor/libgit2/src/diff_tform.c +464 -203
- data/vendor/libgit2/src/diff_xdiff.c +166 -0
- data/vendor/libgit2/src/diff_xdiff.h +28 -0
- data/vendor/libgit2/src/fetch.c +11 -4
- data/vendor/libgit2/src/fileops.c +85 -61
- data/vendor/libgit2/src/fileops.h +4 -0
- data/vendor/libgit2/src/global.c +10 -2
- data/vendor/libgit2/src/global.h +0 -8
- data/vendor/libgit2/src/hash/hash_generic.h +3 -3
- data/vendor/libgit2/src/hash/hash_win32.h +4 -4
- data/vendor/libgit2/src/hashsig.c +0 -1
- data/vendor/libgit2/src/ignore.c +68 -28
- data/vendor/libgit2/src/ignore.h +10 -1
- data/vendor/libgit2/src/index.c +666 -84
- data/vendor/libgit2/src/index.h +6 -0
- data/vendor/libgit2/src/indexer.c +10 -28
- data/vendor/libgit2/src/iterator.c +427 -283
- data/vendor/libgit2/src/iterator.h +58 -4
- data/vendor/libgit2/src/merge.c +1892 -32
- data/vendor/libgit2/src/merge.h +132 -5
- data/vendor/libgit2/src/merge_file.c +174 -0
- data/vendor/libgit2/src/merge_file.h +71 -0
- data/vendor/libgit2/src/mwindow.c +1 -1
- data/vendor/libgit2/src/notes.c +45 -48
- data/vendor/libgit2/src/object.c +89 -127
- data/vendor/libgit2/src/object.h +0 -1
- data/vendor/libgit2/src/object_api.c +129 -0
- data/vendor/libgit2/src/odb.c +156 -59
- data/vendor/libgit2/src/odb.h +5 -2
- data/vendor/libgit2/src/odb_loose.c +31 -17
- data/vendor/libgit2/src/odb_pack.c +39 -43
- data/vendor/libgit2/src/oid.c +62 -27
- data/vendor/libgit2/src/oid.h +33 -0
- data/vendor/libgit2/src/oidmap.h +4 -6
- data/vendor/libgit2/src/pack-objects.c +54 -22
- data/vendor/libgit2/src/pack.c +98 -56
- data/vendor/libgit2/src/pack.h +3 -1
- data/vendor/libgit2/src/pathspec.c +26 -1
- data/vendor/libgit2/src/pathspec.h +14 -0
- data/vendor/libgit2/src/pool.c +5 -0
- data/vendor/libgit2/src/posix.c +2 -2
- data/vendor/libgit2/src/posix.h +3 -0
- data/vendor/libgit2/src/push.c +13 -10
- data/vendor/libgit2/src/refdb.c +82 -62
- data/vendor/libgit2/src/refdb.h +16 -16
- data/vendor/libgit2/src/refdb_fs.c +386 -133
- data/vendor/libgit2/src/reflog.c +3 -1
- data/vendor/libgit2/src/refs.c +247 -221
- data/vendor/libgit2/src/refs.h +2 -1
- data/vendor/libgit2/src/refspec.c +18 -1
- data/vendor/libgit2/src/refspec.h +3 -1
- data/vendor/libgit2/src/remote.c +434 -253
- data/vendor/libgit2/src/remote.h +5 -3
- data/vendor/libgit2/src/repository.c +197 -111
- data/vendor/libgit2/src/repository.h +26 -5
- data/vendor/libgit2/src/reset.c +1 -1
- data/vendor/libgit2/src/revparse.c +84 -79
- data/vendor/libgit2/src/revwalk.c +1 -1
- data/vendor/libgit2/src/signature.c +22 -10
- data/vendor/libgit2/src/stash.c +5 -2
- data/vendor/libgit2/src/status.c +311 -107
- data/vendor/libgit2/src/status.h +23 -0
- data/vendor/libgit2/src/submodule.c +21 -13
- data/vendor/libgit2/src/tag.c +42 -31
- data/vendor/libgit2/src/tag.h +2 -3
- data/vendor/libgit2/src/thread-utils.h +105 -3
- data/vendor/libgit2/src/trace.c +1 -2
- data/vendor/libgit2/src/trace.h +3 -3
- data/vendor/libgit2/src/transport.c +18 -6
- data/vendor/libgit2/src/transports/cred.c +103 -1
- data/vendor/libgit2/src/transports/local.c +19 -9
- data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
- data/vendor/libgit2/src/transports/ssh.c +519 -0
- data/vendor/libgit2/src/transports/winhttp.c +3 -1
- data/vendor/libgit2/src/tree.c +26 -28
- data/vendor/libgit2/src/tree.h +3 -3
- data/vendor/libgit2/src/unix/posix.h +2 -0
- data/vendor/libgit2/src/util.c +43 -6
- data/vendor/libgit2/src/util.h +40 -12
- data/vendor/libgit2/src/vector.c +3 -5
- data/vendor/libgit2/src/vector.h +9 -0
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/error.c +2 -0
- data/vendor/libgit2/src/win32/findfile.c +3 -6
- data/vendor/libgit2/src/win32/posix_w32.c +85 -59
- data/vendor/libgit2/src/win32/pthread.c +16 -8
- data/vendor/libgit2/src/win32/pthread.h +7 -4
- metadata +407 -306
- data/test/coverage/HEAD.json +0 -1
- data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
- data/vendor/libgit2/src/diff_output.c +0 -1819
- data/vendor/libgit2/src/diff_output.h +0 -93
data/ext/rugged/rugged_blob.c
CHANGED
@@ -28,31 +28,26 @@
|
|
28
28
|
extern VALUE rb_mRugged;
|
29
29
|
extern VALUE rb_cRuggedObject;
|
30
30
|
extern VALUE rb_cRuggedRepo;
|
31
|
+
static ID id_read;
|
31
32
|
|
32
33
|
VALUE rb_cRuggedBlob;
|
33
34
|
|
34
35
|
/*
|
35
|
-
*
|
36
|
-
*
|
36
|
+
* call-seq:
|
37
|
+
* blob.text(max_lines = -1, encoding = Encoding.default_external) -> string
|
37
38
|
*
|
38
|
-
*
|
39
|
+
* Return up to +max_lines+ of text from a blob as a +String+.
|
40
|
+
* If +max_lines+ is less than 0, the full string is returned.
|
39
41
|
*
|
40
|
-
*
|
41
|
-
*
|
42
|
+
* The string is created with the given +encoding+, defaulting to
|
43
|
+
* Encoding.default_external.
|
42
44
|
*
|
43
|
-
*
|
44
|
-
*
|
45
|
-
*
|
46
|
-
* When limiting the size of the text with +max_lines+, the string is
|
47
|
-
* expected to have an ASCII-compatible encoding, and is checked
|
48
|
-
* for the newline +\n+ character.
|
45
|
+
* When limiting the size of the text with +max_lines+, the string is
|
46
|
+
* expected to have an ASCII-compatible encoding, and is checked
|
47
|
+
* for the newline +\n+ character.
|
49
48
|
*/
|
50
49
|
static VALUE rb_git_blob_text_GET(int argc, VALUE *argv, VALUE self)
|
51
50
|
{
|
52
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
53
|
-
rb_encoding *encoding = rb_default_external_encoding();
|
54
|
-
#endif
|
55
|
-
|
56
51
|
git_blob *blob;
|
57
52
|
size_t size;
|
58
53
|
const char *content;
|
@@ -76,32 +71,27 @@ static VALUE rb_git_blob_text_GET(int argc, VALUE *argv, VALUE self)
|
|
76
71
|
if (content[i++] == '\n')
|
77
72
|
lines++;
|
78
73
|
}
|
74
|
+
size = (size_t)i;
|
79
75
|
}
|
80
76
|
|
81
|
-
size = (size_t)i;
|
82
77
|
}
|
83
78
|
|
84
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
85
79
|
if (!NIL_P(rb_encoding)) {
|
86
|
-
|
80
|
+
return rb_enc_str_new(content, size, rb_to_encoding(rb_encoding));
|
87
81
|
}
|
88
|
-
#endif
|
89
82
|
|
90
|
-
|
91
|
-
return rugged_str_new("", 0, encoding);
|
92
|
-
|
93
|
-
return rugged_str_new(content, size, encoding);
|
83
|
+
return rb_external_str_new(content, size);
|
94
84
|
}
|
95
85
|
|
96
86
|
/*
|
97
|
-
*
|
98
|
-
*
|
87
|
+
* call-seq:
|
88
|
+
* blob.content(max_bytes=-1) -> string
|
99
89
|
*
|
100
|
-
*
|
101
|
-
*
|
90
|
+
* Return up to +max_bytes+ from the contents of a blob as bytes +String+.
|
91
|
+
* If +max_bytes+ is less than 0, the full string is returned.
|
102
92
|
*
|
103
|
-
*
|
104
|
-
*
|
93
|
+
* This string is tagged with the ASCII-8BIT encoding: the bytes are
|
94
|
+
* returned as-is, since Git is encoding agnostic.
|
105
95
|
*/
|
106
96
|
static VALUE rb_git_blob_content_GET(int argc, VALUE *argv, VALUE self)
|
107
97
|
{
|
@@ -126,28 +116,20 @@ static VALUE rb_git_blob_content_GET(int argc, VALUE *argv, VALUE self)
|
|
126
116
|
size = (size_t)maxbytes;
|
127
117
|
}
|
128
118
|
|
129
|
-
if (size == 0)
|
130
|
-
return rugged_str_ascii("", 0);
|
131
|
-
|
132
119
|
/*
|
133
120
|
* since we don't really ever know the encoding of a blob
|
134
121
|
* lets default to the binary encoding (ascii-8bit)
|
135
|
-
* If there is a way to tell, we should just pass 0/null here instead
|
136
|
-
*
|
137
|
-
* we're skipping the use of STR_NEW because we don't want our string to
|
138
|
-
* eventually end up converted to Encoding.default_internal because this
|
139
|
-
* string could very well be binary data
|
140
122
|
*/
|
141
|
-
return
|
123
|
+
return rb_str_new(content, size);
|
142
124
|
}
|
143
125
|
|
144
126
|
/*
|
145
|
-
*
|
146
|
-
*
|
127
|
+
* call-seq:
|
128
|
+
* blob.rawsize -> int
|
147
129
|
*
|
148
|
-
*
|
149
|
-
*
|
150
|
-
*
|
130
|
+
* Return the size in bytes of the blob. This is the real,
|
131
|
+
* uncompressed size and the length of +blob.content+, not
|
132
|
+
* the compressed size.
|
151
133
|
*/
|
152
134
|
static VALUE rb_git_blob_rawsize(VALUE self)
|
153
135
|
{
|
@@ -158,14 +140,14 @@ static VALUE rb_git_blob_rawsize(VALUE self)
|
|
158
140
|
}
|
159
141
|
|
160
142
|
/*
|
161
|
-
*
|
162
|
-
*
|
143
|
+
* call-seq:
|
144
|
+
* Blob.from_buffer(repository, bytes) -> oid
|
163
145
|
*
|
164
|
-
*
|
165
|
-
*
|
166
|
-
*
|
146
|
+
* Write a blob to +repository+ with the contents specified
|
147
|
+
* in +buffer+. In Ruby 1.9.x, the encoding of +buffer+ is
|
148
|
+
* ignored and bytes are copied as-is.
|
167
149
|
*/
|
168
|
-
static VALUE
|
150
|
+
static VALUE rb_git_blob_from_buffer(VALUE self, VALUE rb_repo, VALUE rb_buffer)
|
169
151
|
{
|
170
152
|
int error;
|
171
153
|
git_oid oid;
|
@@ -183,13 +165,14 @@ static VALUE rb_git_blob_create(VALUE self, VALUE rb_repo, VALUE rb_buffer)
|
|
183
165
|
}
|
184
166
|
|
185
167
|
/*
|
186
|
-
*
|
187
|
-
*
|
168
|
+
* call-seq:
|
169
|
+
* Blob.from_workdir(repository, file_path) -> oid
|
188
170
|
*
|
189
|
-
*
|
190
|
-
*
|
171
|
+
* Write the file specified in +file_path+ to a blob in +repository+.
|
172
|
+
* +file_path+ must be relative to the repository's working folder.
|
173
|
+
* The repository cannot be bare.
|
191
174
|
*
|
192
|
-
*
|
175
|
+
* Blob.from_workdir(repo, 'src/blob.h') #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
|
193
176
|
*/
|
194
177
|
static VALUE rb_git_blob_from_workdir(VALUE self, VALUE rb_repo, VALUE rb_path)
|
195
178
|
{
|
@@ -209,11 +192,127 @@ static VALUE rb_git_blob_from_workdir(VALUE self, VALUE rb_repo, VALUE rb_path)
|
|
209
192
|
}
|
210
193
|
|
211
194
|
/*
|
212
|
-
*
|
213
|
-
*
|
195
|
+
* call-seq:
|
196
|
+
* Blob.from_disk(repository, file_path) -> oid
|
197
|
+
*
|
198
|
+
* Write the file specified in +file_path+ to a blob in +repository+.
|
199
|
+
* The repository can be bare or not.
|
200
|
+
*
|
201
|
+
* Example:
|
202
|
+
*
|
203
|
+
* Blob.from_disk(repo, '/var/repos/blob.h') #=> '5b5b025afb0b4c913b4c338a42934a3863bf3643'
|
204
|
+
*/
|
205
|
+
static VALUE rb_git_blob_from_disk(VALUE self, VALUE rb_repo, VALUE rb_path)
|
206
|
+
{
|
207
|
+
int error;
|
208
|
+
git_oid oid;
|
209
|
+
git_repository *repo;
|
210
|
+
|
211
|
+
Check_Type(rb_path, T_STRING);
|
212
|
+
rugged_check_repo(rb_repo);
|
213
|
+
|
214
|
+
Data_Get_Struct(rb_repo, git_repository, repo);
|
215
|
+
|
216
|
+
error = git_blob_create_fromdisk(&oid, repo, StringValueCStr(rb_path));
|
217
|
+
rugged_exception_check(error);
|
218
|
+
|
219
|
+
return rugged_create_oid(&oid);
|
220
|
+
}
|
221
|
+
|
222
|
+
static VALUE rb_read_check(VALUE *args) {
|
223
|
+
return rb_funcall(args[0], id_read, 1, args[1]);
|
224
|
+
}
|
225
|
+
|
226
|
+
static VALUE rb_read_failed(void) {
|
227
|
+
return Qnil;
|
228
|
+
}
|
229
|
+
|
230
|
+
static int cb_blob__get__chunk(char *content, size_t max_length, void *rb_io)
|
231
|
+
{
|
232
|
+
VALUE rb_buffer, args[2];
|
233
|
+
size_t str_len, safe_len;
|
234
|
+
|
235
|
+
args[0] = (VALUE)rb_io;
|
236
|
+
args[1] = INT2FIX(max_length);
|
237
|
+
|
238
|
+
rb_buffer = rb_rescue(rb_read_check, (VALUE)args, rb_read_failed, 0);
|
239
|
+
|
240
|
+
if (NIL_P(rb_buffer) || TYPE(rb_buffer) != T_STRING )
|
241
|
+
return 0;
|
242
|
+
|
243
|
+
str_len = (size_t)RSTRING_LEN(rb_buffer);
|
244
|
+
safe_len = str_len > max_length ? max_length : str_len;
|
245
|
+
memcpy(content, StringValuePtr(rb_buffer), safe_len);
|
246
|
+
|
247
|
+
return (int)safe_len;
|
248
|
+
}
|
249
|
+
|
250
|
+
/*
|
251
|
+
* call-seq:
|
252
|
+
* Blob.from_chunks(repository, io [, hint_path]) -> oid
|
253
|
+
*
|
254
|
+
* Write a loose blob to the +repository+ from a provider
|
255
|
+
* of chunks of data.
|
256
|
+
*
|
257
|
+
* The repository can be bare or not.
|
258
|
+
*
|
259
|
+
* The data provider +io+ should respond to a <code>read(size)</code>
|
260
|
+
* method. Generally any instance of a class based on Ruby's +IO+ class
|
261
|
+
* should work(ex. +File+). On each +read+ call it should
|
262
|
+
* return a +String+ with maximum size of +size+.
|
263
|
+
*
|
264
|
+
* *NOTE:* If an exception is raised in the +io+ object's
|
265
|
+
* +read+ method, a blob will be created with the data up to that point
|
266
|
+
* and the exception will be rescued.
|
267
|
+
* It's recommended to compare the +blob.size+ with the expected data size
|
268
|
+
* to check if all the data was written.
|
269
|
+
*
|
270
|
+
* Provided the +hint_path+ parameter is given, its value
|
271
|
+
* will help to determine what git filters should be applied
|
272
|
+
* to the object before it can be placed to the object database.
|
273
|
+
*
|
274
|
+
* File.open('/path/to/file') do |file|
|
275
|
+
* Blob.from_chunks(repo, file, 'hint/blob.h') #=> '42cab3c0cde61e2b5a2392e1eadbeffa20ffa171'
|
276
|
+
* end
|
277
|
+
*/
|
278
|
+
static VALUE rb_git_blob_from_chunks(int argc, VALUE *argv, VALUE klass)
|
279
|
+
{
|
280
|
+
VALUE rb_repo, rb_io, rb_hint_path;
|
281
|
+
const char * hint_path = NULL;
|
282
|
+
|
283
|
+
int error;
|
284
|
+
git_oid oid;
|
285
|
+
git_repository *repo;
|
286
|
+
|
287
|
+
rb_scan_args(argc, argv, "21", &rb_repo, &rb_io, &rb_hint_path);
|
288
|
+
|
289
|
+
rugged_check_repo(rb_repo);
|
290
|
+
Data_Get_Struct(rb_repo, git_repository, repo);
|
291
|
+
|
292
|
+
if (!NIL_P(rb_hint_path)) {
|
293
|
+
Check_Type(rb_hint_path, T_STRING);
|
294
|
+
hint_path = StringValueCStr(rb_hint_path);
|
295
|
+
}
|
296
|
+
|
297
|
+
error = git_blob_create_fromchunks(
|
298
|
+
&oid,
|
299
|
+
repo,
|
300
|
+
hint_path,
|
301
|
+
cb_blob__get__chunk,
|
302
|
+
(void *)rb_io);
|
303
|
+
|
304
|
+
rugged_exception_check(error);
|
305
|
+
|
306
|
+
return rugged_create_oid(&oid);
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
/*
|
311
|
+
* call-seq:
|
312
|
+
* blob.sloc -> int
|
214
313
|
*
|
215
|
-
*
|
216
|
-
*
|
314
|
+
* Return the number of non-empty code lines for the blob,
|
315
|
+
* assuming the blob is plaintext (i.e. not binary)
|
217
316
|
*/
|
218
317
|
static VALUE rb_git_blob_sloc(VALUE self)
|
219
318
|
{
|
@@ -247,15 +346,144 @@ static VALUE rb_git_blob_sloc(VALUE self)
|
|
247
346
|
return INT2FIX(sloc);
|
248
347
|
}
|
249
348
|
|
250
|
-
|
349
|
+
/*
|
350
|
+
* call-seq:
|
351
|
+
* blob.binary? -> true or false
|
352
|
+
*
|
353
|
+
* Determine if the blob content is most certainly binary or not.
|
354
|
+
*
|
355
|
+
* The heuristic used to guess if a file is binary is taken from core git:
|
356
|
+
* Searching for NUL bytes and looking for a reasonable ratio of printable
|
357
|
+
* to non-printable characters among the first 4000 bytes.
|
358
|
+
*
|
359
|
+
*/
|
360
|
+
static VALUE rb_git_blob_is_binary(VALUE self)
|
251
361
|
{
|
362
|
+
git_blob *blob;
|
363
|
+
Data_Get_Struct(self, git_blob, blob);
|
364
|
+
return git_blob_is_binary(blob) ? Qtrue : Qfalse;
|
365
|
+
}
|
366
|
+
|
367
|
+
/*
|
368
|
+
* call-seq:
|
369
|
+
* blob.diff(other, options = {}) -> patch
|
370
|
+
*
|
371
|
+
* Directly generate a Rugged::Patch from the difference between +blob+ and +other+.
|
372
|
+
*
|
373
|
+
* +other+ can either be another Rugged::Blob instance, a string,
|
374
|
+
* or nil (treated as an empty blob).
|
375
|
+
*
|
376
|
+
* The following options can be passed in the +options+ Hash:
|
377
|
+
*
|
378
|
+
* :max_size ::
|
379
|
+
* An integer specifying the maximum byte size of a blob before a it will
|
380
|
+
* be treated as binary. The default value is 512MB.
|
381
|
+
*
|
382
|
+
* :context_lines ::
|
383
|
+
* The number of unchanged lines that define the boundary of a hunk (and
|
384
|
+
* to display before and after the actual changes). The default is 3.
|
385
|
+
*
|
386
|
+
* :interhunk_lines ::
|
387
|
+
* The maximum number of unchanged lines between hunk boundaries before the hunks
|
388
|
+
* will be merged into a one. The default is 0.
|
389
|
+
*
|
390
|
+
* :reverse ::
|
391
|
+
* If true, the sides of the diff will be reversed.
|
392
|
+
*
|
393
|
+
* :force_text ::
|
394
|
+
* If true, all files will be treated as text, disabling binary attributes & detection.
|
395
|
+
*
|
396
|
+
* :ignore_whitespace ::
|
397
|
+
* If true, all whitespace will be ignored.
|
398
|
+
*
|
399
|
+
* :ignore_whitespace_change ::
|
400
|
+
* If true, changes in amount of whitespace will be ignored.
|
401
|
+
*
|
402
|
+
* :ignore_whitespace_eol ::
|
403
|
+
* If true, whitespace at end of line will be ignored.
|
404
|
+
*
|
405
|
+
* :patience ::
|
406
|
+
* If true, the "patience diff" algorithm will be used (currently unimplemented).
|
407
|
+
*
|
408
|
+
* :skip_binary_check ::
|
409
|
+
* If true, diff deltas will be generated without spending time on binary
|
410
|
+
* detection. This is useful to improve performance in cases where the actual
|
411
|
+
* file content difference is not needed.
|
412
|
+
*
|
413
|
+
* :old_path ::
|
414
|
+
* An optional string to treat +blob+ as if it had this filename.
|
415
|
+
*
|
416
|
+
* :new_path ::
|
417
|
+
* An optional string to treat +other+ as if it had this filename.
|
418
|
+
*/
|
419
|
+
static VALUE rb_git_blob_diff(int argc, VALUE *argv, VALUE self)
|
420
|
+
{
|
421
|
+
git_blob *blob;
|
422
|
+
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
|
423
|
+
git_diff_patch *patch;
|
424
|
+
const char *old_path = NULL, *new_path = NULL;
|
425
|
+
VALUE rb_other, rb_options;
|
426
|
+
int error;
|
427
|
+
|
428
|
+
rb_scan_args(argc, argv, "10:", &rb_other, &rb_options);
|
429
|
+
if (!NIL_P(rb_options)) {
|
430
|
+
VALUE rb_value;
|
431
|
+
|
432
|
+
rb_value = rb_hash_aref(rb_options, CSTR2SYM("old_path"));
|
433
|
+
if (!NIL_P(rb_value)) {
|
434
|
+
Check_Type(rb_value, T_STRING);
|
435
|
+
old_path = StringValueCStr(rb_value);
|
436
|
+
}
|
437
|
+
|
438
|
+
rb_value = rb_hash_aref(rb_options, CSTR2SYM("new_path"));
|
439
|
+
if (!NIL_P(rb_value)) {
|
440
|
+
Check_Type(rb_value, T_STRING);
|
441
|
+
new_path = StringValueCStr(rb_value);
|
442
|
+
}
|
443
|
+
|
444
|
+
rugged_parse_diff_options(&opts, rb_options);
|
445
|
+
}
|
446
|
+
|
447
|
+
Data_Get_Struct(self, git_blob, blob);
|
448
|
+
|
449
|
+
if (NIL_P(rb_other)) {
|
450
|
+
error = git_diff_patch_from_blobs(&patch, blob, old_path, NULL, new_path, &opts);
|
451
|
+
} else if (rb_obj_is_kind_of(rb_other, rb_cRuggedBlob)) {
|
452
|
+
git_blob *other_blob;
|
453
|
+
|
454
|
+
Data_Get_Struct(rb_other, git_blob, other_blob);
|
455
|
+
|
456
|
+
error = git_diff_patch_from_blobs(&patch, blob, old_path, other_blob, new_path, &opts);
|
457
|
+
} else if (TYPE(rb_other) == T_STRING) {
|
458
|
+
const char * buffer = StringValueCStr(rb_other);
|
459
|
+
|
460
|
+
error = git_diff_patch_from_blob_and_buffer(&patch, blob, old_path, buffer, RSTRING_LEN(rb_other), new_path, &opts);
|
461
|
+
} else {
|
462
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Rugged::Blob, String, or nil)",
|
463
|
+
rb_obj_classname(rb_other));
|
464
|
+
}
|
465
|
+
|
466
|
+
rugged_exception_check(error);
|
467
|
+
|
468
|
+
return rugged_diff_patch_new(self, patch);
|
469
|
+
}
|
470
|
+
|
471
|
+
void Init_rugged_blob(void)
|
472
|
+
{
|
473
|
+
id_read = rb_intern("read");
|
474
|
+
|
252
475
|
rb_cRuggedBlob = rb_define_class_under(rb_mRugged, "Blob", rb_cRuggedObject);
|
253
476
|
|
254
477
|
rb_define_method(rb_cRuggedBlob, "size", rb_git_blob_rawsize, 0);
|
255
478
|
rb_define_method(rb_cRuggedBlob, "content", rb_git_blob_content_GET, -1);
|
256
479
|
rb_define_method(rb_cRuggedBlob, "text", rb_git_blob_text_GET, -1);
|
257
480
|
rb_define_method(rb_cRuggedBlob, "sloc", rb_git_blob_sloc, 0);
|
481
|
+
rb_define_method(rb_cRuggedBlob, "binary?", rb_git_blob_is_binary, 0);
|
482
|
+
rb_define_method(rb_cRuggedBlob, "diff", rb_git_blob_diff, -1);
|
258
483
|
|
259
|
-
rb_define_singleton_method(rb_cRuggedBlob, "
|
484
|
+
rb_define_singleton_method(rb_cRuggedBlob, "from_buffer", rb_git_blob_from_buffer, 2);
|
260
485
|
rb_define_singleton_method(rb_cRuggedBlob, "from_workdir", rb_git_blob_from_workdir, 2);
|
486
|
+
rb_define_singleton_method(rb_cRuggedBlob, "from_disk", rb_git_blob_from_disk, 2);
|
487
|
+
rb_define_singleton_method(rb_cRuggedBlob, "from_chunks", rb_git_blob_from_chunks, -1);
|
488
|
+
|
261
489
|
}
|
data/ext/rugged/rugged_branch.c
CHANGED
@@ -53,20 +53,20 @@ static int parse_branch_type(VALUE rb_filter)
|
|
53
53
|
}
|
54
54
|
|
55
55
|
/*
|
56
|
-
*
|
57
|
-
*
|
56
|
+
* call-seq:
|
57
|
+
* Branch.create(repository, name, target, force = false) -> branch
|
58
58
|
*
|
59
|
-
*
|
60
|
-
*
|
59
|
+
* Create a new branch in +repository+, with the given +name+, and pointing
|
60
|
+
* to the +target+.
|
61
61
|
*
|
62
|
-
*
|
63
|
-
*
|
62
|
+
* +name+ needs to be a branch name, not an absolute reference path
|
63
|
+
* (e.g. +development+ instead of +/refs/heads/development+).
|
64
64
|
*
|
65
|
-
*
|
65
|
+
* +target+ needs to be an existing commit in the given +repository+.
|
66
66
|
*
|
67
|
-
*
|
67
|
+
* If +force+ is +true+, any existing branches will be overwritten.
|
68
68
|
*
|
69
|
-
*
|
69
|
+
* Returns a Rugged::Branch object with the newly created branch.
|
70
70
|
*/
|
71
71
|
static VALUE rb_git_branch_create(int argc, VALUE *argv, VALUE self)
|
72
72
|
{
|
@@ -102,18 +102,18 @@ static VALUE rb_git_branch_create(int argc, VALUE *argv, VALUE self)
|
|
102
102
|
}
|
103
103
|
|
104
104
|
/*
|
105
|
-
*
|
106
|
-
*
|
105
|
+
* call-seq:
|
106
|
+
* Branch.lookup(repository, name, branch_type = :local) -> branch
|
107
107
|
*
|
108
|
-
*
|
108
|
+
* Lookup a branch in +repository+, with the given +name+.
|
109
109
|
*
|
110
|
-
*
|
111
|
-
*
|
110
|
+
* +name+ needs to be a branch name, not an absolute reference path
|
111
|
+
* (e.g. +development+ instead of +/refs/heads/development+).
|
112
112
|
*
|
113
|
-
*
|
114
|
-
*
|
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
115
|
*
|
116
|
-
*
|
116
|
+
* Returns the looked up branch, or +nil+ if the branch doesn't exist.
|
117
117
|
*/
|
118
118
|
static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
|
119
119
|
{
|
@@ -133,7 +133,7 @@ static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
|
|
133
133
|
Data_Get_Struct(rb_repo, git_repository, repo);
|
134
134
|
|
135
135
|
Check_Type(rb_name, T_STRING);
|
136
|
-
|
136
|
+
|
137
137
|
if (!NIL_P(rb_type))
|
138
138
|
branch_type = parse_branch_type(rb_type);
|
139
139
|
|
@@ -146,11 +146,11 @@ static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
|
|
146
146
|
}
|
147
147
|
|
148
148
|
/*
|
149
|
-
*
|
150
|
-
*
|
149
|
+
* call-seq:
|
150
|
+
* branch.delete! -> nil
|
151
151
|
*
|
152
|
-
*
|
153
|
-
*
|
152
|
+
* Remove a branch from the repository. The branch object will become invalidated
|
153
|
+
* and won't be able to be used for any other operations.
|
154
154
|
*/
|
155
155
|
static VALUE rb_git_branch_delete(VALUE self)
|
156
156
|
{
|
@@ -165,27 +165,29 @@ static VALUE rb_git_branch_delete(VALUE self)
|
|
165
165
|
return Qnil;
|
166
166
|
}
|
167
167
|
|
168
|
-
static int cb_branch__each_name(const char *branch_name, git_branch_t branch_type, void *
|
168
|
+
static int cb_branch__each_name(const char *branch_name, git_branch_t branch_type, void *data)
|
169
169
|
{
|
170
|
-
|
171
|
-
|
170
|
+
struct rugged_cb_payload *payload = data;
|
171
|
+
|
172
|
+
rb_protect(rb_yield, rb_str_new_utf8(branch_name), &payload->exception);
|
173
|
+
|
174
|
+
return payload->exception ? GIT_ERROR : GIT_OK;
|
172
175
|
}
|
173
176
|
|
174
|
-
static int cb_branch__each_obj(const char *branch_name, git_branch_t branch_type, void *
|
177
|
+
static int cb_branch__each_obj(const char *branch_name, git_branch_t branch_type, void *data)
|
175
178
|
{
|
176
|
-
VALUE rb_repo = (VALUE)payload;
|
177
|
-
|
178
179
|
git_reference *branch;
|
179
180
|
git_repository *repo;
|
181
|
+
struct rugged_cb_payload *payload = data;
|
180
182
|
|
181
|
-
Data_Get_Struct(
|
183
|
+
Data_Get_Struct(payload->rb_data, git_repository, repo);
|
182
184
|
|
183
185
|
rugged_exception_check(
|
184
186
|
git_branch_lookup(&branch, repo, branch_name, branch_type)
|
185
187
|
);
|
186
188
|
|
187
|
-
rb_yield
|
188
|
-
return
|
189
|
+
rb_protect(rb_yield, rugged_branch_new(payload->rb_data, branch), &payload->exception);
|
190
|
+
return payload->exception ? GIT_ERROR : GIT_OK;
|
189
191
|
}
|
190
192
|
|
191
193
|
static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_only)
|
@@ -193,10 +195,14 @@ static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_onl
|
|
193
195
|
VALUE rb_repo, rb_filter;
|
194
196
|
git_repository *repo;
|
195
197
|
int error;
|
198
|
+
struct rugged_cb_payload payload;
|
196
199
|
int filter = (GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE);
|
197
200
|
|
198
201
|
rb_scan_args(argc, argv, "11", &rb_repo, &rb_filter);
|
199
202
|
|
203
|
+
payload.exception = 0;
|
204
|
+
payload.rb_data = rb_repo;
|
205
|
+
|
200
206
|
if (!rb_block_given_p()) {
|
201
207
|
VALUE symbol = branch_names_only ? CSTR2SYM("each_name") : CSTR2SYM("each");
|
202
208
|
return rb_funcall(self, rb_intern("to_enum"), 3, symbol, rb_repo, rb_filter);
|
@@ -212,25 +218,28 @@ static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_onl
|
|
212
218
|
Data_Get_Struct(rb_repo, git_repository, repo);
|
213
219
|
|
214
220
|
if (branch_names_only) {
|
215
|
-
error = git_branch_foreach(repo, filter, &cb_branch__each_name,
|
221
|
+
error = git_branch_foreach(repo, filter, &cb_branch__each_name, &payload);
|
216
222
|
} else {
|
217
|
-
error = git_branch_foreach(repo, filter, &cb_branch__each_obj,
|
223
|
+
error = git_branch_foreach(repo, filter, &cb_branch__each_obj, &payload);
|
218
224
|
}
|
219
225
|
|
226
|
+
if (payload.exception)
|
227
|
+
rb_jump_tag(payload.exception);
|
220
228
|
rugged_exception_check(error);
|
229
|
+
|
221
230
|
return Qnil;
|
222
231
|
}
|
223
232
|
|
224
233
|
/*
|
225
|
-
*
|
226
|
-
*
|
227
|
-
*
|
234
|
+
* call-seq:
|
235
|
+
* Branch.each_name(repository, filter = :all) { |branch_name| block }
|
236
|
+
* Branch.each_name(repository, filter = :all) -> enumerator
|
228
237
|
*
|
229
|
-
*
|
230
|
-
*
|
238
|
+
* Iterate through the names of the branches in +repository+. Iteration can be
|
239
|
+
* optionally filtered to yield only +:local+ or +:remote+ branches.
|
231
240
|
*
|
232
|
-
*
|
233
|
-
*
|
241
|
+
* The given block will be called once with the name of each branch as a +String+.
|
242
|
+
* If no block is given, an enumerator will be returned.
|
234
243
|
*/
|
235
244
|
static VALUE rb_git_branch_each_name(int argc, VALUE *argv, VALUE self)
|
236
245
|
{
|
@@ -239,16 +248,16 @@ static VALUE rb_git_branch_each_name(int argc, VALUE *argv, VALUE self)
|
|
239
248
|
|
240
249
|
|
241
250
|
/*
|
242
|
-
*
|
243
|
-
*
|
244
|
-
*
|
251
|
+
* call-seq:
|
252
|
+
* Branch.each(repository, filter = :all) { |branch| block }
|
253
|
+
* Branch.each(repository, filter = :all) -> enumerator
|
245
254
|
*
|
246
|
-
*
|
247
|
-
*
|
255
|
+
* Iterate through the branches in +repository+. Iteration can be
|
256
|
+
* optionally filtered to yield only +:local+ or +:remote+ branches.
|
248
257
|
*
|
249
|
-
*
|
250
|
-
*
|
251
|
-
*
|
258
|
+
* The given block will be called once with a +Rugged::Branch+ object
|
259
|
+
* for each branch in the repository. If no block is given, an enumerator
|
260
|
+
* will be returned.
|
252
261
|
*/
|
253
262
|
static VALUE rb_git_branch_each(int argc, VALUE *argv, VALUE self)
|
254
263
|
{
|
@@ -256,17 +265,19 @@ static VALUE rb_git_branch_each(int argc, VALUE *argv, VALUE self)
|
|
256
265
|
}
|
257
266
|
|
258
267
|
/*
|
259
|
-
*
|
260
|
-
*
|
261
|
-
*
|
268
|
+
* call-seq:
|
269
|
+
* branch.move(new_name, force = false) -> new_branch
|
270
|
+
* branch.rename(new_name, force = false) -> new_branch
|
271
|
+
*
|
272
|
+
* Rename a branch to +new_name+.
|
262
273
|
*
|
263
|
-
*
|
274
|
+
* +new_name+ needs to be a branch name, not an absolute reference path
|
275
|
+
* (e.g. +development+ instead of +/refs/heads/development+).
|
264
276
|
*
|
265
|
-
*
|
266
|
-
*
|
277
|
+
* If +force+ is +true+, the branch will be renamed even if a branch
|
278
|
+
* with +new_name+ already exists.
|
267
279
|
*
|
268
|
-
*
|
269
|
-
* with +new_name+ already exists.
|
280
|
+
* A new Rugged::Branch object for the renamed branch will be returned.
|
270
281
|
*/
|
271
282
|
static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
|
272
283
|
{
|
@@ -288,7 +299,20 @@ static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
|
|
288
299
|
return rugged_branch_new(rugged_owner(self), new_branch);
|
289
300
|
}
|
290
301
|
|
291
|
-
|
302
|
+
/*
|
303
|
+
* call-seq:
|
304
|
+
* branch.head? -> true or false
|
305
|
+
*
|
306
|
+
* Returns +true+ if the branch is pointed at by +HEAD+, +false+ otherwise.
|
307
|
+
*/
|
308
|
+
static VALUE rb_git_branch_head_p(VALUE self)
|
309
|
+
{
|
310
|
+
git_reference *branch;
|
311
|
+
Data_Get_Struct(self, git_reference, branch);
|
312
|
+
return git_branch_is_head(branch) ? Qtrue : Qfalse;
|
313
|
+
}
|
314
|
+
|
315
|
+
void Init_rugged_branch(void)
|
292
316
|
{
|
293
317
|
rb_cRuggedBranch = rb_define_class_under(rb_mRugged, "Branch", rb_cRuggedReference);
|
294
318
|
|
@@ -300,4 +324,5 @@ void Init_rugged_branch()
|
|
300
324
|
rb_define_method(rb_cRuggedBranch, "delete!", rb_git_branch_delete, 0);
|
301
325
|
rb_define_method(rb_cRuggedBranch, "rename", rb_git_branch_move, -1);
|
302
326
|
rb_define_method(rb_cRuggedBranch, "move", rb_git_branch_move, -1);
|
327
|
+
rb_define_method(rb_cRuggedBranch, "head?", rb_git_branch_head_p, 0);
|
303
328
|
}
|