rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f476d2b5aaa786237a1a2e6c02ad6817395753a
4
- data.tar.gz: bf560fd348d673a1ecf2082347cdcab68bc85141
3
+ metadata.gz: 0aa39e21ccc3e603f31e60c998ccc0c71980ba60
4
+ data.tar.gz: fff10f16bf3d155d9851ea92cbfa49b2f30e8dda
5
5
  SHA512:
6
- metadata.gz: a47343b080593b0e668fdb259baafb7cd6f0a26dd7813476bafa83e60ded6e9218c417f4591b266825369ad8b600e3bd0e4016f2efa1c536501f39c64160256f
7
- data.tar.gz: eec3ac2c4f8d77755e44c8f6d5e4358dbfa650905b6d6dfa8ecc2b404ffc466b4f1d34cfa8ea6879f9081a13d4a21cbf49c87ebb1826c2377c7a5094a3758d85
6
+ metadata.gz: 0e4bb2074cfea2e6cef066c7bc23b28c07d2dee537ebae03697328bde5dfa8ed012b8c4bab5ad3f52ad2a43781e9230937c9778f40e32a55baf5fd125fc8eede
7
+ data.tar.gz: cb09bd34a103015ad61d197989e31c7fa28df5e1199c10bf5b41e423a224d11b2b9f5e6063c07380d6617c1655ef266d3a8a3c4fbca8567ab0cc168b876f3a42
data/README.md CHANGED
@@ -17,7 +17,12 @@ Rugged is a self-contained gem. You can install it by running:
17
17
 
18
18
  $ gem install rugged
19
19
 
20
- You need to have CMake installed on your system to be able to build the included version of `libgit2`. If you want to build Rugged with HTTPS and SSH support, check out the list of optional [libgit2 dependencies](https://github.com/libgit2/libgit2#optional-dependencies).
20
+ You need to have CMake and `pkg-config` installed on your system to be able to build the included version of `libgit2`. On OS X, after installing [Homebrew](http://brew.sh/), you can get CMake with:
21
+ ```bash
22
+ $ brew install cmake
23
+ ```
24
+
25
+ If you want to build Rugged with HTTPS and SSH support, check out the list of optional [libgit2 dependencies](https://github.com/libgit2/libgit2#optional-dependencies).
21
26
 
22
27
  If you're using bundler and want to bundle `libgit2` with Rugged, you can use the `:submodules` option:
23
28
 
@@ -96,7 +101,7 @@ repo.bare?
96
101
  # => false
97
102
  repo.empty?
98
103
  # => true
99
- repo.head_orphan?
104
+ repo.head_unborn?
100
105
  # => false
101
106
  repo.head_detached?
102
107
  # => false
@@ -109,13 +114,15 @@ repo.workdir
109
114
 
110
115
  # The HEAD of the repository.
111
116
  ref = repo.head
112
- # => #<Rugged::Reference:2228467240 {name: "refs/heads/master", target: "07b44cbda23b726e5d54e2ef383495922c024202"}>
117
+ # => #<Rugged::Reference:2228467240 {name: "refs/heads/master", target: #<Rugged::Commit:2228467250 {message: "helpful message", tree: #<Rugged::Tree:2228467260 {oid: 5d6f29220a0783b8085134df14ec4d960b6c3bf2}>}>
113
118
 
114
- # From the returned ref, you can also access the `name` and `target`:
119
+ # From the returned ref, you can also access the `name`, `target`, and target SHA:
115
120
  ref.name
116
121
  # => "refs/heads/master"
117
122
  ref.target
118
- # => "07b44cbda23b726e5d54e2ef383495922c024202"
123
+ # => #<Rugged::Commit:2228467250 {message: "helpful message", tree: #<Rugged::Tree:2228467260 {oid: 5d6f29220a0783b8085134df14ec4d960b6c3bf2}>}>
124
+ ref.target_id
125
+ # => "2bc6a70483369f33f641ca44873497f13a15cde5"
119
126
 
120
127
  # Reading an object
121
128
  object = repo.read('a0ae5566e3c8a3bddffab21022056f0b5e03ef07')
@@ -15,18 +15,10 @@ def sys(cmd)
15
15
  ret
16
16
  end
17
17
 
18
- if !find_executable('cmake')
19
- abort "ERROR: CMake is required to build Rugged."
20
- end
21
-
22
18
  if !(MAKE = find_executable('gmake') || find_executable('make'))
23
19
  abort "ERROR: GNU make is required to build Rugged."
24
20
  end
25
21
 
26
- if !find_executable('pkg-config')
27
- abort "ERROR: pkg-config is required to build Rugged."
28
- end
29
-
30
22
  if arg_config("--use-system-libraries", !!ENV['RUGGED_USE_SYSTEM_LIBRARIES'])
31
23
  puts "Building Rugged using system libraries.\n"
32
24
 
@@ -40,6 +32,14 @@ if arg_config("--use-system-libraries", !!ENV['RUGGED_USE_SYSTEM_LIBRARIES'])
40
32
  #endif
41
33
  SRC
42
34
  else
35
+ if !find_executable('cmake')
36
+ abort "ERROR: CMake is required to build Rugged."
37
+ end
38
+
39
+ if !find_executable('pkg-config')
40
+ abort "ERROR: pkg-config is required to build Rugged."
41
+ end
42
+
43
43
  CWD = File.expand_path(File.dirname(__FILE__))
44
44
  LIBGIT2_DIR = File.join(CWD, '..', '..', 'vendor', 'libgit2')
45
45
 
@@ -47,7 +47,7 @@ else
47
47
  Dir.mkdir("build") if !Dir.exists?("build")
48
48
 
49
49
  Dir.chdir("build") do
50
- sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo")
50
+ sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"")
51
51
  sys(MAKE)
52
52
 
53
53
  pcfile = File.join(LIBGIT2_DIR, "build", "libgit2.pc")
data/ext/rugged/rugged.c CHANGED
@@ -299,7 +299,7 @@ static VALUE rb_git_minimize_oid(int argc, VALUE *argv, VALUE self)
299
299
  static void cleanup_cb(void *unused)
300
300
  {
301
301
  (void)unused;
302
- git_threads_shutdown();
302
+ git_libgit2_shutdown();
303
303
  }
304
304
 
305
305
  void rugged_exception_raise(void)
@@ -446,6 +446,8 @@ void Init_rugged(void)
446
446
  Init_rugged_remote_collection();
447
447
  Init_rugged_notes();
448
448
  Init_rugged_settings();
449
+ Init_rugged_submodule();
450
+ Init_rugged_submodule_collection();
449
451
  Init_rugged_diff();
450
452
  Init_rugged_patch();
451
453
  Init_rugged_diff_delta();
@@ -484,7 +486,7 @@ void Init_rugged(void)
484
486
  rb_define_const(rb_mRugged, "SORT_REVERSE", INT2FIX(GIT_SORT_REVERSE));
485
487
 
486
488
  /* Initialize libgit2 */
487
- git_threads_init();
489
+ git_libgit2_init();
488
490
 
489
491
  /* Hook a global object to cleanup the library
490
492
  * on shutdown */
data/ext/rugged/rugged.h CHANGED
@@ -65,6 +65,8 @@ void Init_rugged_remote(void);
65
65
  void Init_rugged_remote_collection(void);
66
66
  void Init_rugged_notes(void);
67
67
  void Init_rugged_settings(void);
68
+ void Init_rugged_submodule(void);
69
+ void Init_rugged_submodule_collection(void);
68
70
  void Init_rugged_diff(void);
69
71
  void Init_rugged_patch(void);
70
72
  void Init_rugged_diff_delta(void);
@@ -79,6 +81,7 @@ VALUE rugged_raw_read(git_repository *repo, const git_oid *oid);
79
81
 
80
82
  VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);
81
83
 
84
+ VALUE rugged_repo_new(VALUE klass, git_repository *repo);
82
85
  VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
83
86
  VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
84
87
  VALUE rugged_object_new(VALUE owner, git_object *object);
@@ -117,13 +120,6 @@ static inline VALUE rugged_owner(VALUE object)
117
120
  return rb_iv_get(object, "@owner");
118
121
  }
119
122
 
120
- static inline void rugged_validate_remote_url(VALUE rb_url)
121
- {
122
- Check_Type(rb_url, T_STRING);
123
- if (!git_remote_valid_url(StringValueCStr(rb_url)))
124
- rb_raise(rb_eArgError, "Invalid URL format");
125
- }
126
-
127
123
  extern void rugged_exception_raise(void);
128
124
 
129
125
  static inline void rugged_exception_check(int errorcode)
@@ -24,6 +24,7 @@
24
24
 
25
25
  #include "rugged.h"
26
26
  #include <ctype.h>
27
+ #include <git2/sys/hashsig.h>
27
28
 
28
29
  extern VALUE rb_mRugged;
29
30
  extern VALUE rb_cRuggedObject;
@@ -31,6 +32,7 @@ extern VALUE rb_cRuggedRepo;
31
32
  static ID id_read;
32
33
 
33
34
  VALUE rb_cRuggedBlob;
35
+ VALUE rb_cRuggedBlobSig;
34
36
 
35
37
  /*
36
38
  * call-seq:
@@ -520,6 +522,57 @@ static VALUE rb_git_blob_to_buffer(int argc, VALUE *argv, VALUE self)
520
522
  return rb_ret;
521
523
  }
522
524
 
525
+ static VALUE rb_git_blob_sig_new(int argc, VALUE *argv, VALUE klass)
526
+ {
527
+ int error, opts = 0;
528
+ git_hashsig *sig;
529
+ VALUE rb_blob, rb_options;
530
+
531
+ if (rb_scan_args(argc, argv, "11", &rb_blob, &rb_options) == 2) {
532
+ Check_Type(rb_options, T_FIXNUM);
533
+ opts = FIX2INT(rb_options);
534
+ }
535
+
536
+ if (rb_obj_is_kind_of(rb_blob, rb_cRuggedBlob)) {
537
+ git_blob *blob;
538
+ Data_Get_Struct(rb_blob, git_blob, blob);
539
+
540
+ error = git_hashsig_create(&sig,
541
+ git_blob_rawcontent(blob),
542
+ git_blob_rawsize(blob),
543
+ opts);
544
+ } else {
545
+ Check_Type(rb_blob, T_STRING);
546
+ error = git_hashsig_create(&sig, RSTRING_PTR(rb_blob), RSTRING_LEN(rb_blob), opts);
547
+ }
548
+
549
+ rugged_exception_check(error);
550
+
551
+ return Data_Wrap_Struct(klass, NULL, &git_hashsig_free, sig);
552
+ }
553
+
554
+ static VALUE rb_git_blob_sig_compare(VALUE self, VALUE rb_sig_a, VALUE rb_sig_b)
555
+ {
556
+ git_hashsig *sig_a;
557
+ git_hashsig *sig_b;
558
+ int result;
559
+
560
+ if (!rb_obj_is_kind_of(rb_sig_a, rb_cRuggedBlobSig) ||
561
+ !rb_obj_is_kind_of(rb_sig_b, rb_cRuggedBlobSig)) {
562
+ rb_raise(rb_eTypeError, "Expected Rugged::Blob::HashSignature");
563
+ }
564
+
565
+ Data_Get_Struct(rb_sig_a, git_hashsig, sig_a);
566
+ Data_Get_Struct(rb_sig_b, git_hashsig, sig_b);
567
+
568
+ result = git_hashsig_compare(sig_a, sig_b);
569
+
570
+ if (result < 0)
571
+ rugged_exception_check(result);
572
+
573
+ return INT2FIX(result);
574
+ }
575
+
523
576
  void Init_rugged_blob(void)
524
577
  {
525
578
  id_read = rb_intern("read");
@@ -539,4 +592,8 @@ void Init_rugged_blob(void)
539
592
  rb_define_singleton_method(rb_cRuggedBlob, "from_io", rb_git_blob_from_io, -1);
540
593
 
541
594
  rb_define_singleton_method(rb_cRuggedBlob, "to_buffer", rb_git_blob_to_buffer, -1);
595
+
596
+ rb_cRuggedBlobSig = rb_define_class_under(rb_cRuggedBlob, "HashSignature", rb_cObject);
597
+ rb_define_singleton_method(rb_cRuggedBlobSig, "new", rb_git_blob_sig_new, -1);
598
+ rb_define_singleton_method(rb_cRuggedBlobSig, "compare", rb_git_blob_sig_compare, 2);
542
599
  }
@@ -88,19 +88,42 @@ static void rugged_cred_extract_default(git_cred **cred, VALUE rb_credential)
88
88
  rugged_exception_check(git_cred_default_new(cred));
89
89
  }
90
90
 
91
+ static void rugged_cred_extract_username(git_cred **cred, VALUE rb_credential)
92
+ {
93
+ VALUE rb_username = rb_iv_get(rb_credential, "@username");
94
+ Check_Type(rb_username, T_STRING);
95
+
96
+ rugged_exception_check(git_cred_username_new(cred, StringValueCStr(rb_username)));
97
+ }
98
+
91
99
  void rugged_cred_extract(git_cred **cred, int allowed_types, VALUE rb_credential)
92
100
  {
93
101
  if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredUserPassword)) {
102
+ if (allowed_types & GIT_CREDTYPE_USERNAME) {
103
+ rugged_cred_extract_username(cred, rb_credential);
104
+ return;
105
+ }
106
+
94
107
  if (!(allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT))
95
108
  rb_raise(rb_eArgError, "Invalid credential type");
96
109
 
97
110
  rugged_cred_extract_userpass(cred, rb_credential);
98
111
  } else if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredSshKey)) {
112
+ if (allowed_types & GIT_CREDTYPE_USERNAME) {
113
+ rugged_cred_extract_username(cred, rb_credential);
114
+ return;
115
+ }
116
+
99
117
  if (!(allowed_types & GIT_CREDTYPE_SSH_KEY))
100
118
  rb_raise(rb_eArgError, "Invalid credential type");
101
119
 
102
120
  rugged_cred_extract_ssh_key(cred, rb_credential);
103
121
  } else if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredSshKeyFromAgent)) {
122
+ if (allowed_types & GIT_CREDTYPE_USERNAME) {
123
+ rugged_cred_extract_username(cred, rb_credential);
124
+ return;
125
+ }
126
+
104
127
  if (!(allowed_types & GIT_CREDTYPE_SSH_KEY))
105
128
  rb_raise(rb_eArgError, "Invalid credential type");
106
129
 
@@ -681,6 +681,10 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
681
681
  Data_Get_Struct(self, git_index, index);
682
682
  Data_Get_Struct(rb_tree, git_tree, tree);
683
683
 
684
+ if (!rb_obj_is_kind_of(rb_tree, rb_cRuggedTree)) {
685
+ rb_raise(rb_eTypeError, "A Rugged::Tree instance is required");
686
+ }
687
+
684
688
  error = git_index_read_tree(index, tree);
685
689
  rugged_exception_check(error);
686
690
 
@@ -752,7 +756,7 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
752
756
  * :recurse_untracked_dirs ::
753
757
  * Even if +:include_untracked+ is true, untracked directories will only be
754
758
  * marked with a single entry in the diff. If this flag is set to true,
755
- * all files under ignored directories will be included in the di ff, too.
759
+ * all files under ignored directories will be included in the diff, too.
756
760
  *
757
761
  * :disable_pathspec_match ::
758
762
  * If true, the given +:paths+ will be applied as exact matches, instead of
@@ -831,7 +835,7 @@ static VALUE rb_git_index_diff(int argc, VALUE *argv, VALUE self)
831
835
  xfree(opts.pathspec.strings);
832
836
  rugged_exception_check(error);
833
837
 
834
- return rugged_diff_new(rb_cRuggedDiff, self, diff);
838
+ return rugged_diff_new(rb_cRuggedDiff, owner, diff);
835
839
  }
836
840
 
837
841
  /*
@@ -29,7 +29,7 @@ extern VALUE rb_cRuggedRepo;
29
29
  extern VALUE rb_eRuggedError;
30
30
  VALUE rb_cRuggedRemote;
31
31
 
32
- #define RUGGED_REMOTE_CALLBACKS_INIT {1, progress_cb, NULL, credentials_cb, transfer_progress_cb, update_tips_cb, NULL}
32
+ #define RUGGED_REMOTE_CALLBACKS_INIT {1, progress_cb, NULL, credentials_cb, NULL, transfer_progress_cb, update_tips_cb, NULL}
33
33
 
34
34
  static int progress_cb(const char *str, int len, void *data)
35
35
  {
@@ -322,7 +322,7 @@ static VALUE rb_git_remote_set_url(VALUE self, VALUE rb_url)
322
322
  {
323
323
  git_remote *remote;
324
324
 
325
- rugged_validate_remote_url(rb_url);
325
+ Check_Type(rb_url, T_STRING);
326
326
  Data_Get_Struct(self, git_remote, remote);
327
327
 
328
328
  rugged_exception_check(
@@ -364,7 +364,7 @@ static VALUE rb_git_remote_set_push_url(VALUE self, VALUE rb_url)
364
364
  {
365
365
  git_remote *remote;
366
366
 
367
- rugged_validate_remote_url(rb_url);
367
+ Check_Type(rb_url, T_STRING);
368
368
  Data_Get_Struct(self, git_remote, remote);
369
369
 
370
370
  rugged_exception_check(
@@ -499,40 +499,69 @@ static VALUE rb_git_remote_save(VALUE self)
499
499
 
500
500
  /*
501
501
  * call-seq:
502
- * remote.rename!(new_name) -> array or nil
502
+ * remote.check_connection(direction, options = {}) -> boolean
503
503
  *
504
- * Renames a remote.
504
+ * Try to connect to the +remote+. Useful to simulate
505
+ * <tt>git fetch --dry-run</tt> and <tt>git push --dry-run</tt>.
505
506
  *
506
- * All remote-tracking branches and configuration settings
507
- * for the remote are updated.
507
+ * Returns +true+ if connection is successful, +false+ otherwise.
508
508
  *
509
- * Returns +nil+ if everything was updated or array of fetch refspecs
510
- * that haven't been automatically updated and need potential manual
511
- * tweaking.
509
+ * +direction+ must be either +:fetch+ or +:push+.
512
510
  *
513
- * Anonymous, in-memory remotes created through
514
- * +ReferenceCollection#create_anonymous+ can not be given a name through
515
- * this method.
511
+ * The following options can be passed in the +options+ Hash:
516
512
  *
517
- * remote = Rugged::Remote.lookup(@repo, 'origin')
518
- * remote.rename!('upstream') #=> nil
513
+ * +credentials+ ::
514
+ * The credentials to use for the connection. Can be either an instance of
515
+ * one of the Rugged::Credentials types, or a proc returning one of the
516
+ * former.
517
+ * The proc will be called with the +url+, the +username+ from the url (if
518
+ * applicable) and a list of applicable credential types.
519
+ *
520
+ * Example:
521
+ *
522
+ * remote = repo.remotes["origin"]
523
+ * success = remote.check_connection(:fetch)
524
+ * raise Error("Unable to pull without credentials") unless success
519
525
  */
520
- static VALUE rb_git_remote_rename(VALUE self, VALUE rb_new_name)
526
+ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
521
527
  {
522
528
  git_remote *remote;
523
- git_strarray problems = {0};
524
- VALUE rb_result;
529
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
530
+ struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
531
+ VALUE rb_direction, rb_options;
532
+ ID id_direction;
533
+ int error, direction;
525
534
 
526
- Check_Type(rb_new_name, T_STRING);
527
535
  Data_Get_Struct(self, git_remote, remote);
528
-
529
- rugged_exception_check(
530
- git_remote_rename(&problems, remote, StringValueCStr(rb_new_name))
531
- );
536
+ rb_scan_args(argc, argv, "01:", &rb_direction, &rb_options);
537
+
538
+ Check_Type(rb_direction, T_SYMBOL);
539
+ id_direction = SYM2ID(rb_direction);
540
+ if (id_direction == rb_intern("fetch"))
541
+ direction = GIT_DIRECTION_FETCH;
542
+ else if (id_direction == rb_intern("push"))
543
+ direction = GIT_DIRECTION_PUSH;
544
+ else
545
+ rb_raise(rb_eTypeError, "Invalid direction. Expected :fetch or :push");
532
546
 
533
- rb_result = problems.count == 0 ? Qnil : rugged_strarray_to_rb_ary(&problems);
534
- git_strarray_free(&problems);
535
- return rb_result;
547
+ if (!NIL_P(rb_options))
548
+ rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
549
+
550
+ if ((error = git_remote_set_callbacks(remote, &callbacks)) < 0)
551
+ goto cleanup;
552
+
553
+ if (git_remote_connect(remote, direction))
554
+ return Qfalse;
555
+ else {
556
+ git_remote_disconnect(remote);
557
+ return Qtrue;
558
+ }
559
+
560
+ cleanup:
561
+ if (payload.exception)
562
+ rb_jump_tag(payload.exception);
563
+ rugged_exception_check(error);
564
+ return Qfalse;
536
565
  }
537
566
 
538
567
  /*
@@ -541,7 +570,7 @@ static VALUE rb_git_remote_rename(VALUE self, VALUE rb_new_name)
541
570
  *
542
571
  * Downloads new data from the remote for the given +refspecs+ and updates tips.
543
572
  *
544
- * You can optionally pass in an alternative list of +refspecs+ to use instead of the fetch
573
+ * You can optionally pass in a single or multiple alternative +refspecs+ to use instead of the fetch
545
574
  * refspecs already configured for +remote+.
546
575
  *
547
576
  * Returns a hash containing statistics for the fetch operation.
@@ -584,26 +613,21 @@ static VALUE rb_git_remote_rename(VALUE self, VALUE rb_new_name)
584
613
  */
585
614
  static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
586
615
  {
587
- git_remote *remote, *tmp_remote = NULL;
616
+ git_remote *remote;
588
617
  git_repository *repo;
589
618
  git_signature *signature = NULL;
619
+ git_strarray refspecs;
590
620
  git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
591
621
  struct rugged_remote_cb_payload payload = { Qnil, Qnil, Qnil, Qnil, Qnil, 0 };
592
622
 
593
623
  char *log_message = NULL;
594
- int error, i;
624
+ int error;
595
625
 
596
626
  VALUE rb_options, rb_refspecs, rb_result = Qnil, rb_repo = rugged_owner(self);
597
627
 
598
628
  rb_scan_args(argc, argv, "01:", &rb_refspecs, &rb_options);
599
629
 
600
- if (!NIL_P(rb_refspecs)) {
601
- Check_Type(rb_refspecs, T_ARRAY);
602
- for (i = 0; i < RARRAY_LEN(rb_refspecs); ++i) {
603
- VALUE rb_refspec = rb_ary_entry(rb_refspecs, i);
604
- Check_Type(rb_refspec, T_STRING);
605
- }
606
- }
630
+ rugged_rb_ary_to_strarray(rb_refspecs, &refspecs);
607
631
 
608
632
  Data_Get_Struct(self, git_remote, remote);
609
633
  rugged_check_repo(rb_repo);
@@ -621,22 +645,11 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
621
645
  rugged_remote_init_callbacks_and_payload_from_options(rb_options, &callbacks, &payload);
622
646
  }
623
647
 
624
- if ((error = git_remote_dup(&tmp_remote, remote)) ||
625
- (error = git_remote_set_callbacks(tmp_remote, &callbacks)))
648
+ if ((error = git_remote_set_callbacks(remote, &callbacks)))
626
649
  goto cleanup;
627
650
 
628
- if (!NIL_P(rb_refspecs)) {
629
- git_remote_clear_refspecs(tmp_remote);
630
- for (i = 0; !error && i < RARRAY_LEN(rb_refspecs); ++i) {
631
- VALUE rb_refspec = rb_ary_entry(rb_refspecs, i);
632
-
633
- if ((error = git_remote_add_fetch(tmp_remote, StringValueCStr(rb_refspec))))
634
- goto cleanup;
635
- }
636
- }
637
-
638
- if ((error = git_remote_fetch(tmp_remote, signature, log_message)) == GIT_OK) {
639
- const git_transfer_progress *stats = git_remote_stats(tmp_remote);
651
+ if ((error = git_remote_fetch(remote, &refspecs, signature, log_message)) == GIT_OK) {
652
+ const git_transfer_progress *stats = git_remote_stats(remote);
640
653
 
641
654
  rb_result = rb_hash_new();
642
655
  rb_hash_aset(rb_result, CSTR2SYM("total_objects"), UINT2NUM(stats->total_objects));
@@ -650,8 +663,8 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
650
663
 
651
664
  cleanup:
652
665
 
666
+ xfree(refspecs.strings);
653
667
  git_signature_free(signature);
654
- git_remote_free(tmp_remote);
655
668
 
656
669
  if (payload.exception)
657
670
  rb_jump_tag(payload.exception);
@@ -827,9 +840,9 @@ void Init_rugged_remote(void)
827
840
  rb_define_method(rb_cRuggedRemote, "add_fetch", rb_git_remote_add_fetch, 1);
828
841
  rb_define_method(rb_cRuggedRemote, "add_push", rb_git_remote_add_push, 1);
829
842
  rb_define_method(rb_cRuggedRemote, "ls", rb_git_remote_ls, -1);
843
+ rb_define_method(rb_cRuggedRemote, "check_connection", rb_git_remote_check_connection, -1);
830
844
  rb_define_method(rb_cRuggedRemote, "fetch", rb_git_remote_fetch, -1);
831
845
  rb_define_method(rb_cRuggedRemote, "push", rb_git_remote_push, -1);
832
846
  rb_define_method(rb_cRuggedRemote, "clear_refspecs", rb_git_remote_clear_refspecs, 0);
833
847
  rb_define_method(rb_cRuggedRemote, "save", rb_git_remote_save, 0);
834
- rb_define_method(rb_cRuggedRemote, "rename!", rb_git_remote_rename, 1);
835
848
  }