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.
Files changed (283) hide show
  1. data/README.md +9 -4
  2. data/Rakefile +1 -1
  3. data/ext/rugged/extconf.rb +10 -0
  4. data/ext/rugged/rugged.c +153 -86
  5. data/ext/rugged/rugged.h +44 -33
  6. data/ext/rugged/rugged_blob.c +288 -60
  7. data/ext/rugged/rugged_branch.c +82 -57
  8. data/ext/rugged/rugged_commit.c +83 -86
  9. data/ext/rugged/rugged_config.c +68 -68
  10. data/ext/rugged/rugged_diff.c +509 -0
  11. data/ext/rugged/rugged_diff_delta.c +94 -0
  12. data/ext/rugged/rugged_diff_hunk.c +100 -0
  13. data/ext/rugged/rugged_diff_line.c +79 -0
  14. data/ext/rugged/rugged_diff_patch.c +169 -0
  15. data/ext/rugged/rugged_index.c +539 -8
  16. data/ext/rugged/rugged_note.c +74 -80
  17. data/ext/rugged/rugged_object.c +63 -8
  18. data/ext/rugged/rugged_reference.c +231 -145
  19. data/ext/rugged/rugged_remote.c +509 -53
  20. data/ext/rugged/rugged_repo.c +572 -236
  21. data/ext/rugged/rugged_revwalk.c +59 -36
  22. data/ext/rugged/rugged_settings.c +7 -9
  23. data/ext/rugged/rugged_signature.c +7 -11
  24. data/ext/rugged/rugged_tag.c +93 -39
  25. data/ext/rugged/rugged_tree.c +321 -58
  26. data/lib/rugged.rb +1 -0
  27. data/lib/rugged/commit.rb +16 -1
  28. data/lib/rugged/console.rb +9 -0
  29. data/lib/rugged/diff.rb +19 -0
  30. data/lib/rugged/diff/delta.rb +54 -0
  31. data/lib/rugged/diff/hunk.rb +23 -0
  32. data/lib/rugged/diff/line.rb +29 -0
  33. data/lib/rugged/diff/patch.rb +28 -0
  34. data/lib/rugged/repository.rb +36 -39
  35. data/lib/rugged/version.rb +1 -1
  36. data/test/blob_test.rb +308 -1
  37. data/test/branch_test.rb +7 -0
  38. data/test/commit_test.rb +7 -10
  39. data/test/coverage/cover.rb +9 -1
  40. data/test/diff_test.rb +777 -0
  41. data/test/fixtures/archive.tar.gz +0 -0
  42. data/test/fixtures/attr/attr0 +1 -0
  43. data/test/fixtures/attr/attr1 +29 -0
  44. data/test/fixtures/attr/attr2 +21 -0
  45. data/test/fixtures/attr/attr3 +4 -0
  46. data/test/fixtures/attr/binfile +1 -0
  47. data/test/fixtures/attr/dir/file +0 -0
  48. data/test/fixtures/attr/file +1 -0
  49. data/test/fixtures/attr/gitattributes +29 -0
  50. data/test/fixtures/attr/gitignore +2 -0
  51. data/test/fixtures/attr/ign +1 -0
  52. data/test/fixtures/attr/macro_bad +1 -0
  53. data/test/fixtures/attr/macro_test +1 -0
  54. data/test/fixtures/attr/root_test1 +1 -0
  55. data/test/fixtures/attr/root_test2 +6 -0
  56. data/test/fixtures/attr/root_test3 +19 -0
  57. data/test/fixtures/attr/root_test4.txt +14 -0
  58. data/test/fixtures/attr/sub/abc +37 -0
  59. data/test/fixtures/attr/sub/dir/file +0 -0
  60. data/test/fixtures/attr/sub/file +1 -0
  61. data/test/fixtures/attr/sub/ign/file +1 -0
  62. data/test/fixtures/attr/sub/ign/sub/file +1 -0
  63. data/test/fixtures/attr/sub/sub/dir +0 -0
  64. data/test/fixtures/attr/sub/sub/file +1 -0
  65. data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
  66. data/test/fixtures/attr/sub/subdir_test1 +2 -0
  67. data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
  68. data/test/fixtures/diff/another.txt +38 -0
  69. data/test/fixtures/diff/readme.txt +36 -0
  70. data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
  71. data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
  72. data/test/fixtures/mergedrepo/one.txt +10 -0
  73. data/test/fixtures/mergedrepo/two.txt +12 -0
  74. data/test/fixtures/status/current_file +1 -0
  75. data/test/fixtures/status/ignored_file +1 -0
  76. data/test/fixtures/status/modified_file +2 -0
  77. data/test/fixtures/status/new_file +1 -0
  78. data/test/fixtures/status/staged_changes +2 -0
  79. data/test/fixtures/status/staged_changes_modified_file +3 -0
  80. data/test/fixtures/status/staged_delete_modified_file +1 -0
  81. data/test/fixtures/status/staged_new_file +1 -0
  82. data/test/fixtures/status/staged_new_file_modified_file +2 -0
  83. data/test/fixtures/status/subdir.txt +2 -0
  84. data/test/fixtures/status/subdir/current_file +1 -0
  85. data/test/fixtures/status/subdir/modified_file +2 -0
  86. data/test/fixtures/status/subdir/new_file +1 -0
  87. data/test/fixtures/status//350/277/231 +1 -0
  88. data/test/fixtures/testrepo.git/config +5 -0
  89. data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
  90. data/test/fixtures/text_file.md +464 -0
  91. data/test/fixtures/unsymlinked.git/HEAD +1 -0
  92. data/test/fixtures/unsymlinked.git/config +6 -0
  93. data/test/fixtures/unsymlinked.git/description +1 -0
  94. data/test/fixtures/unsymlinked.git/info/exclude +2 -0
  95. data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
  96. data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
  97. data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
  98. data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
  99. data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
  100. data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
  101. data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
  102. data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
  103. data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
  104. data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
  105. data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
  106. data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
  107. data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
  108. data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
  109. data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
  110. data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
  111. data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
  112. data/test/index_test.rb +120 -0
  113. data/test/reference_test.rb +38 -3
  114. data/test/remote_test.rb +224 -3
  115. data/test/repo_reset_test.rb +2 -0
  116. data/test/repo_test.rb +147 -10
  117. data/test/test_helper.rb +5 -2
  118. data/vendor/libgit2/include/git2/attr.h +3 -3
  119. data/vendor/libgit2/include/git2/blob.h +11 -17
  120. data/vendor/libgit2/include/git2/branch.h +3 -2
  121. data/vendor/libgit2/include/git2/checkout.h +7 -0
  122. data/vendor/libgit2/include/git2/clone.h +3 -0
  123. data/vendor/libgit2/include/git2/commit.h +61 -66
  124. data/vendor/libgit2/include/git2/common.h +73 -42
  125. data/vendor/libgit2/include/git2/config.h +57 -71
  126. data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
  127. data/vendor/libgit2/include/git2/diff.h +179 -30
  128. data/vendor/libgit2/include/git2/errors.h +3 -3
  129. data/vendor/libgit2/include/git2/index.h +225 -146
  130. data/vendor/libgit2/include/git2/indexer.h +2 -22
  131. data/vendor/libgit2/include/git2/inttypes.h +9 -9
  132. data/vendor/libgit2/include/git2/merge.h +123 -5
  133. data/vendor/libgit2/include/git2/odb.h +59 -38
  134. data/vendor/libgit2/include/git2/odb_backend.h +45 -104
  135. data/vendor/libgit2/include/git2/oid.h +30 -19
  136. data/vendor/libgit2/include/git2/pack.h +21 -3
  137. data/vendor/libgit2/include/git2/refdb.h +0 -35
  138. data/vendor/libgit2/include/git2/refs.h +93 -31
  139. data/vendor/libgit2/include/git2/refspec.h +17 -0
  140. data/vendor/libgit2/include/git2/remote.h +60 -20
  141. data/vendor/libgit2/include/git2/repository.h +48 -70
  142. data/vendor/libgit2/include/git2/reset.h +3 -3
  143. data/vendor/libgit2/include/git2/revparse.h +22 -0
  144. data/vendor/libgit2/include/git2/stash.h +1 -1
  145. data/vendor/libgit2/include/git2/status.h +131 -56
  146. data/vendor/libgit2/include/git2/strarray.h +2 -2
  147. data/vendor/libgit2/include/git2/submodule.h +16 -16
  148. data/vendor/libgit2/include/git2/sys/commit.h +46 -0
  149. data/vendor/libgit2/include/git2/sys/config.h +71 -0
  150. data/vendor/libgit2/include/git2/sys/index.h +179 -0
  151. data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
  152. data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
  153. data/vendor/libgit2/include/git2/sys/refs.h +38 -0
  154. data/vendor/libgit2/include/git2/sys/repository.h +106 -0
  155. data/vendor/libgit2/include/git2/tag.h +44 -18
  156. data/vendor/libgit2/include/git2/trace.h +1 -2
  157. data/vendor/libgit2/include/git2/transport.h +74 -0
  158. data/vendor/libgit2/include/git2/tree.h +12 -22
  159. data/vendor/libgit2/include/git2/types.h +33 -0
  160. data/vendor/libgit2/include/git2/version.h +2 -2
  161. data/vendor/libgit2/src/array.h +66 -0
  162. data/vendor/libgit2/src/attr.c +26 -13
  163. data/vendor/libgit2/src/attr_file.c +3 -2
  164. data/vendor/libgit2/src/attr_file.h +3 -3
  165. data/vendor/libgit2/src/attrcache.h +4 -4
  166. data/vendor/libgit2/src/blob.c +13 -9
  167. data/vendor/libgit2/src/blob.h +2 -2
  168. data/vendor/libgit2/src/branch.c +67 -49
  169. data/vendor/libgit2/src/cache.c +224 -54
  170. data/vendor/libgit2/src/cache.h +33 -20
  171. data/vendor/libgit2/src/checkout.c +145 -85
  172. data/vendor/libgit2/src/clone.c +62 -50
  173. data/vendor/libgit2/src/commit.c +74 -40
  174. data/vendor/libgit2/src/commit.h +2 -3
  175. data/vendor/libgit2/src/commit_list.c +14 -8
  176. data/vendor/libgit2/src/config.c +119 -36
  177. data/vendor/libgit2/src/config.h +3 -0
  178. data/vendor/libgit2/src/config_cache.c +24 -7
  179. data/vendor/libgit2/src/config_file.c +9 -6
  180. data/vendor/libgit2/src/crlf.c +4 -2
  181. data/vendor/libgit2/src/date.c +3 -3
  182. data/vendor/libgit2/src/delta.c +1 -1
  183. data/vendor/libgit2/src/diff.c +681 -303
  184. data/vendor/libgit2/src/diff.h +34 -2
  185. data/vendor/libgit2/src/diff_driver.c +405 -0
  186. data/vendor/libgit2/src/diff_driver.h +49 -0
  187. data/vendor/libgit2/src/diff_file.c +447 -0
  188. data/vendor/libgit2/src/diff_file.h +58 -0
  189. data/vendor/libgit2/src/diff_patch.c +995 -0
  190. data/vendor/libgit2/src/diff_patch.h +46 -0
  191. data/vendor/libgit2/src/diff_print.c +430 -0
  192. data/vendor/libgit2/src/diff_tform.c +464 -203
  193. data/vendor/libgit2/src/diff_xdiff.c +166 -0
  194. data/vendor/libgit2/src/diff_xdiff.h +28 -0
  195. data/vendor/libgit2/src/fetch.c +11 -4
  196. data/vendor/libgit2/src/fileops.c +85 -61
  197. data/vendor/libgit2/src/fileops.h +4 -0
  198. data/vendor/libgit2/src/global.c +10 -2
  199. data/vendor/libgit2/src/global.h +0 -8
  200. data/vendor/libgit2/src/hash/hash_generic.h +3 -3
  201. data/vendor/libgit2/src/hash/hash_win32.h +4 -4
  202. data/vendor/libgit2/src/hashsig.c +0 -1
  203. data/vendor/libgit2/src/ignore.c +68 -28
  204. data/vendor/libgit2/src/ignore.h +10 -1
  205. data/vendor/libgit2/src/index.c +666 -84
  206. data/vendor/libgit2/src/index.h +6 -0
  207. data/vendor/libgit2/src/indexer.c +10 -28
  208. data/vendor/libgit2/src/iterator.c +427 -283
  209. data/vendor/libgit2/src/iterator.h +58 -4
  210. data/vendor/libgit2/src/merge.c +1892 -32
  211. data/vendor/libgit2/src/merge.h +132 -5
  212. data/vendor/libgit2/src/merge_file.c +174 -0
  213. data/vendor/libgit2/src/merge_file.h +71 -0
  214. data/vendor/libgit2/src/mwindow.c +1 -1
  215. data/vendor/libgit2/src/notes.c +45 -48
  216. data/vendor/libgit2/src/object.c +89 -127
  217. data/vendor/libgit2/src/object.h +0 -1
  218. data/vendor/libgit2/src/object_api.c +129 -0
  219. data/vendor/libgit2/src/odb.c +156 -59
  220. data/vendor/libgit2/src/odb.h +5 -2
  221. data/vendor/libgit2/src/odb_loose.c +31 -17
  222. data/vendor/libgit2/src/odb_pack.c +39 -43
  223. data/vendor/libgit2/src/oid.c +62 -27
  224. data/vendor/libgit2/src/oid.h +33 -0
  225. data/vendor/libgit2/src/oidmap.h +4 -6
  226. data/vendor/libgit2/src/pack-objects.c +54 -22
  227. data/vendor/libgit2/src/pack.c +98 -56
  228. data/vendor/libgit2/src/pack.h +3 -1
  229. data/vendor/libgit2/src/pathspec.c +26 -1
  230. data/vendor/libgit2/src/pathspec.h +14 -0
  231. data/vendor/libgit2/src/pool.c +5 -0
  232. data/vendor/libgit2/src/posix.c +2 -2
  233. data/vendor/libgit2/src/posix.h +3 -0
  234. data/vendor/libgit2/src/push.c +13 -10
  235. data/vendor/libgit2/src/refdb.c +82 -62
  236. data/vendor/libgit2/src/refdb.h +16 -16
  237. data/vendor/libgit2/src/refdb_fs.c +386 -133
  238. data/vendor/libgit2/src/reflog.c +3 -1
  239. data/vendor/libgit2/src/refs.c +247 -221
  240. data/vendor/libgit2/src/refs.h +2 -1
  241. data/vendor/libgit2/src/refspec.c +18 -1
  242. data/vendor/libgit2/src/refspec.h +3 -1
  243. data/vendor/libgit2/src/remote.c +434 -253
  244. data/vendor/libgit2/src/remote.h +5 -3
  245. data/vendor/libgit2/src/repository.c +197 -111
  246. data/vendor/libgit2/src/repository.h +26 -5
  247. data/vendor/libgit2/src/reset.c +1 -1
  248. data/vendor/libgit2/src/revparse.c +84 -79
  249. data/vendor/libgit2/src/revwalk.c +1 -1
  250. data/vendor/libgit2/src/signature.c +22 -10
  251. data/vendor/libgit2/src/stash.c +5 -2
  252. data/vendor/libgit2/src/status.c +311 -107
  253. data/vendor/libgit2/src/status.h +23 -0
  254. data/vendor/libgit2/src/submodule.c +21 -13
  255. data/vendor/libgit2/src/tag.c +42 -31
  256. data/vendor/libgit2/src/tag.h +2 -3
  257. data/vendor/libgit2/src/thread-utils.h +105 -3
  258. data/vendor/libgit2/src/trace.c +1 -2
  259. data/vendor/libgit2/src/trace.h +3 -3
  260. data/vendor/libgit2/src/transport.c +18 -6
  261. data/vendor/libgit2/src/transports/cred.c +103 -1
  262. data/vendor/libgit2/src/transports/local.c +19 -9
  263. data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
  264. data/vendor/libgit2/src/transports/ssh.c +519 -0
  265. data/vendor/libgit2/src/transports/winhttp.c +3 -1
  266. data/vendor/libgit2/src/tree.c +26 -28
  267. data/vendor/libgit2/src/tree.h +3 -3
  268. data/vendor/libgit2/src/unix/posix.h +2 -0
  269. data/vendor/libgit2/src/util.c +43 -6
  270. data/vendor/libgit2/src/util.h +40 -12
  271. data/vendor/libgit2/src/vector.c +3 -5
  272. data/vendor/libgit2/src/vector.h +9 -0
  273. data/vendor/libgit2/src/win32/dir.c +1 -1
  274. data/vendor/libgit2/src/win32/error.c +2 -0
  275. data/vendor/libgit2/src/win32/findfile.c +3 -6
  276. data/vendor/libgit2/src/win32/posix_w32.c +85 -59
  277. data/vendor/libgit2/src/win32/pthread.c +16 -8
  278. data/vendor/libgit2/src/win32/pthread.h +7 -4
  279. metadata +407 -306
  280. data/test/coverage/HEAD.json +0 -1
  281. data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
  282. data/vendor/libgit2/src/diff_output.c +0 -1819
  283. data/vendor/libgit2/src/diff_output.h +0 -93
@@ -12,16 +12,15 @@
12
12
  #include "git2/odb.h"
13
13
  #include "git2/repository.h"
14
14
  #include "git2/object.h"
15
+ #include "git2/config.h"
15
16
 
16
- #include "index.h"
17
17
  #include "cache.h"
18
18
  #include "refs.h"
19
19
  #include "buffer.h"
20
- #include "odb.h"
21
20
  #include "object.h"
22
21
  #include "attrcache.h"
23
22
  #include "strmap.h"
24
- #include "refdb.h"
23
+ #include "diff_driver.h"
25
24
 
26
25
  #define DOT_GIT ".git"
27
26
  #define GIT_DIR DOT_GIT "/"
@@ -31,7 +30,13 @@
31
30
  /** Cvar cache identifiers */
32
31
  typedef enum {
33
32
  GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
34
- GIT_CVAR_EOL, /* core.eol */
33
+ GIT_CVAR_EOL, /* core.eol */
34
+ GIT_CVAR_SYMLINKS, /* core.symlinks */
35
+ GIT_CVAR_IGNORECASE, /* core.ignorecase */
36
+ GIT_CVAR_FILEMODE, /* core.filemode */
37
+ GIT_CVAR_IGNORESTAT, /* core.ignorestat */
38
+ GIT_CVAR_TRUSTCTIME, /* core.trustctime */
39
+ GIT_CVAR_ABBREV, /* core.abbrev */
35
40
  GIT_CVAR_CACHE_MAX
36
41
  } git_cvar_cached;
37
42
 
@@ -67,7 +72,21 @@ typedef enum {
67
72
  #else
68
73
  GIT_EOL_NATIVE = GIT_EOL_LF,
69
74
  #endif
70
- GIT_EOL_DEFAULT = GIT_EOL_NATIVE
75
+ GIT_EOL_DEFAULT = GIT_EOL_NATIVE,
76
+
77
+ /* core.symlinks: bool */
78
+ GIT_SYMLINKS_DEFAULT = GIT_CVAR_TRUE,
79
+ /* core.ignorecase */
80
+ GIT_IGNORECASE_DEFAULT = GIT_CVAR_FALSE,
81
+ /* core.filemode */
82
+ GIT_FILEMODE_DEFAULT = GIT_CVAR_TRUE,
83
+ /* core.ignorestat */
84
+ GIT_IGNORESTAT_DEFAULT = GIT_CVAR_FALSE,
85
+ /* core.trustctime */
86
+ GIT_TRUSTCTIME_DEFAULT = GIT_CVAR_TRUE,
87
+ /* core.abbrev */
88
+ GIT_ABBREV_DEFAULT = 7,
89
+
71
90
  } git_cvar_value;
72
91
 
73
92
  /* internal repository init flags */
@@ -87,9 +106,11 @@ struct git_repository {
87
106
  git_cache objects;
88
107
  git_attr_cache attrcache;
89
108
  git_strmap *submodules;
109
+ git_diff_driver_registry *diff_drivers;
90
110
 
91
111
  char *path_repository;
92
112
  char *workdir;
113
+ char *namespace;
93
114
 
94
115
  unsigned is_bare:1;
95
116
  unsigned int lru_counter;
@@ -32,7 +32,7 @@ int git_reset_default(
32
32
  int error;
33
33
  git_index *index = NULL;
34
34
 
35
- assert(pathspecs != NULL && pathspecs->count > 0);
35
+ assert(pathspecs != NULL && pathspecs->count > 0);
36
36
 
37
37
  memset(&entry, 0, sizeof(git_index_entry));
38
38
 
@@ -14,60 +14,6 @@
14
14
 
15
15
  #include "git2.h"
16
16
 
17
- static int disambiguate_refname(git_reference **out, git_repository *repo, const char *refname)
18
- {
19
- int error, i;
20
- bool fallbackmode = true;
21
- git_reference *ref;
22
- git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT;
23
-
24
- static const char* formatters[] = {
25
- "%s",
26
- GIT_REFS_DIR "%s",
27
- GIT_REFS_TAGS_DIR "%s",
28
- GIT_REFS_HEADS_DIR "%s",
29
- GIT_REFS_REMOTES_DIR "%s",
30
- GIT_REFS_REMOTES_DIR "%s/" GIT_HEAD_FILE,
31
- NULL
32
- };
33
-
34
- if (*refname)
35
- git_buf_puts(&name, refname);
36
- else {
37
- git_buf_puts(&name, GIT_HEAD_FILE);
38
- fallbackmode = false;
39
- }
40
-
41
- for (i = 0; formatters[i] && (fallbackmode || i == 0); i++) {
42
-
43
- git_buf_clear(&refnamebuf);
44
-
45
- if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0)
46
- goto cleanup;
47
-
48
- if (!git_reference_is_valid_name(git_buf_cstr(&refnamebuf))) {
49
- error = GIT_EINVALIDSPEC;
50
- continue;
51
- }
52
-
53
- error = git_reference_lookup_resolved(&ref, repo, git_buf_cstr(&refnamebuf), -1);
54
-
55
- if (!error) {
56
- *out = ref;
57
- error = 0;
58
- goto cleanup;
59
- }
60
-
61
- if (error != GIT_ENOTFOUND)
62
- goto cleanup;
63
- }
64
-
65
- cleanup:
66
- git_buf_free(&name);
67
- git_buf_free(&refnamebuf);
68
- return error;
69
- }
70
-
71
17
  static int maybe_sha_or_abbrev(git_object** out, git_repository *repo, const char *spec, size_t speclen)
72
18
  {
73
19
  git_oid oid;
@@ -138,36 +84,45 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
138
84
  return maybe_abbrev(out, repo, substr+2);
139
85
  }
140
86
 
141
- static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec)
87
+ static int revparse_lookup_object(
88
+ git_object **object_out,
89
+ git_reference **reference_out,
90
+ git_repository *repo,
91
+ const char *spec)
142
92
  {
143
93
  int error;
144
94
  git_reference *ref;
145
95
 
146
- error = maybe_sha(out, repo, spec);
96
+ error = maybe_sha(object_out, repo, spec);
147
97
  if (!error)
148
98
  return 0;
149
99
 
150
100
  if (error < 0 && error != GIT_ENOTFOUND)
151
101
  return error;
152
102
 
153
- error = disambiguate_refname(&ref, repo, spec);
103
+ error = git_reference_dwim(&ref, repo, spec);
154
104
  if (!error) {
155
- error = git_object_lookup(out, repo, git_reference_target(ref), GIT_OBJ_ANY);
156
- git_reference_free(ref);
105
+
106
+ error = git_object_lookup(
107
+ object_out, repo, git_reference_target(ref), GIT_OBJ_ANY);
108
+
109
+ if (!error)
110
+ *reference_out = ref;
111
+
157
112
  return error;
158
113
  }
159
114
 
160
115
  if (error < 0 && error != GIT_ENOTFOUND)
161
116
  return error;
162
117
 
163
- error = maybe_abbrev(out, repo, spec);
118
+ error = maybe_abbrev(object_out, repo, spec);
164
119
  if (!error)
165
120
  return 0;
166
121
 
167
122
  if (error < 0 && error != GIT_ENOTFOUND)
168
123
  return error;
169
124
 
170
- error = maybe_describe(out, repo, spec);
125
+ error = maybe_describe(object_out, repo, spec);
171
126
  if (!error)
172
127
  return 0;
173
128
 
@@ -235,7 +190,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
235
190
 
236
191
  git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);
237
192
 
238
- if ((error = disambiguate_refname(base_ref, repo, git_buf_cstr(&buf))) == 0)
193
+ if ((error = git_reference_dwim(base_ref, repo, git_buf_cstr(&buf))) == 0)
239
194
  goto cleanup;
240
195
 
241
196
  if (error < 0 && error != GIT_ENOTFOUND)
@@ -316,7 +271,7 @@ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base
316
271
  int error = -1;
317
272
 
318
273
  if (*base_ref == NULL) {
319
- if ((error = disambiguate_refname(&ref, repo, identifier)) < 0)
274
+ if ((error = git_reference_dwim(&ref, repo, identifier)) < 0)
320
275
  return error;
321
276
  } else {
322
277
  ref = *base_ref;
@@ -344,7 +299,7 @@ static int retrieve_remote_tracking_reference(git_reference **base_ref, const ch
344
299
  int error = -1;
345
300
 
346
301
  if (*base_ref == NULL) {
347
- if ((error = disambiguate_refname(&ref, repo, identifier)) < 0)
302
+ if ((error = git_reference_dwim(&ref, repo, identifier)) < 0)
348
303
  return error;
349
304
  } else {
350
305
  ref = *base_ref;
@@ -671,14 +626,8 @@ static int ensure_base_rev_loaded(git_object **object, git_reference **reference
671
626
  if (*object != NULL)
672
627
  return 0;
673
628
 
674
- if (*reference != NULL) {
675
- if ((error = object_from_reference(object, *reference)) < 0)
676
- return error;
677
-
678
- git_reference_free(*reference);
679
- *reference = NULL;
680
- return 0;
681
- }
629
+ if (*reference != NULL)
630
+ return object_from_reference(object, *reference);
682
631
 
683
632
  if (!allow_empty_identifier && identifier_len == 0)
684
633
  return GIT_EINVALIDSPEC;
@@ -686,7 +635,7 @@ static int ensure_base_rev_loaded(git_object **object, git_reference **reference
686
635
  if (git_buf_put(&identifier, spec, identifier_len) < 0)
687
636
  return -1;
688
637
 
689
- error = revparse_lookup_object(object, repo, git_buf_cstr(&identifier));
638
+ error = revparse_lookup_object(object, reference, repo, git_buf_cstr(&identifier));
690
639
  git_buf_free(&identifier);
691
640
 
692
641
  return error;
@@ -722,7 +671,12 @@ static int ensure_left_hand_identifier_is_not_known_yet(git_object *object, git_
722
671
  return GIT_EINVALIDSPEC;
723
672
  }
724
673
 
725
- int git_revparse_single(git_object **out, git_repository *repo, const char *spec)
674
+ int revparse__ext(
675
+ git_object **object_out,
676
+ git_reference **reference_out,
677
+ size_t *identifier_len_out,
678
+ git_repository *repo,
679
+ const char *spec)
726
680
  {
727
681
  size_t pos = 0, identifier_len = 0;
728
682
  int error = -1, n;
@@ -731,9 +685,10 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
731
685
  git_reference *reference = NULL;
732
686
  git_object *base_rev = NULL;
733
687
 
734
- assert(out && repo && spec);
688
+ assert(object_out && reference_out && repo && spec);
735
689
 
736
- *out = NULL;
690
+ *object_out = NULL;
691
+ *reference_out = NULL;
737
692
 
738
693
  while (spec[pos]) {
739
694
  switch (spec[pos]) {
@@ -852,7 +807,9 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
852
807
  if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
853
808
  goto cleanup;
854
809
 
855
- *out = base_rev;
810
+ *object_out = base_rev;
811
+ *reference_out = reference;
812
+ *identifier_len_out = identifier_len;
856
813
  error = 0;
857
814
 
858
815
  cleanup:
@@ -862,12 +819,61 @@ cleanup:
862
819
  "Failed to parse revision specifier - Invalid pattern '%s'", spec);
863
820
 
864
821
  git_object_free(base_rev);
822
+ git_reference_free(reference);
865
823
  }
866
- git_reference_free(reference);
824
+
867
825
  git_buf_free(&buf);
868
826
  return error;
869
827
  }
870
828
 
829
+ int git_revparse_ext(
830
+ git_object **object_out,
831
+ git_reference **reference_out,
832
+ git_repository *repo,
833
+ const char *spec)
834
+ {
835
+ int error;
836
+ size_t identifier_len;
837
+ git_object *obj = NULL;
838
+ git_reference *ref = NULL;
839
+
840
+ if ((error = revparse__ext(&obj, &ref, &identifier_len, repo, spec)) < 0)
841
+ goto cleanup;
842
+
843
+ *object_out = obj;
844
+ *reference_out = ref;
845
+ GIT_UNUSED(identifier_len);
846
+
847
+ return 0;
848
+
849
+ cleanup:
850
+ git_object_free(obj);
851
+ git_reference_free(ref);
852
+ return error;
853
+ }
854
+
855
+ int git_revparse_single(git_object **out, git_repository *repo, const char *spec)
856
+ {
857
+ int error;
858
+ git_object *obj = NULL;
859
+ git_reference *ref = NULL;
860
+
861
+ *out = NULL;
862
+
863
+ if ((error = git_revparse_ext(&obj, &ref, repo, spec)) < 0)
864
+ goto cleanup;
865
+
866
+ git_reference_free(ref);
867
+
868
+ *out = obj;
869
+
870
+ return 0;
871
+
872
+ cleanup:
873
+ git_object_free(obj);
874
+ git_reference_free(ref);
875
+ return error;
876
+ }
871
877
 
872
878
  int git_revparse(
873
879
  git_revspec *revspec,
@@ -909,4 +915,3 @@ int git_revparse(
909
915
 
910
916
  return error;
911
917
  }
912
-
@@ -186,7 +186,7 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
186
186
  data.hide = hide;
187
187
 
188
188
  if (git_reference_foreach_glob(
189
- walk->repo, git_buf_cstr(&buf), GIT_REF_LISTALL, push_glob_cb, &data) < 0)
189
+ walk->repo, git_buf_cstr(&buf), push_glob_cb, &data) < 0)
190
190
  goto on_error;
191
191
 
192
192
  regfree(&preg);
@@ -9,6 +9,7 @@
9
9
  #include "signature.h"
10
10
  #include "repository.h"
11
11
  #include "git2/common.h"
12
+ #include "posix.h"
12
13
 
13
14
  void git_signature_free(git_signature *sig)
14
15
  {
@@ -35,11 +36,11 @@ static bool contains_angle_brackets(const char *input)
35
36
 
36
37
  static char *extract_trimmed(const char *ptr, size_t len)
37
38
  {
38
- while (len && ptr[0] == ' ') {
39
+ while (len && git__isspace(ptr[0])) {
39
40
  ptr++; len--;
40
41
  }
41
42
 
42
- while (len && ptr[len - 1] == ' ') {
43
+ while (len && git__isspace(ptr[len - 1])) {
43
44
  len--;
44
45
  }
45
46
 
@@ -66,10 +67,12 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
66
67
  p->name = extract_trimmed(name, strlen(name));
67
68
  p->email = extract_trimmed(email, strlen(email));
68
69
 
69
- if (p->name == NULL || p->email == NULL ||
70
- p->name[0] == '\0' || p->email[0] == '\0') {
70
+ if (p->name == NULL || p->email == NULL)
71
+ return -1; /* oom */
72
+
73
+ if (p->name[0] == '\0') {
71
74
  git_signature_free(p);
72
- return -1;
75
+ return signature_error("Signature cannot have an empty name");
73
76
  }
74
77
 
75
78
  p->when.time = time;
@@ -81,9 +84,16 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
81
84
 
82
85
  git_signature *git_signature_dup(const git_signature *sig)
83
86
  {
84
- git_signature *new;
85
- if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < 0)
87
+ git_signature *new = git__calloc(1, sizeof(git_signature));
88
+
89
+ if (new == NULL)
86
90
  return NULL;
91
+
92
+ new->name = git__strdup(sig->name);
93
+ new->email = git__strdup(sig->email);
94
+ new->when.time = sig->when.time;
95
+ new->when.offset = sig->when.offset;
96
+
87
97
  return new;
88
98
  }
89
99
 
@@ -164,9 +174,11 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
164
174
 
165
175
  tz_start = time_end + 1;
166
176
 
167
- if ((tz_start[0] != '-' && tz_start[0] != '+') ||
168
- git__strtol32(&offset, tz_start + 1, &tz_end, 10) < 0)
169
- return signature_error("malformed timezone");
177
+ if ((tz_start[0] != '-' && tz_start[0] != '+') ||
178
+ git__strtol32(&offset, tz_start + 1, &tz_end, 10) < 0) {
179
+ //malformed timezone, just assume it's zero
180
+ offset = 0;
181
+ }
170
182
 
171
183
  hours = offset / 100;
172
184
  mins = offset % 100;
@@ -14,6 +14,7 @@
14
14
  #include "git2/stash.h"
15
15
  #include "git2/status.h"
16
16
  #include "git2/checkout.h"
17
+ #include "git2/index.h"
17
18
  #include "signature.h"
18
19
 
19
20
  static int create_error(int error, const char *msg)
@@ -587,8 +588,10 @@ int git_stash_foreach(
587
588
  const git_reflog_entry *entry;
588
589
 
589
590
  error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE);
590
- if (error == GIT_ENOTFOUND)
591
+ if (error == GIT_ENOTFOUND) {
592
+ giterr_clear();
591
593
  return 0;
594
+ }
592
595
  if (error < 0)
593
596
  goto cleanup;
594
597
 
@@ -651,7 +654,7 @@ int git_stash_drop(
651
654
  const git_reflog_entry *entry;
652
655
 
653
656
  entry = git_reflog_entry_byindex(reflog, 0);
654
-
657
+
655
658
  git_reference_free(stash);
656
659
  error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1);
657
660
  }