rugged 1.9.0 → 1.9.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +4 -4
  3. data/ext/rugged/rugged.c +12 -1
  4. data/ext/rugged/rugged_blame.c +22 -6
  5. data/ext/rugged/rugged_blob.c +24 -9
  6. data/ext/rugged/rugged_branch.c +10 -7
  7. data/ext/rugged/rugged_branch_collection.c +8 -6
  8. data/ext/rugged/rugged_commit.c +7 -6
  9. data/ext/rugged/rugged_config.c +20 -11
  10. data/ext/rugged/rugged_diff.c +26 -12
  11. data/ext/rugged/rugged_diff_hunk.c +2 -1
  12. data/ext/rugged/rugged_index.c +39 -29
  13. data/ext/rugged/rugged_note.c +7 -6
  14. data/ext/rugged/rugged_object.c +3 -2
  15. data/ext/rugged/rugged_patch.c +23 -9
  16. data/ext/rugged/rugged_rebase.c +22 -10
  17. data/ext/rugged/rugged_reference.c +22 -13
  18. data/ext/rugged/rugged_reference_collection.c +9 -7
  19. data/ext/rugged/rugged_remote.c +23 -12
  20. data/ext/rugged/rugged_remote_collection.c +11 -9
  21. data/ext/rugged/rugged_repo.c +60 -45
  22. data/ext/rugged/rugged_revwalk.c +22 -12
  23. data/ext/rugged/rugged_submodule.c +23 -20
  24. data/ext/rugged/rugged_submodule_collection.c +20 -9
  25. data/ext/rugged/rugged_tag.c +6 -4
  26. data/ext/rugged/rugged_tag_collection.c +7 -5
  27. data/ext/rugged/rugged_tree.c +27 -15
  28. data/lib/rugged/version.rb +1 -1
  29. data/vendor/libgit2/AUTHORS +2 -0
  30. data/vendor/libgit2/CMakeLists.txt +1 -1
  31. data/vendor/libgit2/COPYING +83 -11
  32. data/vendor/libgit2/cmake/DefaultCFlags.cmake +4 -1
  33. data/vendor/libgit2/cmake/SelectRegex.cmake +8 -3
  34. data/vendor/libgit2/cmake/SelectSSH.cmake +9 -3
  35. data/vendor/libgit2/deps/pcre2/CMakeLists.txt +110 -0
  36. data/vendor/libgit2/deps/pcre2/LICENCE.md +104 -0
  37. data/vendor/libgit2/deps/pcre2/config.h.in +54 -0
  38. data/vendor/libgit2/deps/pcre2/pcre2.h +1079 -0
  39. data/vendor/libgit2/deps/pcre2/pcre2_auto_possess.c +1416 -0
  40. data/vendor/libgit2/deps/{pcre/pcre_chartables.c → pcre2/pcre2_chartables.c} +41 -47
  41. data/vendor/libgit2/deps/{pcre/pcre_ord2utf8.c → pcre2/pcre2_chkdint.c} +36 -36
  42. data/vendor/libgit2/deps/pcre2/pcre2_compile.c +11345 -0
  43. data/vendor/libgit2/deps/pcre2/pcre2_compile.h +356 -0
  44. data/vendor/libgit2/deps/pcre2/pcre2_compile_cgroup.c +632 -0
  45. data/vendor/libgit2/deps/pcre2/pcre2_compile_class.c +2777 -0
  46. data/vendor/libgit2/deps/pcre2/pcre2_config.c +250 -0
  47. data/vendor/libgit2/deps/pcre2/pcre2_context.c +557 -0
  48. data/vendor/libgit2/deps/pcre2/pcre2_convert.c +1263 -0
  49. data/vendor/libgit2/deps/{pcre/pcre_dfa_exec.c → pcre2/pcre2_dfa_match.c} +1402 -943
  50. data/vendor/libgit2/deps/pcre2/pcre2_error.c +384 -0
  51. data/vendor/libgit2/deps/pcre2/pcre2_extuni.c +159 -0
  52. data/vendor/libgit2/deps/pcre2/pcre2_find_bracket.c +217 -0
  53. data/vendor/libgit2/deps/pcre2/pcre2_fuzzsupport.c +844 -0
  54. data/vendor/libgit2/deps/pcre2/pcre2_internal.h +2353 -0
  55. data/vendor/libgit2/deps/pcre2/pcre2_intmodedep.h +1044 -0
  56. data/vendor/libgit2/deps/pcre2/pcre2_maketables.c +177 -0
  57. data/vendor/libgit2/deps/pcre2/pcre2_match.c +8244 -0
  58. data/vendor/libgit2/deps/pcre2/pcre2_match_data.c +184 -0
  59. data/vendor/libgit2/deps/pcre2/pcre2_match_next.c +171 -0
  60. data/vendor/libgit2/deps/{pcre/pcre_newline.c → pcre2/pcre2_newline.c} +92 -63
  61. data/vendor/libgit2/deps/{pcre/pcre_refcount.c → pcre2/pcre2_ord2utf.c} +64 -38
  62. data/vendor/libgit2/deps/pcre2/pcre2_pattern_info.c +430 -0
  63. data/vendor/libgit2/deps/pcre2/pcre2_printint_inc.h +1098 -0
  64. data/vendor/libgit2/deps/pcre2/pcre2_script_run.c +344 -0
  65. data/vendor/libgit2/deps/pcre2/pcre2_serialize.c +284 -0
  66. data/vendor/libgit2/deps/pcre2/pcre2_string_utils.c +199 -0
  67. data/vendor/libgit2/deps/pcre2/pcre2_study.c +2087 -0
  68. data/vendor/libgit2/deps/pcre2/pcre2_substitute.c +1761 -0
  69. data/vendor/libgit2/deps/pcre2/pcre2_substring.c +553 -0
  70. data/vendor/libgit2/deps/pcre2/pcre2_tables.c +310 -0
  71. data/vendor/libgit2/deps/pcre2/pcre2_ucd.c +5805 -0
  72. data/vendor/libgit2/deps/pcre2/pcre2_ucp.h +408 -0
  73. data/vendor/libgit2/deps/pcre2/pcre2_ucptables_inc.h +1596 -0
  74. data/vendor/libgit2/deps/pcre2/pcre2_util.h +179 -0
  75. data/vendor/libgit2/deps/pcre2/pcre2_valid_utf.c +397 -0
  76. data/vendor/libgit2/deps/pcre2/pcre2_xclass.c +547 -0
  77. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +1 -1
  78. data/vendor/libgit2/deps/xdiff/xmerge.c +14 -10
  79. data/vendor/libgit2/include/git2/common.h +13 -1
  80. data/vendor/libgit2/include/git2/deprecated.h +1 -1
  81. data/vendor/libgit2/include/git2/index.h +1 -1
  82. data/vendor/libgit2/include/git2/merge.h +4 -2
  83. data/vendor/libgit2/include/git2/oid.h +0 -1
  84. data/vendor/libgit2/include/git2/proxy.h +2 -3
  85. data/vendor/libgit2/include/git2/remote.h +19 -7
  86. data/vendor/libgit2/include/git2/stdint.h +1 -1
  87. data/vendor/libgit2/include/git2/sys/transport.h +1 -1
  88. data/vendor/libgit2/include/git2/version.h +4 -2
  89. data/vendor/libgit2/src/cli/CMakeLists.txt +1 -2
  90. data/vendor/libgit2/src/cli/opt.c +3 -3
  91. data/vendor/libgit2/src/cli/opt_usage.c +1 -1
  92. data/vendor/libgit2/src/libgit2/CMakeLists.txt +32 -16
  93. data/vendor/libgit2/src/libgit2/attr_file.c +10 -3
  94. data/vendor/libgit2/src/libgit2/blame.c +6 -0
  95. data/vendor/libgit2/src/libgit2/clone.c +6 -0
  96. data/vendor/libgit2/src/libgit2/commit.c +1 -1
  97. data/vendor/libgit2/src/libgit2/commit_graph.c +1 -2
  98. data/vendor/libgit2/src/libgit2/config.c +1 -1
  99. data/vendor/libgit2/src/libgit2/config_file.c +2 -1
  100. data/vendor/libgit2/src/libgit2/config_mem.c +1 -0
  101. data/vendor/libgit2/src/libgit2/config_parse.c +2 -1
  102. data/vendor/libgit2/src/libgit2/delta.c +13 -1
  103. data/vendor/libgit2/src/libgit2/diff_driver.c +1 -1
  104. data/vendor/libgit2/src/libgit2/diff_stats.c +19 -12
  105. data/vendor/libgit2/src/libgit2/fetchhead.c +1 -1
  106. data/vendor/libgit2/src/libgit2/index.c +8 -8
  107. data/vendor/libgit2/src/libgit2/index.h +3 -0
  108. data/vendor/libgit2/src/libgit2/indexer.c +5 -4
  109. data/vendor/libgit2/src/libgit2/merge.c +1 -1
  110. data/vendor/libgit2/src/libgit2/merge.h +4 -0
  111. data/vendor/libgit2/src/libgit2/merge_file.c +43 -30
  112. data/vendor/libgit2/src/libgit2/message.c +1 -1
  113. data/vendor/libgit2/src/libgit2/midx.c +2 -3
  114. data/vendor/libgit2/src/libgit2/odb.c +2 -6
  115. data/vendor/libgit2/src/libgit2/odb_loose.c +24 -14
  116. data/vendor/libgit2/src/libgit2/oid.c +4 -5
  117. data/vendor/libgit2/src/libgit2/pack-objects.c +2 -4
  118. data/vendor/libgit2/src/libgit2/pack.c +3 -0
  119. data/vendor/libgit2/src/libgit2/refs.c +15 -6
  120. data/vendor/libgit2/src/libgit2/remote.c +4 -1
  121. data/vendor/libgit2/src/libgit2/remote.h +0 -1
  122. data/vendor/libgit2/src/libgit2/repository.c +5 -4
  123. data/vendor/libgit2/src/libgit2/settings.c +9 -0
  124. data/vendor/libgit2/src/libgit2/streams/openssl.c +4 -1
  125. data/vendor/libgit2/src/libgit2/streams/socket.c +30 -0
  126. data/vendor/libgit2/src/libgit2/submodule.c +89 -17
  127. data/vendor/libgit2/src/libgit2/tag.c +3 -1
  128. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +2 -0
  129. data/vendor/libgit2/src/libgit2/transports/credential.c +1 -1
  130. data/vendor/libgit2/src/libgit2/transports/git.c +1 -1
  131. data/vendor/libgit2/src/libgit2/transports/http.c +4 -4
  132. data/vendor/libgit2/src/libgit2/transports/httpclient.c +12 -9
  133. data/vendor/libgit2/src/libgit2/transports/local.c +8 -1
  134. data/vendor/libgit2/src/libgit2/transports/smart.c +5 -5
  135. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +5 -4
  136. data/vendor/libgit2/src/libgit2/transports/ssh_exec.c +57 -18
  137. data/vendor/libgit2/src/libgit2/transports/ssh_libssh2.c +3 -3
  138. data/vendor/libgit2/src/util/CMakeLists.txt +3 -4
  139. data/vendor/libgit2/src/util/fs_path.c +66 -6
  140. data/vendor/libgit2/src/util/fs_path.h +16 -10
  141. data/vendor/libgit2/src/util/futils.h +11 -3
  142. data/vendor/libgit2/src/util/hash/builtin.c +14 -4
  143. data/vendor/libgit2/src/util/hash/openssl.c +0 -4
  144. data/vendor/libgit2/src/util/hash/rfc6234/sha224-256.c +8 -6
  145. data/vendor/libgit2/src/util/hashmap.h +1 -0
  146. data/vendor/libgit2/src/util/net.c +5 -5
  147. data/vendor/libgit2/src/util/process.h +2 -1
  148. data/vendor/libgit2/src/util/regexp.c +27 -12
  149. data/vendor/libgit2/src/util/regexp.h +7 -2
  150. data/vendor/libgit2/src/util/runtime.c +2 -2
  151. data/vendor/libgit2/src/util/str.c +18 -6
  152. data/vendor/libgit2/src/util/str.h +5 -3
  153. data/vendor/libgit2/src/util/unix/process.c +92 -15
  154. data/vendor/libgit2/src/util/util.c +16 -3
  155. data/vendor/libgit2/src/util/util.h +1 -0
  156. data/vendor/libgit2/src/util/win32/path_w32.c +81 -5
  157. data/vendor/libgit2/src/util/win32/process.c +22 -6
  158. metadata +59 -41
  159. data/vendor/libgit2/deps/pcre/CMakeLists.txt +0 -141
  160. data/vendor/libgit2/deps/pcre/COPYING +0 -5
  161. data/vendor/libgit2/deps/pcre/LICENCE +0 -93
  162. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +0 -22
  163. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +0 -17
  164. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +0 -58
  165. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +0 -29
  166. data/vendor/libgit2/deps/pcre/config.h.in +0 -57
  167. data/vendor/libgit2/deps/pcre/pcre.h +0 -641
  168. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +0 -319
  169. data/vendor/libgit2/deps/pcre/pcre_compile.c +0 -9815
  170. data/vendor/libgit2/deps/pcre/pcre_config.c +0 -190
  171. data/vendor/libgit2/deps/pcre/pcre_exec.c +0 -7173
  172. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +0 -245
  173. data/vendor/libgit2/deps/pcre/pcre_get.c +0 -669
  174. data/vendor/libgit2/deps/pcre/pcre_globals.c +0 -86
  175. data/vendor/libgit2/deps/pcre/pcre_internal.h +0 -2787
  176. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +0 -11913
  177. data/vendor/libgit2/deps/pcre/pcre_maketables.c +0 -156
  178. data/vendor/libgit2/deps/pcre/pcre_printint.c +0 -834
  179. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +0 -211
  180. data/vendor/libgit2/deps/pcre/pcre_study.c +0 -1686
  181. data/vendor/libgit2/deps/pcre/pcre_tables.c +0 -727
  182. data/vendor/libgit2/deps/pcre/pcre_ucd.c +0 -3644
  183. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +0 -301
  184. data/vendor/libgit2/deps/pcre/pcre_version.c +0 -98
  185. data/vendor/libgit2/deps/pcre/pcre_xclass.c +0 -268
  186. data/vendor/libgit2/deps/pcre/pcreposix.c +0 -420
  187. data/vendor/libgit2/deps/pcre/pcreposix.h +0 -117
  188. data/vendor/libgit2/deps/pcre/ucp.h +0 -224
@@ -77,6 +77,7 @@ static void submodule_get_index_status(unsigned int *, git_submodule *);
77
77
  static void submodule_get_wd_status(unsigned int *, git_submodule *, git_repository *, git_submodule_ignore_t);
78
78
  static void submodule_update_from_index_entry(git_submodule *sm, const git_index_entry *ie);
79
79
  static void submodule_update_from_head_data(git_submodule *sm, mode_t mode, const git_oid *id);
80
+ static int path_is_valid(git_repository *repo, const char *path);
80
81
 
81
82
  static int submodule_cmp(const void *a, const void *b)
82
83
  {
@@ -221,6 +222,7 @@ static int load_submodule_names(git_submodule_namemap **out, git_repository *rep
221
222
 
222
223
  while ((error = git_config_next(&entry, iter)) == 0) {
223
224
  const char *fdot, *ldot;
225
+
224
226
  fdot = strchr(entry->name, '.');
225
227
  ldot = strrchr(entry->name, '.');
226
228
 
@@ -233,6 +235,7 @@ static int load_submodule_names(git_submodule_namemap **out, git_repository *rep
233
235
 
234
236
  git_str_clear(&buf);
235
237
  git_str_put(&buf, fdot + 1, ldot - fdot - 1);
238
+
236
239
  isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
237
240
  if (isvalid < 0) {
238
241
  error = isvalid;
@@ -241,6 +244,14 @@ static int load_submodule_names(git_submodule_namemap **out, git_repository *rep
241
244
  if (!isvalid)
242
245
  continue;
243
246
 
247
+ isvalid = path_is_valid(repo, entry->value);
248
+ if (isvalid < 0) {
249
+ error = isvalid;
250
+ goto out;
251
+ }
252
+ if (!isvalid)
253
+ continue;
254
+
244
255
  if ((value = git__strdup(entry->value)) == NULL) {
245
256
  error = -1;
246
257
  goto out;
@@ -319,9 +330,9 @@ int git_submodule__lookup_with_cache(
319
330
  const char *name, /* trailing slash is allowed */
320
331
  git_submodule_cache *cache)
321
332
  {
322
- int error;
323
- unsigned int location;
324
333
  git_submodule *sm;
334
+ unsigned int location;
335
+ int error;
325
336
 
326
337
  GIT_ASSERT_ARG(repo);
327
338
  GIT_ASSERT_ARG(name);
@@ -344,7 +355,17 @@ int git_submodule__lookup_with_cache(
344
355
  if ((error = submodule_alloc(&sm, repo, name)) < 0)
345
356
  return error;
346
357
 
347
- if ((error = git_submodule_reload(sm, false)) < 0) {
358
+ /*
359
+ * Only try to reload if they gave us a valid _name_; if this is a
360
+ * path, we'll do some lookups then try to reload to populate.
361
+ */
362
+ if (git_submodule_name_is_valid(sm->repo, name, 0) <= 0) {
363
+ error = GIT_ENOTFOUND;
364
+ } else {
365
+ error = git_submodule_reload(sm, false);
366
+ }
367
+
368
+ if (error < 0 && error != GIT_ENOTFOUND) {
348
369
  git_submodule_free(sm);
349
370
  return error;
350
371
  }
@@ -403,6 +424,7 @@ int git_submodule__lookup_with_cache(
403
424
  /* If we still haven't found it, do the WD check */
404
425
  if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) {
405
426
  git_submodule_free(sm);
427
+ git_error_set(GIT_ERROR_SUBMODULE, "invalid submodule name: '%s'", name);
406
428
  error = GIT_ENOTFOUND;
407
429
 
408
430
  /* If it's not configured, we still check if there's a repo at the path */
@@ -454,6 +476,27 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag
454
476
  return isvalid;
455
477
  }
456
478
 
479
+ static int path_is_valid(git_repository *repo, const char *path)
480
+ {
481
+ git_str buf = GIT_STR_INIT;
482
+ int flags = GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS &
483
+ ~GIT_FS_PATH_REJECT_EMPTY_COMPONENT;
484
+ int error, isvalid;
485
+
486
+ /* Avoid allocating a new string if we can avoid it */
487
+ if (strchr(path, '\\') != NULL) {
488
+ if ((error = git_fs_path_normalize_slashes(&buf, path)) < 0)
489
+ return error;
490
+ } else {
491
+ git_str_attach_notowned(&buf, path, strlen(path));
492
+ }
493
+
494
+ isvalid = git_path_is_valid(repo, buf.ptr, 0, flags);
495
+ git_str_dispose(&buf);
496
+
497
+ return isvalid;
498
+ }
499
+
457
500
  static void submodule_free_dup(void *sm)
458
501
  {
459
502
  git_submodule_free(sm);
@@ -1075,16 +1118,23 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
1075
1118
  git_commit_free(head);
1076
1119
 
1077
1120
  /* add it */
1078
- error = git_index_add(index, &entry);
1121
+ if ((error = git_index_add(index, &entry)) < 0)
1122
+ goto cleanup;
1123
+
1124
+ /* Adding implies conflict was resolved, move conflict entries to REUC */
1125
+ if ((error = git_index__conflict_to_reuc(index, entry.path)) < 0 && error != GIT_ENOTFOUND)
1126
+ goto cleanup;
1079
1127
 
1080
1128
  /* write it, if requested */
1081
- if (!error && write_index) {
1082
- error = git_index_write(index);
1129
+ if (write_index) {
1130
+ if ((error = git_index_write(index)) < 0)
1131
+ goto cleanup;
1083
1132
 
1084
- if (!error)
1085
- git_oid_cpy(&sm->index_oid, &sm->wd_oid);
1133
+ git_oid_cpy(&sm->index_oid, &sm->wd_oid);
1086
1134
  }
1087
1135
 
1136
+ error = 0;
1137
+
1088
1138
  cleanup:
1089
1139
  git_repository_free(sm_repo);
1090
1140
  git_str_dispose(&path);
@@ -1714,18 +1764,34 @@ static int submodule_update_head(git_submodule *submodule)
1714
1764
  return 0;
1715
1765
  }
1716
1766
 
1767
+ static int submodule_name_error(const char *name)
1768
+ {
1769
+ git_error_set(GIT_ERROR_SUBMODULE,
1770
+ "invalid value for submodule name: '%s'", name);
1771
+ return GIT_EINVALID;
1772
+ }
1773
+
1774
+ static int submodule_config_error(const char *property, const char *value)
1775
+ {
1776
+ git_error_set(GIT_ERROR_SUBMODULE,
1777
+ "invalid value for submodule '%s' property: '%s'", property, value);
1778
+ return GIT_EINVALID;
1779
+ }
1780
+
1717
1781
  int git_submodule_reload(git_submodule *sm, int force)
1718
1782
  {
1719
1783
  git_config *mods = NULL;
1720
- int error;
1784
+ int valid, error = 0;
1721
1785
 
1722
1786
  GIT_UNUSED(force);
1723
1787
 
1724
1788
  GIT_ASSERT_ARG(sm);
1725
1789
 
1726
- if ((error = git_submodule_name_is_valid(sm->repo, sm->name, 0)) <= 0)
1790
+ if ((valid = git_submodule_name_is_valid(sm->repo, sm->name, 0)) <= 0) {
1727
1791
  /* This should come with a warning, but we've no API for that */
1792
+ error = valid ? valid : submodule_name_error(sm->name);
1728
1793
  goto out;
1794
+ }
1729
1795
 
1730
1796
  if (git_repository_is_bare(sm->repo))
1731
1797
  goto out;
@@ -1748,6 +1814,12 @@ int git_submodule_reload(git_submodule *sm, int force)
1748
1814
  (error = submodule_update_head(sm)) < 0)
1749
1815
  goto out;
1750
1816
 
1817
+ if ((valid = path_is_valid(sm->repo, sm->path)) <= 0) {
1818
+ /* This should come with a warning, but we've no API for that */
1819
+ error = valid ? valid : submodule_config_error("path", sm->path);
1820
+ goto out;
1821
+ }
1822
+
1751
1823
  out:
1752
1824
  git_config_free(mods);
1753
1825
  return error;
@@ -1931,13 +2003,6 @@ void git_submodule_free(git_submodule *sm)
1931
2003
  GIT_REFCOUNT_DEC(sm, submodule_release);
1932
2004
  }
1933
2005
 
1934
- static int submodule_config_error(const char *property, const char *value)
1935
- {
1936
- git_error_set(GIT_ERROR_INVALID,
1937
- "invalid value for submodule '%s' property: '%s'", property, value);
1938
- return -1;
1939
- }
1940
-
1941
2006
  int git_submodule_parse_ignore(git_submodule_ignore_t *out, const char *value)
1942
2007
  {
1943
2008
  int val;
@@ -2136,6 +2201,13 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
2136
2201
  goto done;
2137
2202
  }
2138
2203
 
2204
+ isvalid = path_is_valid(data->repo, sm->path);
2205
+ if (isvalid <= 0) {
2206
+ git_submodule_free(sm);
2207
+ error = isvalid;
2208
+ goto done;
2209
+ }
2210
+
2139
2211
  if ((error = git_submodule_cache_put(cache, sm->name, sm)) < 0)
2140
2212
  goto done;
2141
2213
 
@@ -263,8 +263,10 @@ static bool tag_name_is_valid(const char *tag_name)
263
263
  /*
264
264
  * Discourage tag name starting with dash,
265
265
  * https://github.com/git/git/commit/4f0accd638b8d2
266
+ * and refuse to use HEAD as a tagname,
267
+ * https://github.com/git/git/commit/bbd445d5efd415
266
268
  */
267
- return tag_name[0] != '-';
269
+ return tag_name[0] != '-' && git__strcmp(tag_name, "HEAD");
268
270
  }
269
271
 
270
272
  static int git_tag_create__internal(
@@ -324,12 +324,14 @@ static int sspi_init_context(
324
324
  return 0;
325
325
  }
326
326
 
327
+ #if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK) || defined(GIT_WIN32)
327
328
  int git_http_auth_negotiate(
328
329
  git_http_auth_context **out,
329
330
  const git_net_url *url)
330
331
  {
331
332
  return sspi_init_context(out, GIT_HTTP_AUTH_NEGOTIATE, url);
332
333
  }
334
+ #endif
333
335
 
334
336
  int git_http_auth_ntlm(
335
337
  git_http_auth_context **out,
@@ -161,7 +161,7 @@ static void ssh_custom_free(struct git_credential *cred)
161
161
 
162
162
  if (c->publickey) {
163
163
  /* Zero the memory which previously held the publickey */
164
- size_t key_len = strlen(c->publickey);
164
+ size_t key_len = c->publickey_len;
165
165
  git__memzero(c->publickey, key_len);
166
166
  git__free(c->publickey);
167
167
  }
@@ -39,7 +39,7 @@ typedef struct {
39
39
  */
40
40
  static int gen_proto(git_str *request, const char *cmd, const char *url)
41
41
  {
42
- char *delim, *repo;
42
+ const char *delim, *repo;
43
43
  char host[] = "host=";
44
44
  size_t len;
45
45
 
@@ -130,12 +130,12 @@ GIT_INLINE(void) free_cred(git_credential **cred)
130
130
  static int handle_auth(
131
131
  http_server *server,
132
132
  const char *server_type,
133
- const char *url,
134
133
  unsigned int allowed_schemetypes,
135
134
  unsigned int allowed_credtypes,
136
135
  git_credential_acquire_cb callback,
137
136
  void *callback_payload)
138
137
  {
138
+ git_str server_url = GIT_STR_INIT;
139
139
  int error = 1;
140
140
 
141
141
  if (server->cred)
@@ -154,7 +154,8 @@ static int handle_auth(
154
154
  }
155
155
 
156
156
  if (error > 0 && callback) {
157
- error = callback(&server->cred, url, server->url.username, allowed_credtypes, callback_payload);
157
+ if ((error = git_net_url_fmt(&server_url, &server->url)) == 0)
158
+ error = callback(&server->cred, server_url.ptr, server->url.username, allowed_credtypes, callback_payload);
158
159
 
159
160
  /* treat GIT_PASSTHROUGH as if callback isn't set */
160
161
  if (error == GIT_PASSTHROUGH)
@@ -169,6 +170,7 @@ static int handle_auth(
169
170
  if (!error)
170
171
  server->auth_schemetypes = allowed_schemetypes;
171
172
 
173
+ git_str_dispose(&server_url);
172
174
  return error;
173
175
  }
174
176
 
@@ -188,7 +190,6 @@ GIT_INLINE(int) handle_remote_auth(
188
190
  return handle_auth(
189
191
  &transport->server,
190
192
  SERVER_TYPE_REMOTE,
191
- transport->owner->url,
192
193
  response->server_auth_schemetypes,
193
194
  response->server_auth_credtypes,
194
195
  connect_opts->callbacks.credentials,
@@ -211,7 +212,6 @@ GIT_INLINE(int) handle_proxy_auth(
211
212
  return handle_auth(
212
213
  &transport->proxy,
213
214
  SERVER_TYPE_PROXY,
214
- connect_opts->proxy_opts.url,
215
215
  response->server_auth_schemetypes,
216
216
  response->proxy_auth_credtypes,
217
217
  connect_opts->proxy_opts.credentials,
@@ -379,7 +379,7 @@ static int on_headers_complete(git_http_parser *parser)
379
379
  ctx->response->resend_credentials = resend_needed(ctx->client,
380
380
  ctx->response);
381
381
 
382
- if (ctx->response->content_type || ctx->response->chunked)
382
+ if (ctx->response->content_length || ctx->response->chunked)
383
383
  ctx->client->state = READING_BODY;
384
384
  else
385
385
  ctx->client->state = DONE;
@@ -553,7 +553,7 @@ static int apply_credentials(
553
553
  {
554
554
  git_http_auth_context *auth = server->auth_context;
555
555
  git_vector *challenges = &server->auth_challenges;
556
- const char *challenge;
556
+ const char *challenge = NULL;
557
557
  git_str token = GIT_STR_INIT;
558
558
  int error = 0;
559
559
 
@@ -1243,13 +1243,16 @@ GIT_INLINE(int) client_read_and_parse(git_http_client *client)
1243
1243
  }
1244
1244
 
1245
1245
  /*
1246
- * See if we've consumed the entire response body. If the client was
1247
- * reading the body but did not consume it entirely, it's possible that
1248
- * they knew that the stream had finished (in a git response, seeing a
1249
- * final flush) and stopped reading. But if the response was chunked,
1250
- * we may have not consumed the final chunk marker. Consume it to
1251
- * ensure that we don't have it waiting in our socket. If there's
1252
- * more than just a chunk marker, close the connection.
1246
+ * Try to consume any remaining response body. The client may have
1247
+ * decided that it did not need to consume the entire response body.
1248
+ * For example, the client saw a redirect in the header and ignored
1249
+ * the body. Or the client saw a particular sequence (like a final
1250
+ * flush in a git response) and stopped reading (but there were
1251
+ * additional response bytes, perhaps because the response was chunked).
1252
+ * Do one more read to try to clear this out; this takes care of small
1253
+ * remainders, like a chunk response or a small redirect message. If
1254
+ * there is too much data, we'll just leave it and close the
1255
+ * connection.
1253
1256
  */
1254
1257
  static void complete_response_body(git_http_client *client)
1255
1258
  {
@@ -41,6 +41,9 @@ typedef struct {
41
41
  git_vector refs;
42
42
  unsigned connected : 1,
43
43
  have_refs : 1;
44
+ #ifdef GIT_EXPERIMENTAL_SHA256
45
+ git_oid_t oid_type;
46
+ #endif
44
47
  } transport_local;
45
48
 
46
49
  static void free_head(git_remote_head *head)
@@ -231,6 +234,10 @@ static int local_connect(
231
234
 
232
235
  t->repo = repo;
233
236
 
237
+ #ifdef GIT_EXPERIMENTAL_SHA256
238
+ t->oid_type = repo->oid_type;
239
+ #endif
240
+
234
241
  if (store_refs(t) < 0)
235
242
  return -1;
236
243
 
@@ -267,7 +274,7 @@ static int local_oid_type(git_oid_t *out, git_transport *transport)
267
274
  {
268
275
  transport_local *t = (transport_local *)transport;
269
276
 
270
- *out = t->repo->oid_type;
277
+ *out = t->oid_type;
271
278
 
272
279
  return 0;
273
280
  }
@@ -64,13 +64,13 @@ GIT_INLINE(int) git_smart__reset_stream(transport_smart *t, bool close_subtransp
64
64
 
65
65
  if (t->wrapped->close(t->wrapped) < 0)
66
66
  return -1;
67
- }
68
67
 
69
- git__free(t->caps.object_format);
70
- t->caps.object_format = NULL;
68
+ git__free(t->caps.object_format);
69
+ t->caps.object_format = NULL;
71
70
 
72
- git__free(t->caps.agent);
73
- t->caps.agent = NULL;
71
+ git__free(t->caps.agent);
72
+ t->caps.agent = NULL;
73
+ }
74
74
 
75
75
  return 0;
76
76
  }
@@ -236,15 +236,16 @@ static int set_data(
236
236
  len > (size_t)((caps - line) + 1)) {
237
237
  caps++;
238
238
 
239
- if (strncmp(caps, "object-format=", CONST_STRLEN("object-format=")) == 0)
239
+ if (len - (caps - line) >= CONST_STRLEN("object-format=") &&
240
+ strncmp(caps, "object-format=", CONST_STRLEN("object-format=")) == 0)
240
241
  format_str = caps + CONST_STRLEN("object-format=");
241
- else if ((format_str = strstr(caps, " object-format=")) != NULL)
242
+ else if ((format_str = git__memmem(caps, len - (caps - line), " object-format=", CONST_STRLEN(" object-format="))) != NULL)
242
243
  format_str += CONST_STRLEN(" object-format=");
243
244
  }
244
245
 
245
246
  if (format_str) {
246
- if ((eos = strchr(format_str, ' ')) == NULL)
247
- eos = strchr(format_str, '\0');
247
+ if ((eos = memchr(format_str, ' ', len - (format_str - line))) == NULL)
248
+ eos = memchr(format_str, '\0', len - (format_str - line));
248
249
 
249
250
  GIT_ASSERT(eos);
250
251
 
@@ -120,7 +120,8 @@ GIT_INLINE(int) ensure_transport_state(
120
120
  }
121
121
 
122
122
  static int get_ssh_cmdline(
123
- git_str *out,
123
+ git_vector *args,
124
+ bool *use_shell,
124
125
  ssh_exec_subtransport *transport,
125
126
  git_net_url *url,
126
127
  const char *command)
@@ -128,7 +129,8 @@ static int get_ssh_cmdline(
128
129
  git_remote *remote = ((transport_smart *)transport->owner)->owner;
129
130
  git_repository *repo = remote->repo;
130
131
  git_config *cfg;
131
- git_str ssh_cmd = GIT_STR_INIT;
132
+ git_str ssh_cmd = GIT_STR_INIT, url_and_host = GIT_STR_INIT,
133
+ remote_cmd = GIT_STR_INIT;
132
134
  const char *default_ssh_cmd = "ssh";
133
135
  int error;
134
136
 
@@ -151,25 +153,57 @@ static int get_ssh_cmdline(
151
153
  if ((error = git_repository_config_snapshot(&cfg, repo)) < 0)
152
154
  return error;
153
155
 
154
- if ((error = git__getenv(&ssh_cmd, "GIT_SSH")) == 0)
155
- ;
156
+ if ((error = git__getenv(&ssh_cmd, "GIT_SSH_COMMAND")) == 0)
157
+ *use_shell = true;
158
+ else if (error != GIT_ENOTFOUND)
159
+ goto done;
160
+ else if ((error = git__getenv(&ssh_cmd, "GIT_SSH")) == 0)
161
+ *use_shell = false;
156
162
  else if (error != GIT_ENOTFOUND)
157
163
  goto done;
158
164
  else if ((error = git_config__get_string_buf(&ssh_cmd, cfg, "core.sshcommand")) < 0 && error != GIT_ENOTFOUND)
159
165
  goto done;
160
166
 
161
- error = git_str_printf(out, "%s %s %s \"%s%s%s\" \"%s\" \"%s\"",
162
- ssh_cmd.size > 0 ? ssh_cmd.ptr : default_ssh_cmd,
163
- url->port_specified ? "-p" : "",
164
- url->port_specified ? url->port : "",
165
- url->username ? url->username : "",
166
- url->username ? "@" : "",
167
- url->host,
168
- command,
169
- url->path);
167
+ git_error_clear();
168
+
169
+ if (!ssh_cmd.size &&
170
+ git_str_puts(&ssh_cmd, default_ssh_cmd) < 0)
171
+ goto done;
172
+
173
+ if ((error = git_vector_insert(args, git_str_detach(&ssh_cmd))) < 0)
174
+ goto done;
175
+
176
+ if (url->port_specified) {
177
+ char *p = git__strdup("-p");
178
+ char *port = git__strdup(url->port);
179
+
180
+ if (!p || !port ||
181
+ (error = git_vector_insert(args, p)) < 0 ||
182
+ (error = git_vector_insert(args, port)) < 0)
183
+ goto done;
184
+ }
185
+
186
+ if (url->username) {
187
+ if ((error = git_str_puts(&url_and_host, url->username)) < 0 ||
188
+ (error = git_str_putc(&url_and_host, '@')) < 0)
189
+ goto done;
190
+ }
191
+
192
+ if ((error = git_str_puts(&url_and_host, url->host)) < 0 ||
193
+ (error = git_vector_insert(args, git_str_detach(&url_and_host))) < 0)
194
+ goto done;
195
+
196
+ if ((error = git_str_puts(&remote_cmd, command)) < 0 ||
197
+ (error = git_str_puts(&remote_cmd, " '")) < 0 ||
198
+ (error = git_str_puts_escaped(&remote_cmd, url->path, "'!", "'\\", "'")) < 0 ||
199
+ (error = git_str_puts(&remote_cmd, "'")) < 0 ||
200
+ (error = git_vector_insert(args, git_str_detach(&remote_cmd))) < 0)
201
+ goto done;
170
202
 
171
203
  done:
172
204
  git_str_dispose(&ssh_cmd);
205
+ git_str_dispose(&url_and_host);
206
+ git_str_dispose(&remote_cmd);
173
207
  git_config_free(cfg);
174
208
  return error;
175
209
  }
@@ -183,7 +217,8 @@ static int start_ssh(
183
217
 
184
218
  git_process_options process_opts = GIT_PROCESS_OPTIONS_INIT;
185
219
  git_net_url url = GIT_NET_URL_INIT;
186
- git_str ssh_cmdline = GIT_STR_INIT;
220
+ git_vector args = GIT_VECTOR_INIT;
221
+ bool use_shell = false;
187
222
  const char *command;
188
223
  int error;
189
224
 
@@ -214,11 +249,15 @@ static int start_ssh(
214
249
  if (error < 0)
215
250
  goto done;
216
251
 
217
- if ((error = get_ssh_cmdline(&ssh_cmdline, transport, &url, command)) < 0)
252
+ if ((error = get_ssh_cmdline(&args, &use_shell,
253
+ transport, &url, command)) < 0)
218
254
  goto done;
219
255
 
220
- if ((error = git_process_new_from_cmdline(&transport->process,
221
- ssh_cmdline.ptr, env, ARRAY_SIZE(env), &process_opts)) < 0 ||
256
+ process_opts.use_shell = use_shell;
257
+
258
+ if ((error = git_process_new(&transport->process,
259
+ (const char **)args.contents, args.length,
260
+ env, ARRAY_SIZE(env), &process_opts)) < 0 ||
222
261
  (error = git_process_start(transport->process)) < 0) {
223
262
  git_process_free(transport->process);
224
263
  transport->process = NULL;
@@ -226,7 +265,7 @@ static int start_ssh(
226
265
  }
227
266
 
228
267
  done:
229
- git_str_dispose(&ssh_cmdline);
268
+ git_vector_dispose_deep(&args);
230
269
  git_net_url_dispose(&url);
231
270
  return error;
232
271
  }
@@ -366,7 +366,7 @@ static int _git_ssh_authenticate_session(
366
366
  default:
367
367
  rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
368
368
  }
369
- } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
369
+ } while (LIBSSH2_ERROR_EAGAIN == rc);
370
370
 
371
371
  if (rc == LIBSSH2_ERROR_PASSWORD_EXPIRED ||
372
372
  rc == LIBSSH2_ERROR_AUTHENTICATION_FAILED ||
@@ -556,7 +556,7 @@ static int _git_ssh_session_create(
556
556
  if (git_str_len(&prefs) > 0) {
557
557
  do {
558
558
  rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, git_str_cstr(&prefs));
559
- } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
559
+ } while (LIBSSH2_ERROR_EAGAIN == rc);
560
560
  if (rc != LIBSSH2_ERROR_NONE) {
561
561
  ssh_error(s, "failed to set hostkey preference");
562
562
  goto on_error;
@@ -566,7 +566,7 @@ static int _git_ssh_session_create(
566
566
 
567
567
  do {
568
568
  rc = libssh2_session_handshake(s, socket->s);
569
- } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
569
+ } while (LIBSSH2_ERROR_EAGAIN == rc);
570
570
 
571
571
  if (rc != LIBSSH2_ERROR_NONE) {
572
572
  ssh_error(s, "failed to start SSH session");
@@ -2,13 +2,12 @@
2
2
 
3
3
  add_library(util OBJECT)
4
4
 
5
- configure_file(git2_features.h.in git2_features.h)
5
+ configure_file(git2_features.h.in "${PROJECT_BINARY_DIR}/gen_headers/git2_features.h")
6
6
 
7
7
  set(UTIL_INCLUDES
8
- "${PROJECT_BINARY_DIR}/src/util"
9
- "${PROJECT_BINARY_DIR}/include"
10
8
  "${PROJECT_SOURCE_DIR}/src/util"
11
- "${PROJECT_SOURCE_DIR}/include")
9
+ "${PROJECT_SOURCE_DIR}/include"
10
+ "${PROJECT_BINARY_DIR}/gen_headers")
12
11
 
13
12
  file(GLOB UTIL_SRC *.c *.h allocators/*.c allocators/*.h hash.h)
14
13
  list(SORT UTIL_SRC)