rugged 0.27.5 → 0.27.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +2 -2
  4. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
  5. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +2 -0
  6. data/vendor/libgit2/include/git2.h +1 -0
  7. data/vendor/libgit2/include/git2/attr.h +18 -7
  8. data/vendor/libgit2/include/git2/blame.h +39 -22
  9. data/vendor/libgit2/include/git2/blob.h +1 -1
  10. data/vendor/libgit2/include/git2/branch.h +1 -1
  11. data/vendor/libgit2/include/git2/buffer.h +14 -2
  12. data/vendor/libgit2/include/git2/checkout.h +13 -12
  13. data/vendor/libgit2/include/git2/cherrypick.h +6 -4
  14. data/vendor/libgit2/include/git2/clone.h +8 -6
  15. data/vendor/libgit2/include/git2/commit.h +28 -0
  16. data/vendor/libgit2/include/git2/common.h +27 -0
  17. data/vendor/libgit2/include/git2/config.h +1 -0
  18. data/vendor/libgit2/include/git2/describe.h +30 -7
  19. data/vendor/libgit2/include/git2/diff.h +32 -22
  20. data/vendor/libgit2/include/git2/errors.h +1 -0
  21. data/vendor/libgit2/include/git2/ignore.h +2 -2
  22. data/vendor/libgit2/include/git2/mailmap.h +115 -0
  23. data/vendor/libgit2/include/git2/merge.h +10 -8
  24. data/vendor/libgit2/include/git2/proxy.h +9 -5
  25. data/vendor/libgit2/include/git2/rebase.h +7 -4
  26. data/vendor/libgit2/include/git2/refspec.h +17 -0
  27. data/vendor/libgit2/include/git2/remote.h +12 -10
  28. data/vendor/libgit2/include/git2/repository.h +7 -5
  29. data/vendor/libgit2/include/git2/revert.h +5 -3
  30. data/vendor/libgit2/include/git2/stash.h +11 -8
  31. data/vendor/libgit2/include/git2/status.h +7 -3
  32. data/vendor/libgit2/include/git2/submodule.h +8 -7
  33. data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
  34. data/vendor/libgit2/include/git2/sys/index.h +3 -0
  35. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  36. data/vendor/libgit2/include/git2/sys/merge.h +6 -1
  37. data/vendor/libgit2/include/git2/sys/path.h +55 -0
  38. data/vendor/libgit2/include/git2/transaction.h +1 -0
  39. data/vendor/libgit2/include/git2/types.h +8 -5
  40. data/vendor/libgit2/include/git2/version.h +2 -2
  41. data/vendor/libgit2/include/git2/worktree.h +46 -11
  42. data/vendor/libgit2/src/CMakeLists.txt +87 -15
  43. data/vendor/libgit2/src/alloc.c +47 -0
  44. data/vendor/libgit2/src/alloc.h +40 -0
  45. data/vendor/libgit2/src/apply.c +4 -4
  46. data/vendor/libgit2/src/attr.c +4 -4
  47. data/vendor/libgit2/src/attr_file.c +8 -7
  48. data/vendor/libgit2/src/attrcache.c +2 -2
  49. data/vendor/libgit2/src/blame.c +11 -4
  50. data/vendor/libgit2/src/blame.h +1 -0
  51. data/vendor/libgit2/src/blame_git.c +8 -5
  52. data/vendor/libgit2/src/blob.c +5 -5
  53. data/vendor/libgit2/src/branch.c +20 -20
  54. data/vendor/libgit2/src/buffer.c +9 -4
  55. data/vendor/libgit2/src/buffer.h +1 -1
  56. data/vendor/libgit2/src/checkout.c +33 -24
  57. data/vendor/libgit2/src/cherrypick.c +3 -3
  58. data/vendor/libgit2/src/clone.c +13 -13
  59. data/vendor/libgit2/src/commit.c +16 -3
  60. data/vendor/libgit2/src/common.h +3 -1
  61. data/vendor/libgit2/src/config.c +3 -3
  62. data/vendor/libgit2/src/config_file.c +193 -241
  63. data/vendor/libgit2/src/config_parse.c +89 -66
  64. data/vendor/libgit2/src/config_parse.h +2 -2
  65. data/vendor/libgit2/src/crlf.c +9 -3
  66. data/vendor/libgit2/src/diff.c +2 -2
  67. data/vendor/libgit2/src/diff_driver.c +3 -3
  68. data/vendor/libgit2/src/diff_file.c +3 -3
  69. data/vendor/libgit2/src/diff_generate.c +4 -3
  70. data/vendor/libgit2/src/diff_print.c +8 -8
  71. data/vendor/libgit2/src/diff_tform.c +1 -1
  72. data/vendor/libgit2/src/diff_xdiff.c +12 -0
  73. data/vendor/libgit2/src/features.h.in +2 -0
  74. data/vendor/libgit2/src/fetch.c +2 -2
  75. data/vendor/libgit2/src/fetchhead.c +5 -5
  76. data/vendor/libgit2/src/filebuf.c +4 -4
  77. data/vendor/libgit2/src/fileops.c +10 -10
  78. data/vendor/libgit2/src/filter.c +3 -3
  79. data/vendor/libgit2/src/global.c +17 -12
  80. data/vendor/libgit2/src/hash.h +2 -0
  81. data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
  82. data/vendor/libgit2/src/hash/hash_mbedtls.h +20 -0
  83. data/vendor/libgit2/src/ignore.c +15 -20
  84. data/vendor/libgit2/src/index.c +77 -36
  85. data/vendor/libgit2/src/index.h +10 -0
  86. data/vendor/libgit2/src/indexer.c +9 -9
  87. data/vendor/libgit2/src/iterator.c +8 -8
  88. data/vendor/libgit2/src/khash.h +3 -1
  89. data/vendor/libgit2/src/mailmap.c +485 -0
  90. data/vendor/libgit2/src/mailmap.h +35 -0
  91. data/vendor/libgit2/src/merge.c +7 -7
  92. data/vendor/libgit2/src/netops.c +5 -5
  93. data/vendor/libgit2/src/notes.c +2 -2
  94. data/vendor/libgit2/src/odb.c +7 -7
  95. data/vendor/libgit2/src/odb_loose.c +13 -13
  96. data/vendor/libgit2/src/odb_pack.c +3 -3
  97. data/vendor/libgit2/src/pack-objects.c +2 -2
  98. data/vendor/libgit2/src/pack.c +5 -5
  99. data/vendor/libgit2/src/pack.h +1 -1
  100. data/vendor/libgit2/src/patch.c +1 -1
  101. data/vendor/libgit2/src/patch_generate.c +2 -2
  102. data/vendor/libgit2/src/patch_parse.c +11 -4
  103. data/vendor/libgit2/src/path.c +42 -66
  104. data/vendor/libgit2/src/path.h +2 -72
  105. data/vendor/libgit2/src/pathspec.c +1 -1
  106. data/vendor/libgit2/src/push.c +2 -2
  107. data/vendor/libgit2/src/rebase.c +19 -22
  108. data/vendor/libgit2/src/refdb_fs.c +65 -34
  109. data/vendor/libgit2/src/refs.c +6 -6
  110. data/vendor/libgit2/src/refspec.c +30 -5
  111. data/vendor/libgit2/src/refspec.h +1 -1
  112. data/vendor/libgit2/src/remote.c +40 -40
  113. data/vendor/libgit2/src/repository.c +63 -59
  114. data/vendor/libgit2/src/reset.c +1 -1
  115. data/vendor/libgit2/src/revert.c +3 -3
  116. data/vendor/libgit2/src/revparse.c +4 -4
  117. data/vendor/libgit2/src/revwalk.c +44 -10
  118. data/vendor/libgit2/src/revwalk.h +2 -1
  119. data/vendor/libgit2/src/settings.c +25 -1
  120. data/vendor/libgit2/src/signature.c +1 -1
  121. data/vendor/libgit2/src/stash.c +80 -34
  122. data/vendor/libgit2/src/status.c +1 -1
  123. data/vendor/libgit2/src/stdalloc.c +120 -0
  124. data/vendor/libgit2/src/stdalloc.h +17 -0
  125. data/vendor/libgit2/src/streams/mbedtls.c +463 -0
  126. data/vendor/libgit2/src/streams/mbedtls.h +20 -0
  127. data/vendor/libgit2/src/streams/openssl.c +132 -34
  128. data/vendor/libgit2/src/streams/openssl.h +0 -107
  129. data/vendor/libgit2/src/streams/tls.c +3 -0
  130. data/vendor/libgit2/src/submodule.c +117 -82
  131. data/vendor/libgit2/src/sysdir.c +4 -4
  132. data/vendor/libgit2/src/tag.c +7 -7
  133. data/vendor/libgit2/src/trace.h +1 -1
  134. data/vendor/libgit2/src/trailer.c +6 -6
  135. data/vendor/libgit2/src/transport.c +2 -2
  136. data/vendor/libgit2/src/transports/auth.c +1 -1
  137. data/vendor/libgit2/src/transports/auth_negotiate.c +2 -2
  138. data/vendor/libgit2/src/transports/git.c +1 -1
  139. data/vendor/libgit2/src/transports/http.c +12 -12
  140. data/vendor/libgit2/src/transports/local.c +7 -7
  141. data/vendor/libgit2/src/transports/smart.c +17 -8
  142. data/vendor/libgit2/src/transports/smart.h +5 -5
  143. data/vendor/libgit2/src/transports/smart_pkt.c +122 -130
  144. data/vendor/libgit2/src/transports/smart_protocol.c +48 -38
  145. data/vendor/libgit2/src/transports/ssh.c +1 -1
  146. data/vendor/libgit2/src/transports/winhttp.c +6 -6
  147. data/vendor/libgit2/src/tree.c +12 -53
  148. data/vendor/libgit2/src/tree.h +0 -12
  149. data/vendor/libgit2/src/util.c +16 -0
  150. data/vendor/libgit2/src/util.h +12 -135
  151. data/vendor/libgit2/src/win32/findfile.c +2 -2
  152. data/vendor/libgit2/src/win32/posix_w32.c +1 -1
  153. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +94 -0
  154. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +28 -75
  155. data/vendor/libgit2/src/worktree.c +64 -43
  156. data/vendor/libgit2/src/worktree.h +2 -0
  157. data/vendor/libgit2/src/xdiff/xdiffi.c +3 -1
  158. metadata +16 -2
@@ -207,7 +207,7 @@ char *git_path_dirname(const char *path)
207
207
 
208
208
  git_path_dirname_r(&buf, path);
209
209
  dirname = git_buf_detach(&buf);
210
- git_buf_free(&buf); /* avoid memleak if error occurs */
210
+ git_buf_dispose(&buf); /* avoid memleak if error occurs */
211
211
 
212
212
  return dirname;
213
213
  }
@@ -219,7 +219,7 @@ char *git_path_basename(const char *path)
219
219
 
220
220
  git_path_basename_r(&buf, path);
221
221
  basename = git_buf_detach(&buf);
222
- git_buf_free(&buf); /* avoid memleak if error occurs */
222
+ git_buf_dispose(&buf); /* avoid memleak if error occurs */
223
223
 
224
224
  return basename;
225
225
  }
@@ -642,7 +642,7 @@ bool git_path_is_empty_dir(const char *path)
642
642
  else
643
643
  error = git_path_direach(&dir, 0, path_found_entry, NULL);
644
644
 
645
- git_buf_free(&dir);
645
+ git_buf_dispose(&dir);
646
646
 
647
647
  return !error;
648
648
  }
@@ -956,7 +956,7 @@ void git_path_iconv_clear(git_path_iconv_t *ic)
956
956
  if (ic) {
957
957
  if (ic->map != (iconv_t)-1)
958
958
  iconv_close(ic->map);
959
- git_buf_free(&ic->buf);
959
+ git_buf_dispose(&ic->buf);
960
960
  }
961
961
  }
962
962
 
@@ -1060,7 +1060,7 @@ bool git_path_does_fs_decompose_unicode(const char *root)
1060
1060
  (void)p_unlink(path.ptr);
1061
1061
 
1062
1062
  done:
1063
- git_buf_free(&path);
1063
+ git_buf_dispose(&path);
1064
1064
  return found_decomposed;
1065
1065
  }
1066
1066
 
@@ -1308,7 +1308,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
1308
1308
  if (diriter == NULL)
1309
1309
  return;
1310
1310
 
1311
- git_buf_free(&diriter->path_utf8);
1311
+ git_buf_dispose(&diriter->path_utf8);
1312
1312
 
1313
1313
  if (diriter->handle != INVALID_HANDLE_VALUE) {
1314
1314
  FindClose(diriter->handle);
@@ -1338,7 +1338,7 @@ int git_path_diriter_init(
1338
1338
  }
1339
1339
 
1340
1340
  if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
1341
- git_buf_free(&diriter->path);
1341
+ git_buf_dispose(&diriter->path);
1342
1342
 
1343
1343
  giterr_set(GITERR_OS, "failed to open directory '%s'", path);
1344
1344
  return -1;
@@ -1448,7 +1448,7 @@ void git_path_diriter_free(git_path_diriter *diriter)
1448
1448
  git_path_iconv_clear(&diriter->ic);
1449
1449
  #endif
1450
1450
 
1451
- git_buf_free(&diriter->path);
1451
+ git_buf_dispose(&diriter->path);
1452
1452
  }
1453
1453
 
1454
1454
  #endif
@@ -1766,14 +1766,14 @@ static bool verify_component(
1766
1766
  if (flags & GIT_PATH_REJECT_DOT_GIT_HFS) {
1767
1767
  if (!verify_dotgit_hfs(component, len))
1768
1768
  return false;
1769
- if (S_ISLNK(mode) && git_path_is_hfs_dotgit_modules(component, len))
1769
+ if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
1770
1770
  return false;
1771
1771
  }
1772
1772
 
1773
1773
  if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) {
1774
1774
  if (!verify_dotgit_ntfs(repo, component, len))
1775
1775
  return false;
1776
- if (S_ISLNK(mode) && git_path_is_ntfs_dotgit_modules(component, len))
1776
+ if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
1777
1777
  return false;
1778
1778
  }
1779
1779
 
@@ -1872,64 +1872,40 @@ int git_path_normalize_slashes(git_buf *out, const char *path)
1872
1872
  return 0;
1873
1873
  }
1874
1874
 
1875
- static int verify_dotgit_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix)
1876
- {
1877
- if (!verify_dotgit_ntfs_generic(name, len, dotgit_name, dotgit_len, shortname_pfix))
1878
- return false;
1879
-
1880
- return verify_dotgit_hfs_generic(name, len, dotgit_name, dotgit_len);
1881
- }
1882
-
1883
- int git_path_is_ntfs_dotgit_modules(const char *name, size_t len)
1884
- {
1885
- return !verify_dotgit_ntfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"), "gi7eba");
1886
- }
1887
-
1888
- int git_path_is_hfs_dotgit_modules(const char *name, size_t len)
1889
- {
1890
- return !verify_dotgit_hfs_generic(name, len, "gitmodules", CONST_STRLEN("gitmodules"));
1891
- }
1892
-
1893
- int git_path_is_dotgit_modules(const char *name, size_t len)
1894
- {
1895
- if (git_path_is_hfs_dotgit_modules(name, len))
1896
- return 1;
1897
-
1898
- return git_path_is_ntfs_dotgit_modules(name, len);
1899
- }
1900
-
1901
- int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len)
1902
- {
1903
- return !verify_dotgit_ntfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"), "gi250a");
1904
- }
1875
+ static const struct {
1876
+ const char *file;
1877
+ const char *hash;
1878
+ size_t filelen;
1879
+ } gitfiles[] = {
1880
+ { "gitignore", "gi250a", CONST_STRLEN("gitignore") },
1881
+ { "gitmodules", "gi7eba", CONST_STRLEN("gitmodules") },
1882
+ { "gitattributes", "gi7d29", CONST_STRLEN("gitattributes") }
1883
+ };
1905
1884
 
1906
- int git_path_is_hfs_dotgit_ignore(const char *name, size_t len)
1885
+ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs)
1907
1886
  {
1908
- return !verify_dotgit_hfs_generic(name, len, "gitignore", CONST_STRLEN("gitignore"));
1909
- }
1910
-
1911
- int git_path_is_dotgit_ignore(const char *name, size_t len)
1912
- {
1913
- if (git_path_is_hfs_dotgit_ignore(name, len))
1914
- return 1;
1915
-
1916
- return git_path_is_ntfs_dotgit_ignore(name, len);
1917
- }
1887
+ const char *file, *hash;
1888
+ size_t filelen;
1918
1889
 
1919
- int git_path_is_hfs_dotgit_attributes(const char *name, size_t len)
1920
- {
1921
- return !verify_dotgit_hfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"));
1922
- }
1923
-
1924
- int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len)
1925
- {
1926
- return !verify_dotgit_ntfs_generic(name, len, "gitattributes", CONST_STRLEN("gitattributes"), "gi7d29");
1927
- }
1928
-
1929
- int git_path_is_dotgit_attributes(const char *name, size_t len)
1930
- {
1931
- if (git_path_is_hfs_dotgit_attributes(name, len))
1932
- return 1;
1890
+ if (gitfile < 0 && gitfile >= ARRAY_SIZE(gitfiles)) {
1891
+ giterr_set(GITERR_OS, "invalid gitfile for path validation");
1892
+ return -1;
1893
+ }
1933
1894
 
1934
- return git_path_is_ntfs_dotgit_attributes(name, len);
1895
+ file = gitfiles[gitfile].file;
1896
+ filelen = gitfiles[gitfile].filelen;
1897
+ hash = gitfiles[gitfile].hash;
1898
+
1899
+ switch (fs) {
1900
+ case GIT_PATH_FS_GENERIC:
1901
+ return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) ||
1902
+ !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
1903
+ case GIT_PATH_FS_NTFS:
1904
+ return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash);
1905
+ case GIT_PATH_FS_HFS:
1906
+ return !verify_dotgit_hfs_generic(path, pathlen, file, filelen);
1907
+ default:
1908
+ giterr_set(GITERR_OS, "invalid filesystem for path validation");
1909
+ return -1;
1910
+ }
1935
1911
  }
@@ -13,6 +13,8 @@
13
13
  #include "buffer.h"
14
14
  #include "vector.h"
15
15
 
16
+ #include "git2/sys/path.h"
17
+
16
18
  /**
17
19
  * Path manipulation utils
18
20
  *
@@ -645,76 +647,4 @@ extern bool git_path_isvalid(
645
647
  */
646
648
  int git_path_normalize_slashes(git_buf *out, const char *path);
647
649
 
648
- /**
649
- * Check whether a path component corresponds to a .gitmodules file
650
- *
651
- * @param name the path component to check
652
- * @param len the length of `name`
653
- */
654
- extern int git_path_is_dotgit_modules(const char *name, size_t len);
655
-
656
- /**
657
- * Check whether a path component corresponds to a .gitmodules file in NTFS
658
- *
659
- * @param name the path component to check
660
- * @param len the length of `name`
661
- */
662
- extern int git_path_is_ntfs_dotgit_modules(const char *name, size_t len);
663
-
664
- /**
665
- * Check whether a path component corresponds to a .gitmodules file in HFS+
666
- *
667
- * @param name the path component to check
668
- * @param len the length of `name`
669
- */
670
- extern int git_path_is_hfs_dotgit_modules(const char *name, size_t len);
671
-
672
- /**
673
- * Check whether a path component corresponds to a .gitignore file
674
- *
675
- * @param name the path component to check
676
- * @param len the length of `name`
677
- */
678
- extern int git_path_is_dotgit_ignore(const char *name, size_t len);
679
-
680
- /**
681
- * Check whether a path component corresponds to a .gitignore file in NTFS
682
- *
683
- * @param name the path component to check
684
- * @param len the length of `name`
685
- */
686
- extern int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len);
687
-
688
- /**
689
- * Check whether a path component corresponds to a .gitignore file in HFS+
690
- *
691
- * @param name the path component to check
692
- * @param len the length of `name`
693
- */
694
- extern int git_path_is_hfs_dotgit_ignore(const char *name, size_t len);
695
-
696
- /**
697
- * Check whether a path component corresponds to a .gitignore file
698
- *
699
- * @param name the path component to check
700
- * @param len the length of `name`
701
- */
702
- extern int git_path_is_dotgit_attributes(const char *name, size_t len);
703
-
704
- /**
705
- * Check whether a path component corresponds to a .gitattributes file in NTFS
706
- *
707
- * @param name the path component to check
708
- * @param len the length of `name`
709
- */
710
- extern int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len);
711
-
712
- /**
713
- * Check whether a path component corresponds to a .gitattributes file in HFS+
714
- *
715
- * @param name the path component to check
716
- * @param len the length of `name`
717
- */
718
- extern int git_path_is_hfs_dotgit_attributes(const char *name, size_t len);
719
-
720
650
  #endif
@@ -36,7 +36,7 @@ char *git_pathspec_prefix(const git_strarray *pathspec)
36
36
  git_buf_truncate(&prefix, scan - prefix.ptr);
37
37
 
38
38
  if (prefix.size <= 0) {
39
- git_buf_free(&prefix);
39
+ git_buf_dispose(&prefix);
40
40
  return NULL;
41
41
  }
42
42
 
@@ -83,7 +83,7 @@ static void free_refspec(push_spec *spec)
83
83
  if (spec == NULL)
84
84
  return;
85
85
 
86
- git_refspec__free(&spec->refspec);
86
+ git_refspec__dispose(&spec->refspec);
87
87
  git__free(spec);
88
88
  }
89
89
 
@@ -228,7 +228,7 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
228
228
  error = 0;
229
229
 
230
230
  on_error:
231
- git_buf_free(&remote_ref_name);
231
+ git_buf_dispose(&remote_ref_name);
232
232
  return error;
233
233
  }
234
234
 
@@ -116,7 +116,7 @@ done:
116
116
  if (type != GIT_REBASE_TYPE_NONE && path_out)
117
117
  *path_out = git_buf_detach(&path);
118
118
 
119
- git_buf_free(&path);
119
+ git_buf_dispose(&path);
120
120
 
121
121
  return 0;
122
122
  }
@@ -251,9 +251,9 @@ static int rebase_open_merge(git_rebase *rebase)
251
251
  rebase->onto_name = git_buf_detach(&buf);
252
252
 
253
253
  done:
254
- git_buf_free(&cmt);
255
- git_buf_free(&state_path);
256
- git_buf_free(&buf);
254
+ git_buf_dispose(&cmt);
255
+ git_buf_dispose(&state_path);
256
+ git_buf_dispose(&buf);
257
257
 
258
258
  return error;
259
259
  }
@@ -275,9 +275,6 @@ static int rebase_alloc(git_rebase **out, const git_rebase_options *rebase_opts)
275
275
  GITERR_CHECK_ALLOC(rebase->options.rewrite_notes_ref);
276
276
  }
277
277
 
278
- if ((rebase->options.checkout_options.checkout_strategy & (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_FORCE)) == 0)
279
- rebase->options.checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
280
-
281
278
  *out = rebase;
282
279
 
283
280
  return 0;
@@ -393,10 +390,10 @@ done:
393
390
  else
394
391
  git_rebase_free(rebase);
395
392
 
396
- git_buf_free(&path);
397
- git_buf_free(&orig_head_name);
398
- git_buf_free(&orig_head_id);
399
- git_buf_free(&onto_id);
393
+ git_buf_dispose(&path);
394
+ git_buf_dispose(&orig_head_name);
395
+ git_buf_dispose(&orig_head_id);
396
+ git_buf_dispose(&onto_id);
400
397
  return error;
401
398
  }
402
399
 
@@ -424,8 +421,8 @@ static int rebase_setupfile(git_rebase *rebase, const char *filename, int flags,
424
421
  if ((error = git_buf_joinpath(&path, rebase->state_path, filename)) == 0)
425
422
  error = git_futils_writebuffer(&contents, path.ptr, flags, REBASE_FILE_MODE);
426
423
 
427
- git_buf_free(&path);
428
- git_buf_free(&contents);
424
+ git_buf_dispose(&path);
425
+ git_buf_dispose(&contents);
429
426
 
430
427
  return error;
431
428
  }
@@ -466,7 +463,7 @@ static int rebase_setupfiles_merge(git_rebase *rebase)
466
463
  }
467
464
 
468
465
  done:
469
- git_buf_free(&commit_filename);
466
+ git_buf_dispose(&commit_filename);
470
467
  return error;
471
468
  }
472
469
 
@@ -662,8 +659,8 @@ static int rebase_init_merge(
662
659
  done:
663
660
  git_reference_free(head_ref);
664
661
  git_commit_free(onto_commit);
665
- git_buf_free(&reflog);
666
- git_buf_free(&state_path);
662
+ git_buf_dispose(&reflog);
663
+ git_buf_dispose(&state_path);
667
664
 
668
665
  return error;
669
666
  }
@@ -842,7 +839,7 @@ done:
842
839
  git_tree_free(parent_tree);
843
840
  git_commit_free(parent_commit);
844
841
  git_commit_free(current_commit);
845
- git_buf_free(&path);
842
+ git_buf_dispose(&path);
846
843
 
847
844
  return error;
848
845
  }
@@ -1266,9 +1263,9 @@ on_error:
1266
1263
  error = -1;
1267
1264
 
1268
1265
  done:
1269
- git_buf_free(&rewritten);
1270
- git_buf_free(&path);
1271
- git_buf_free(&notes_ref);
1266
+ git_buf_dispose(&rewritten);
1267
+ git_buf_dispose(&path);
1268
+ git_buf_dispose(&notes_ref);
1272
1269
 
1273
1270
  return error;
1274
1271
  }
@@ -1300,8 +1297,8 @@ static int return_to_orig_head(git_rebase *rebase)
1300
1297
  rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
1301
1298
  head_msg.ptr);
1302
1299
 
1303
- git_buf_free(&head_msg);
1304
- git_buf_free(&branch_msg);
1300
+ git_buf_dispose(&head_msg);
1301
+ git_buf_dispose(&branch_msg);
1305
1302
  git_commit_free(terminal_commit);
1306
1303
  git_reference_free(head_ref);
1307
1304
  git_reference_free(branch_ref);
@@ -183,7 +183,7 @@ static int packed_reload(refdb_fs_backend *backend)
183
183
  }
184
184
 
185
185
  git_sortedcache_wunlock(backend->refcache);
186
- git_buf_free(&packedrefs);
186
+ git_buf_dispose(&packedrefs);
187
187
 
188
188
  return 0;
189
189
 
@@ -192,7 +192,7 @@ parse_failed:
192
192
 
193
193
  git_sortedcache_clear(backend->refcache, false);
194
194
  git_sortedcache_wunlock(backend->refcache);
195
- git_buf_free(&packedrefs);
195
+ git_buf_dispose(&packedrefs);
196
196
 
197
197
  return -1;
198
198
  }
@@ -226,7 +226,7 @@ static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
226
226
  /* build full path to file */
227
227
  if ((error = git_buf_joinpath(buf, base, path)) < 0 ||
228
228
  (error = git_futils_readbuffer(buf, buf->ptr)) < 0)
229
- git_buf_free(buf);
229
+ git_buf_dispose(buf);
230
230
 
231
231
  return error;
232
232
  }
@@ -266,7 +266,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
266
266
  git_sortedcache_wunlock(backend->refcache);
267
267
 
268
268
  done:
269
- git_buf_free(&ref_file);
269
+ git_buf_dispose(&ref_file);
270
270
  return error;
271
271
  }
272
272
 
@@ -317,7 +317,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
317
317
  error = git_path_direach(
318
318
  &refs_path, backend->direach_flags, _dirent_loose_load, backend);
319
319
 
320
- git_buf_free(&refs_path);
320
+ git_buf_dispose(&refs_path);
321
321
 
322
322
  return error;
323
323
  }
@@ -340,7 +340,7 @@ static int refdb_fs_backend__exists(
340
340
  *exists = git_path_isfile(ref_path.ptr) ||
341
341
  (git_sortedcache_lookup(backend->refcache, ref_name) != NULL);
342
342
 
343
- git_buf_free(&ref_path);
343
+ git_buf_dispose(&ref_path);
344
344
  return 0;
345
345
  }
346
346
 
@@ -414,7 +414,7 @@ static int loose_lookup(
414
414
  *out = git_reference__alloc(ref_name, &oid, NULL);
415
415
  }
416
416
 
417
- git_buf_free(&ref_file);
417
+ git_buf_dispose(&ref_file);
418
418
  return error;
419
419
  }
420
420
 
@@ -505,26 +505,57 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
505
505
  git_iterator *fsit = NULL;
506
506
  git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
507
507
  const git_index_entry *entry = NULL;
508
+ const char *ref_prefix = GIT_REFS_DIR;
509
+ size_t ref_prefix_len = strlen(ref_prefix);
508
510
 
509
511
  if (!backend->commonpath) /* do nothing if no commonpath for loose refs */
510
512
  return 0;
511
513
 
512
514
  fsit_opts.flags = backend->iterator_flags;
513
515
 
514
- if ((error = git_buf_printf(&path, "%s/refs", backend->commonpath)) < 0 ||
515
- (error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
516
- git_buf_free(&path);
516
+ if (iter->glob) {
517
+ const char *last_sep = NULL;
518
+ const char *pos;
519
+ for (pos = iter->glob; *pos; ++pos) {
520
+ switch (*pos) {
521
+ case '?':
522
+ case '*':
523
+ case '[':
524
+ case '\\':
525
+ break;
526
+ case '/':
527
+ last_sep = pos;
528
+ /* FALLTHROUGH */
529
+ default:
530
+ continue;
531
+ }
532
+ break;
533
+ }
534
+ if (last_sep) {
535
+ ref_prefix = iter->glob;
536
+ ref_prefix_len = (last_sep - ref_prefix) + 1;
537
+ }
538
+ }
539
+
540
+ if ((error = git_buf_printf(&path, "%s/", backend->commonpath)) < 0 ||
541
+ (error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) {
542
+ git_buf_dispose(&path);
517
543
  return error;
518
544
  }
519
545
 
520
- error = git_buf_sets(&path, GIT_REFS_DIR);
546
+ if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
547
+ git_buf_dispose(&path);
548
+ return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
549
+ }
550
+
551
+ error = git_buf_sets(&path, ref_prefix);
521
552
 
522
553
  while (!error && !git_iterator_advance(&entry, fsit)) {
523
554
  const char *ref_name;
524
555
  struct packref *ref;
525
556
  char *ref_dup;
526
557
 
527
- git_buf_truncate(&path, strlen(GIT_REFS_DIR));
558
+ git_buf_truncate(&path, ref_prefix_len);
528
559
  git_buf_puts(&path, entry->path);
529
560
  ref_name = git_buf_cstr(&path);
530
561
 
@@ -546,7 +577,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
546
577
  }
547
578
 
548
579
  git_iterator_free(fsit);
549
- git_buf_free(&path);
580
+ git_buf_dispose(&path);
550
581
 
551
582
  return error;
552
583
  }
@@ -772,7 +803,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
772
803
  if (error == GIT_EDIRECTORY)
773
804
  giterr_set(GITERR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
774
805
 
775
- git_buf_free(&ref_path);
806
+ git_buf_dispose(&ref_path);
776
807
  return error;
777
808
  }
778
809
 
@@ -959,7 +990,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
959
990
  continue;
960
991
 
961
992
  if (error < 0) {
962
- git_buf_free(&ref_content);
993
+ git_buf_dispose(&ref_content);
963
994
  giterr_set(GITERR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
964
995
  return error;
965
996
  }
@@ -990,7 +1021,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
990
1021
  p_unlink(lock.path_original);
991
1022
  }
992
1023
 
993
- git_buf_free(&ref_content);
1024
+ git_buf_dispose(&ref_content);
994
1025
  git_filebuf_cleanup(&lock);
995
1026
  return 0;
996
1027
  }
@@ -1319,7 +1350,7 @@ static int refdb_fs_backend__delete_tail(
1319
1350
  }
1320
1351
 
1321
1352
  /* If a loose reference exists, remove it from the filesystem */
1322
- if (git_buf_joinpath(&loose_path, backend->gitpath, ref_name) < 0)
1353
+ if (git_buf_joinpath(&loose_path, backend->commonpath, ref_name) < 0)
1323
1354
  return -1;
1324
1355
 
1325
1356
 
@@ -1352,7 +1383,7 @@ static int refdb_fs_backend__delete_tail(
1352
1383
  error = packed_write(backend);
1353
1384
 
1354
1385
  cleanup:
1355
- git_buf_free(&loose_path);
1386
+ git_buf_dispose(&loose_path);
1356
1387
  git_filebuf_cleanup(file);
1357
1388
 
1358
1389
  return error;
@@ -1491,7 +1522,7 @@ static char *setup_namespace(git_repository *repo, const char *in)
1491
1522
  out = git_buf_detach(&path);
1492
1523
 
1493
1524
  done:
1494
- git_buf_free(&path);
1525
+ git_buf_dispose(&path);
1495
1526
  return out;
1496
1527
  }
1497
1528
 
@@ -1624,7 +1655,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1624
1655
  return error;
1625
1656
 
1626
1657
  error = create_new_reflog_file(git_buf_cstr(&path));
1627
- git_buf_free(&path);
1658
+ git_buf_dispose(&path);
1628
1659
 
1629
1660
  return error;
1630
1661
  }
@@ -1640,7 +1671,7 @@ static int has_reflog(git_repository *repo, const char *name)
1640
1671
  ret = git_path_isfile(git_buf_cstr(&path));
1641
1672
 
1642
1673
  cleanup:
1643
- git_buf_free(&path);
1674
+ git_buf_dispose(&path);
1644
1675
  return ret;
1645
1676
  }
1646
1677
 
@@ -1694,8 +1725,8 @@ cleanup:
1694
1725
  git_reflog_free(log);
1695
1726
 
1696
1727
  success:
1697
- git_buf_free(&log_file);
1698
- git_buf_free(&log_path);
1728
+ git_buf_dispose(&log_file);
1729
+ git_buf_dispose(&log_path);
1699
1730
 
1700
1731
  return error;
1701
1732
  }
@@ -1760,7 +1791,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
1760
1791
  error = git_filebuf_open(file, git_buf_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
1761
1792
 
1762
1793
  cleanup:
1763
- git_buf_free(&log_path);
1794
+ git_buf_dispose(&log_path);
1764
1795
 
1765
1796
  return error;
1766
1797
  }
@@ -1796,7 +1827,7 @@ cleanup:
1796
1827
  git_filebuf_cleanup(&fbuf);
1797
1828
 
1798
1829
  success:
1799
- git_buf_free(&log);
1830
+ git_buf_dispose(&log);
1800
1831
 
1801
1832
  return error;
1802
1833
  }
@@ -1880,8 +1911,8 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1880
1911
  error = git_futils_writebuffer(&buf, git_buf_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
1881
1912
 
1882
1913
  cleanup:
1883
- git_buf_free(&buf);
1884
- git_buf_free(&path);
1914
+ git_buf_dispose(&buf);
1915
+ git_buf_dispose(&path);
1885
1916
 
1886
1917
  return error;
1887
1918
  }
@@ -1959,10 +1990,10 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
1959
1990
  }
1960
1991
 
1961
1992
  cleanup:
1962
- git_buf_free(&temp_path);
1963
- git_buf_free(&old_path);
1964
- git_buf_free(&new_path);
1965
- git_buf_free(&normalized);
1993
+ git_buf_dispose(&temp_path);
1994
+ git_buf_dispose(&old_path);
1995
+ git_buf_dispose(&new_path);
1996
+ git_buf_dispose(&normalized);
1966
1997
 
1967
1998
  return error;
1968
1999
  }
@@ -1985,7 +2016,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
1985
2016
  if (!error && git_path_exists(path.ptr))
1986
2017
  error = p_unlink(path.ptr);
1987
2018
 
1988
- git_buf_free(&path);
2019
+ git_buf_dispose(&path);
1989
2020
 
1990
2021
  return error;
1991
2022
 
@@ -2024,7 +2055,7 @@ int git_refdb_backend_fs(
2024
2055
  NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
2025
2056
  goto fail;
2026
2057
 
2027
- git_buf_free(&gitpath);
2058
+ git_buf_dispose(&gitpath);
2028
2059
 
2029
2060
  if (!git_repository__cvar(&t, backend->repo, GIT_CVAR_IGNORECASE) && t) {
2030
2061
  backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
@@ -2060,7 +2091,7 @@ int git_refdb_backend_fs(
2060
2091
  return 0;
2061
2092
 
2062
2093
  fail:
2063
- git_buf_free(&gitpath);
2094
+ git_buf_dispose(&gitpath);
2064
2095
  git__free(backend->gitpath);
2065
2096
  git__free(backend->commonpath);
2066
2097
  git__free(backend);