rugged 0.27.7 → 0.27.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +6 -2
  4. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
  5. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
  6. data/vendor/libgit2/cmake/Modules/FindIconv.cmake +11 -6
  7. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -2
  8. data/vendor/libgit2/include/git2.h +0 -1
  9. data/vendor/libgit2/include/git2/attr.h +7 -18
  10. data/vendor/libgit2/include/git2/blame.h +22 -39
  11. data/vendor/libgit2/include/git2/blob.h +1 -1
  12. data/vendor/libgit2/include/git2/branch.h +1 -1
  13. data/vendor/libgit2/include/git2/buffer.h +2 -14
  14. data/vendor/libgit2/include/git2/checkout.h +12 -13
  15. data/vendor/libgit2/include/git2/cherrypick.h +4 -6
  16. data/vendor/libgit2/include/git2/clone.h +6 -8
  17. data/vendor/libgit2/include/git2/commit.h +0 -28
  18. data/vendor/libgit2/include/git2/common.h +0 -27
  19. data/vendor/libgit2/include/git2/config.h +0 -1
  20. data/vendor/libgit2/include/git2/describe.h +7 -30
  21. data/vendor/libgit2/include/git2/diff.h +22 -32
  22. data/vendor/libgit2/include/git2/errors.h +0 -1
  23. data/vendor/libgit2/include/git2/ignore.h +2 -2
  24. data/vendor/libgit2/include/git2/merge.h +8 -10
  25. data/vendor/libgit2/include/git2/proxy.h +5 -9
  26. data/vendor/libgit2/include/git2/rebase.h +4 -7
  27. data/vendor/libgit2/include/git2/refs.h +1 -1
  28. data/vendor/libgit2/include/git2/refspec.h +0 -17
  29. data/vendor/libgit2/include/git2/remote.h +10 -12
  30. data/vendor/libgit2/include/git2/repository.h +5 -7
  31. data/vendor/libgit2/include/git2/revert.h +3 -5
  32. data/vendor/libgit2/include/git2/stash.h +8 -11
  33. data/vendor/libgit2/include/git2/status.h +3 -7
  34. data/vendor/libgit2/include/git2/submodule.h +7 -8
  35. data/vendor/libgit2/include/git2/sys/index.h +0 -3
  36. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  37. data/vendor/libgit2/include/git2/sys/merge.h +1 -6
  38. data/vendor/libgit2/include/git2/transaction.h +0 -1
  39. data/vendor/libgit2/include/git2/types.h +5 -8
  40. data/vendor/libgit2/include/git2/version.h +2 -2
  41. data/vendor/libgit2/include/git2/worktree.h +11 -46
  42. data/vendor/libgit2/src/CMakeLists.txt +28 -91
  43. data/vendor/libgit2/src/annotated_commit.c +4 -4
  44. data/vendor/libgit2/src/apply.c +6 -5
  45. data/vendor/libgit2/src/attr.c +4 -4
  46. data/vendor/libgit2/src/attr_file.c +5 -5
  47. data/vendor/libgit2/src/attrcache.c +2 -2
  48. data/vendor/libgit2/src/blame.c +4 -11
  49. data/vendor/libgit2/src/blame.h +0 -1
  50. data/vendor/libgit2/src/blame_git.c +5 -8
  51. data/vendor/libgit2/src/blob.c +5 -5
  52. data/vendor/libgit2/src/branch.c +20 -20
  53. data/vendor/libgit2/src/buffer.c +4 -9
  54. data/vendor/libgit2/src/buffer.h +1 -1
  55. data/vendor/libgit2/src/checkout.c +24 -33
  56. data/vendor/libgit2/src/cherrypick.c +3 -3
  57. data/vendor/libgit2/src/clone.c +13 -13
  58. data/vendor/libgit2/src/commit.c +5 -18
  59. data/vendor/libgit2/src/commit_list.c +9 -3
  60. data/vendor/libgit2/src/common.h +1 -3
  61. data/vendor/libgit2/src/config.c +15 -6
  62. data/vendor/libgit2/src/config_file.c +249 -193
  63. data/vendor/libgit2/src/config_parse.c +66 -89
  64. data/vendor/libgit2/src/config_parse.h +2 -2
  65. data/vendor/libgit2/src/crlf.c +3 -9
  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 +3 -4
  70. data/vendor/libgit2/src/diff_print.c +8 -8
  71. data/vendor/libgit2/src/diff_tform.c +4 -2
  72. data/vendor/libgit2/src/diff_xdiff.c +0 -12
  73. data/vendor/libgit2/src/features.h.in +0 -2
  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 +9 -3
  79. data/vendor/libgit2/src/global.c +12 -17
  80. data/vendor/libgit2/src/hash.h +0 -2
  81. data/vendor/libgit2/src/ignore.c +5 -5
  82. data/vendor/libgit2/src/index.c +40 -80
  83. data/vendor/libgit2/src/index.h +0 -10
  84. data/vendor/libgit2/src/indexer.c +9 -9
  85. data/vendor/libgit2/src/iterator.c +8 -8
  86. data/vendor/libgit2/src/khash.h +1 -3
  87. data/vendor/libgit2/src/merge.c +7 -7
  88. data/vendor/libgit2/src/netops.c +5 -5
  89. data/vendor/libgit2/src/notes.c +2 -2
  90. data/vendor/libgit2/src/odb.c +9 -9
  91. data/vendor/libgit2/src/odb_loose.c +22 -18
  92. data/vendor/libgit2/src/odb_pack.c +3 -3
  93. data/vendor/libgit2/src/pack-objects.c +3 -3
  94. data/vendor/libgit2/src/pack.c +5 -5
  95. data/vendor/libgit2/src/pack.h +1 -1
  96. data/vendor/libgit2/src/parse.c +7 -4
  97. data/vendor/libgit2/src/patch.c +1 -1
  98. data/vendor/libgit2/src/patch_generate.c +2 -2
  99. data/vendor/libgit2/src/patch_parse.c +4 -24
  100. data/vendor/libgit2/src/path.c +140 -39
  101. data/vendor/libgit2/src/path.h +84 -2
  102. data/vendor/libgit2/src/pathspec.c +1 -1
  103. data/vendor/libgit2/src/push.c +2 -2
  104. data/vendor/libgit2/src/rebase.c +23 -20
  105. data/vendor/libgit2/src/refdb_fs.c +34 -65
  106. data/vendor/libgit2/src/refs.c +16 -13
  107. data/vendor/libgit2/src/refspec.c +5 -30
  108. data/vendor/libgit2/src/refspec.h +1 -1
  109. data/vendor/libgit2/src/remote.c +43 -43
  110. data/vendor/libgit2/src/repository.c +56 -56
  111. data/vendor/libgit2/src/reset.c +1 -1
  112. data/vendor/libgit2/src/revert.c +3 -3
  113. data/vendor/libgit2/src/revparse.c +7 -6
  114. data/vendor/libgit2/src/revwalk.c +20 -48
  115. data/vendor/libgit2/src/revwalk.h +1 -2
  116. data/vendor/libgit2/src/settings.c +1 -25
  117. data/vendor/libgit2/src/signature.c +4 -2
  118. data/vendor/libgit2/src/stash.c +34 -80
  119. data/vendor/libgit2/src/status.c +1 -1
  120. data/vendor/libgit2/src/streams/curl.c +1 -1
  121. data/vendor/libgit2/src/streams/openssl.c +34 -132
  122. data/vendor/libgit2/src/streams/openssl.h +107 -0
  123. data/vendor/libgit2/src/streams/tls.c +0 -3
  124. data/vendor/libgit2/src/submodule.c +83 -118
  125. data/vendor/libgit2/src/sysdir.c +4 -4
  126. data/vendor/libgit2/src/tag.c +12 -12
  127. data/vendor/libgit2/src/trace.h +1 -1
  128. data/vendor/libgit2/src/trailer.c +6 -6
  129. data/vendor/libgit2/src/transport.c +2 -2
  130. data/vendor/libgit2/src/transports/auth.c +1 -1
  131. data/vendor/libgit2/src/transports/auth_negotiate.c +2 -2
  132. data/vendor/libgit2/src/transports/git.c +1 -1
  133. data/vendor/libgit2/src/transports/http.c +15 -12
  134. data/vendor/libgit2/src/transports/local.c +7 -7
  135. data/vendor/libgit2/src/transports/smart.c +15 -20
  136. data/vendor/libgit2/src/transports/smart.h +5 -5
  137. data/vendor/libgit2/src/transports/smart_pkt.c +131 -123
  138. data/vendor/libgit2/src/transports/smart_protocol.c +38 -48
  139. data/vendor/libgit2/src/transports/ssh.c +1 -1
  140. data/vendor/libgit2/src/transports/winhttp.c +26 -21
  141. data/vendor/libgit2/src/tree-cache.c +2 -2
  142. data/vendor/libgit2/src/tree.c +69 -23
  143. data/vendor/libgit2/src/tree.h +12 -0
  144. data/vendor/libgit2/src/util.c +99 -52
  145. data/vendor/libgit2/src/util.h +138 -14
  146. data/vendor/libgit2/src/vector.c +13 -8
  147. data/vendor/libgit2/src/win32/findfile.c +2 -2
  148. data/vendor/libgit2/src/win32/posix_w32.c +1 -1
  149. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +0 -94
  150. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +75 -28
  151. data/vendor/libgit2/src/worktree.c +44 -65
  152. data/vendor/libgit2/src/worktree.h +0 -2
  153. data/vendor/libgit2/src/xdiff/xdiffi.c +1 -3
  154. metadata +5 -17
  155. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +0 -93
  156. data/vendor/libgit2/include/git2/mailmap.h +0 -115
  157. data/vendor/libgit2/include/git2/sys/alloc.h +0 -101
  158. data/vendor/libgit2/include/git2/sys/path.h +0 -55
  159. data/vendor/libgit2/src/alloc.c +0 -47
  160. data/vendor/libgit2/src/alloc.h +0 -40
  161. data/vendor/libgit2/src/hash/hash_mbedtls.c +0 -38
  162. data/vendor/libgit2/src/hash/hash_mbedtls.h +0 -20
  163. data/vendor/libgit2/src/mailmap.c +0 -485
  164. data/vendor/libgit2/src/mailmap.h +0 -35
  165. data/vendor/libgit2/src/stdalloc.c +0 -120
  166. data/vendor/libgit2/src/stdalloc.h +0 -17
  167. data/vendor/libgit2/src/streams/mbedtls.c +0 -463
  168. data/vendor/libgit2/src/streams/mbedtls.h +0 -20
@@ -529,7 +529,7 @@ static void similarity_unload(similarity_info *info)
529
529
  if (info->blob)
530
530
  git_blob_free(info->blob);
531
531
  else
532
- git_buf_dispose(&info->data);
532
+ git_buf_free(&info->data);
533
533
  }
534
534
 
535
535
  #define FLAG_SET(opts,flag_name) (((opts)->flags & flag_name) != 0)
@@ -816,13 +816,15 @@ int git_diff_find_similar(
816
816
  diff_find_match *best_match;
817
817
  git_diff_file swap;
818
818
 
819
+ assert(diff);
820
+
819
821
  if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
820
822
  return error;
821
823
 
822
824
  num_deltas = diff->deltas.length;
823
825
 
824
826
  /* TODO: maybe abort if deltas.length > rename_limit ??? */
825
- if (!git__is_uint32(num_deltas))
827
+ if (!num_deltas || !git__is_uint32(num_deltas))
826
828
  goto cleanup;
827
829
 
828
830
  /* No flags set; nothing to do */
@@ -6,7 +6,6 @@
6
6
  */
7
7
 
8
8
  #include "diff_xdiff.h"
9
- #include "util.h"
10
9
 
11
10
  #include "git2/errors.h"
12
11
  #include "diff.h"
@@ -116,7 +115,6 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
116
115
  const git_diff_delta *delta = patch->base.delta;
117
116
  git_patch_generated_output *output = &info->xo->output;
118
117
  git_diff_line line;
119
- size_t buffer_len;
120
118
 
121
119
  if (len == 1) {
122
120
  output->error = git_xdiff_parse_hunk(&info->hunk, bufs[0].ptr);
@@ -126,16 +124,6 @@ static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
126
124
  info->hunk.header_len = bufs[0].size;
127
125
  if (info->hunk.header_len >= sizeof(info->hunk.header))
128
126
  info->hunk.header_len = sizeof(info->hunk.header) - 1;
129
-
130
- /* Sanitize the hunk header in case there is invalid Unicode */
131
- buffer_len = git__utf8_valid_buf_length((const uint8_t *) bufs[0].ptr, info->hunk.header_len);
132
- /* Sanitizing the hunk header may delete the newline, so add it back again if there is room */
133
- if (buffer_len < info->hunk.header_len) {
134
- bufs[0].ptr[buffer_len] = '\n';
135
- buffer_len += 1;
136
- info->hunk.header_len = buffer_len;
137
- }
138
-
139
127
  memcpy(info->hunk.header, bufs[0].ptr, info->hunk.header_len);
140
128
  info->hunk.header[info->hunk.header_len] = '\0';
141
129
 
@@ -27,12 +27,10 @@
27
27
  #cmakedefine GIT_HTTPS 1
28
28
  #cmakedefine GIT_OPENSSL 1
29
29
  #cmakedefine GIT_SECURE_TRANSPORT 1
30
- #cmakedefine GIT_MBEDTLS 1
31
30
 
32
31
  #cmakedefine GIT_SHA1_COLLISIONDETECT 1
33
32
  #cmakedefine GIT_SHA1_WIN32 1
34
33
  #cmakedefine GIT_SHA1_COMMON_CRYPTO 1
35
34
  #cmakedefine GIT_SHA1_OPENSSL 1
36
- #cmakedefine GIT_SHA1_MBEDTLS 1
37
35
 
38
36
  #endif
@@ -78,7 +78,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
78
78
  goto cleanup;
79
79
 
80
80
  error = git_refspec__dwim_one(&remote->active_refspecs, &head, &remote->refs);
81
- git_refspec__dispose(&head);
81
+ git_refspec__free(&head);
82
82
 
83
83
  if (error < 0)
84
84
  goto cleanup;
@@ -96,7 +96,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts)
96
96
  }
97
97
 
98
98
  cleanup:
99
- git_refspec__dispose(&tagspec);
99
+ git_refspec__free(&tagspec);
100
100
 
101
101
  return error;
102
102
  }
@@ -119,11 +119,11 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
119
119
  return -1;
120
120
 
121
121
  if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_APPEND, GIT_REFS_FILE_MODE) < 0) {
122
- git_buf_dispose(&path);
122
+ git_buf_free(&path);
123
123
  return -1;
124
124
  }
125
125
 
126
- git_buf_dispose(&path);
126
+ git_buf_free(&path);
127
127
 
128
128
  git_vector_sort(fetchhead_refs);
129
129
 
@@ -283,9 +283,9 @@ int git_repository_fetchhead_foreach(git_repository *repo,
283
283
  }
284
284
 
285
285
  done:
286
- git_buf_dispose(&file);
287
- git_buf_dispose(&path);
288
- git_buf_dispose(&name);
286
+ git_buf_free(&file);
287
+ git_buf_free(&path);
288
+ git_buf_free(&name);
289
289
 
290
290
  return error;
291
291
  }
@@ -256,7 +256,7 @@ static int resolve_symlink(git_buf *out, const char *path)
256
256
  goto cleanup;
257
257
 
258
258
  git_buf_swap(&curpath, &dir);
259
- git_buf_dispose(&dir);
259
+ git_buf_free(&dir);
260
260
 
261
261
  if ((error = git_path_apply_relative(&curpath, target.ptr)) < 0)
262
262
  goto cleanup;
@@ -267,8 +267,8 @@ static int resolve_symlink(git_buf *out, const char *path)
267
267
  error = -1;
268
268
 
269
269
  cleanup:
270
- git_buf_dispose(&curpath);
271
- git_buf_dispose(&target);
270
+ git_buf_free(&curpath);
271
+ git_buf_free(&target);
272
272
  return error;
273
273
  }
274
274
 
@@ -343,7 +343,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
343
343
  file->fd = git_futils_mktmp(&tmp_path, path, mode);
344
344
 
345
345
  if (file->fd < 0) {
346
- git_buf_dispose(&tmp_path);
346
+ git_buf_free(&tmp_path);
347
347
  goto cleanup;
348
348
  }
349
349
  file->fd_is_open = true;
@@ -159,7 +159,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
159
159
 
160
160
  if (read_size != (ssize_t)len) {
161
161
  giterr_set(GITERR_OS, "failed to read descriptor");
162
- git_buf_dispose(buf);
162
+ git_buf_free(buf);
163
163
  return -1;
164
164
  }
165
165
 
@@ -209,7 +209,7 @@ int git_futils_readbuffer_updated(
209
209
 
210
210
  if (checksum) {
211
211
  if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
212
- git_buf_dispose(&buf);
212
+ git_buf_free(&buf);
213
213
  return error;
214
214
  }
215
215
 
@@ -217,7 +217,7 @@ int git_futils_readbuffer_updated(
217
217
  * If we were given a checksum, we only want to use it if it's different
218
218
  */
219
219
  if (!git_oid__cmp(checksum, &checksum_new)) {
220
- git_buf_dispose(&buf);
220
+ git_buf_free(&buf);
221
221
  if (updated)
222
222
  *updated = 0;
223
223
 
@@ -234,7 +234,7 @@ int git_futils_readbuffer_updated(
234
234
  *updated = 1;
235
235
 
236
236
  git_buf_swap(out, &buf);
237
- git_buf_dispose(&buf);
237
+ git_buf_free(&buf);
238
238
 
239
239
  return 0;
240
240
  }
@@ -526,8 +526,8 @@ int git_futils_mkdir(
526
526
  parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
527
527
 
528
528
  done:
529
- git_buf_dispose(&make_path);
530
- git_buf_dispose(&parent_path);
529
+ git_buf_free(&make_path);
530
+ git_buf_free(&parent_path);
531
531
  return error;
532
532
  }
533
533
 
@@ -661,7 +661,7 @@ retry_lstat:
661
661
  }
662
662
 
663
663
  done:
664
- git_buf_dispose(&make_path);
664
+ git_buf_free(&make_path);
665
665
  return error;
666
666
  }
667
667
 
@@ -822,7 +822,7 @@ int git_futils_rmdir_r(
822
822
  error = 0;
823
823
  }
824
824
 
825
- git_buf_dispose(&fullpath);
825
+ git_buf_free(&fullpath);
826
826
 
827
827
  return error;
828
828
  }
@@ -1081,8 +1081,8 @@ int git_futils_cp_r(
1081
1081
 
1082
1082
  error = _cp_r_callback(&info, &path);
1083
1083
 
1084
- git_buf_dispose(&path);
1085
- git_buf_dispose(&info.to);
1084
+ git_buf_free(&path);
1085
+ git_buf_free(&info.to);
1086
1086
 
1087
1087
  return error;
1088
1088
  }
@@ -809,6 +809,7 @@ static int proxy_stream_close(git_writestream *s)
809
809
  {
810
810
  struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
811
811
  git_buf *writebuf;
812
+ git_error_state error_state = {0};
812
813
  int error;
813
814
 
814
815
  assert(proxy_stream);
@@ -826,6 +827,11 @@ static int proxy_stream_close(git_writestream *s)
826
827
  git_buf_sanitize(proxy_stream->output);
827
828
  writebuf = proxy_stream->output;
828
829
  } else {
830
+ /* close stream before erroring out taking care
831
+ * to preserve the original error */
832
+ giterr_state_capture(&error_state, error);
833
+ proxy_stream->target->close(proxy_stream->target);
834
+ giterr_state_restore(&error_state);
829
835
  return error;
830
836
  }
831
837
 
@@ -841,8 +847,8 @@ static void proxy_stream_free(git_writestream *s)
841
847
  struct proxy_stream *proxy_stream = (struct proxy_stream *)s;
842
848
  assert(proxy_stream);
843
849
 
844
- git_buf_dispose(&proxy_stream->input);
845
- git_buf_dispose(&proxy_stream->temp_buf);
850
+ git_buf_free(&proxy_stream->input);
851
+ git_buf_free(&proxy_stream->temp_buf);
846
852
  git__free(proxy_stream);
847
853
  }
848
854
 
@@ -977,7 +983,7 @@ done:
977
983
  if (fd >= 0)
978
984
  p_close(fd);
979
985
  stream_list_free(&filter_streams);
980
- git_buf_dispose(&abspath);
986
+ git_buf_free(&abspath);
981
987
  return error;
982
988
  }
983
989
 
@@ -7,13 +7,11 @@
7
7
 
8
8
  #include "global.h"
9
9
 
10
- #include "alloc.h"
11
10
  #include "hash.h"
12
11
  #include "sysdir.h"
13
12
  #include "filter.h"
14
13
  #include "merge_driver.h"
15
14
  #include "streams/curl.h"
16
- #include "streams/mbedtls.h"
17
15
  #include "streams/openssl.h"
18
16
  #include "thread-utils.h"
19
17
  #include "git2/global.h"
@@ -61,15 +59,13 @@ static int init_common(void)
61
59
  #endif
62
60
 
63
61
  /* Initialize any other subsystems that have global state */
64
- if ((ret = git_allocator_global_init()) == 0 &&
65
- (ret = git_hash_global_init()) == 0 &&
62
+ if ((ret = git_hash_global_init()) == 0 &&
66
63
  (ret = git_sysdir_global_init()) == 0 &&
67
64
  (ret = git_filter_global_init()) == 0 &&
68
65
  (ret = git_merge_driver_global_init()) == 0 &&
69
66
  (ret = git_transport_ssh_global_init()) == 0 &&
70
67
  (ret = git_openssl_stream_global_init()) == 0 &&
71
- (ret = git_curl_stream_global_init()) == 0 &&
72
- (ret = git_mbedtls_stream_global_init()) == 0)
68
+ (ret = git_curl_stream_global_init()) == 0)
73
69
  ret = git_mwindow_global_init();
74
70
 
75
71
  GIT_MEMORY_BARRIER;
@@ -278,10 +274,10 @@ int git_libgit2_init(void)
278
274
  {
279
275
  int ret, err;
280
276
 
277
+ ret = git_atomic_inc(&git__n_inits);
278
+
281
279
  if ((err = pthread_mutex_lock(&_init_mutex)) != 0)
282
280
  return err;
283
-
284
- ret = git_atomic_inc(&git__n_inits);
285
281
  err = pthread_once(&_once_init, init_once);
286
282
  err |= pthread_mutex_unlock(&_init_mutex);
287
283
 
@@ -295,13 +291,13 @@ int git_libgit2_shutdown(void)
295
291
  {
296
292
  void *ptr = NULL;
297
293
  pthread_once_t new_once = PTHREAD_ONCE_INIT;
298
- int error, ret;
299
-
300
- if ((error = pthread_mutex_lock(&_init_mutex)) != 0)
301
- return error;
294
+ int ret;
302
295
 
303
296
  if ((ret = git_atomic_dec(&git__n_inits)) != 0)
304
- goto out;
297
+ return ret;
298
+
299
+ if ((ret = pthread_mutex_lock(&_init_mutex)) != 0)
300
+ return ret;
305
301
 
306
302
  /* Shut down any subsystems that have global state */
307
303
  shutdown_common();
@@ -316,11 +312,10 @@ int git_libgit2_shutdown(void)
316
312
  git_mutex_free(&git__mwindow_mutex);
317
313
  _once_init = new_once;
318
314
 
319
- out:
320
- if ((error = pthread_mutex_unlock(&_init_mutex)) != 0)
321
- return error;
315
+ if ((ret = pthread_mutex_unlock(&_init_mutex)) != 0)
316
+ return ret;
322
317
 
323
- return ret;
318
+ return 0;
324
319
  }
325
320
 
326
321
  git_global_st *git__global_state(void)
@@ -26,8 +26,6 @@ void git_hash_ctx_cleanup(git_hash_ctx *ctx);
26
26
  # include "hash/hash_openssl.h"
27
27
  #elif defined(GIT_SHA1_WIN32)
28
28
  # include "hash/hash_win32.h"
29
- #elif defined(GIT_SHA1_MBEDTLS)
30
- # include "hash/hash_mbedtls.h"
31
29
  #else
32
30
  # include "hash/hash_generic.h"
33
31
  #endif
@@ -158,7 +158,7 @@ static int does_negate_rule(int *out, git_vector *rules, git_attr_fnmatch *match
158
158
 
159
159
  out:
160
160
  git__free(path);
161
- git_buf_dispose(&buf);
161
+ git_buf_free(&buf);
162
162
  return error;
163
163
  }
164
164
 
@@ -315,7 +315,7 @@ int git_ignore__for_path(
315
315
  (error = git_path_to_dir(&local)) < 0 ||
316
316
  (error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0)
317
317
  {;} /* Nothing, we just want to stop on the first error */
318
- git_buf_dispose(&local);
318
+ git_buf_free(&local);
319
319
  } else {
320
320
  error = git_buf_joinpath(&ignores->dir, path, "");
321
321
  }
@@ -355,7 +355,7 @@ int git_ignore__for_path(
355
355
  git_repository_attr_cache(repo)->cfg_excl_file);
356
356
 
357
357
  cleanup:
358
- git_buf_dispose(&infopath);
358
+ git_buf_free(&infopath);
359
359
  if (error < 0)
360
360
  git_ignore__free(ignores);
361
361
 
@@ -427,7 +427,7 @@ void git_ignore__free(git_ignores *ignores)
427
427
  }
428
428
  git_vector_free(&ignores->ign_global);
429
429
 
430
- git_buf_dispose(&ignores->dir);
430
+ git_buf_free(&ignores->dir);
431
431
  }
432
432
 
433
433
  static bool ignore_lookup_in_rules(
@@ -632,7 +632,7 @@ int git_ignore__check_pathspec_for_exact_ignores(
632
632
  }
633
633
 
634
634
  git_index_free(idx);
635
- git_buf_dispose(&path);
635
+ git_buf_free(&path);
636
636
 
637
637
  return error;
638
638
  }
@@ -135,8 +135,6 @@ struct reuc_entry_internal {
135
135
  char path[GIT_FLEX_ARRAY];
136
136
  };
137
137
 
138
- bool git_index__enforce_unsaved_safety = false;
139
-
140
138
  /* local declarations */
141
139
  static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size);
142
140
  static int read_header(struct index_header *dest, const void *buffer);
@@ -518,8 +516,6 @@ static int index_remove_entry(git_index *index, size_t pos)
518
516
  } else {
519
517
  index_entry_free(entry);
520
518
  }
521
-
522
- index->dirty = 1;
523
519
  }
524
520
 
525
521
  return error;
@@ -531,7 +527,6 @@ int git_index_clear(git_index *index)
531
527
 
532
528
  assert(index);
533
529
 
534
- index->dirty = 1;
535
530
  index->tree = NULL;
536
531
  git_pool_clear(&index->tree_pool);
537
532
 
@@ -642,10 +637,8 @@ int git_index_read(git_index *index, int force)
642
637
  index->on_disk = git_path_exists(index->index_file_path);
643
638
 
644
639
  if (!index->on_disk) {
645
- if (force && (error = git_index_clear(index)) < 0)
646
- return error;
647
-
648
- index->dirty = 0;
640
+ if (force)
641
+ return git_index_clear(index);
649
642
  return 0;
650
643
  }
651
644
 
@@ -657,7 +650,6 @@ int git_index_read(git_index *index, int force)
657
650
  index->index_file_path);
658
651
  return updated;
659
652
  }
660
-
661
653
  if (!updated && !force)
662
654
  return 0;
663
655
 
@@ -673,26 +665,13 @@ int git_index_read(git_index *index, int force)
673
665
  if (!error)
674
666
  error = parse_index(index, buffer.ptr, buffer.size);
675
667
 
676
- if (!error) {
668
+ if (!error)
677
669
  git_futils_filestamp_set(&index->stamp, &stamp);
678
- index->dirty = 0;
679
- }
680
670
 
681
- git_buf_dispose(&buffer);
671
+ git_buf_free(&buffer);
682
672
  return error;
683
673
  }
684
674
 
685
- int git_index_read_safely(git_index *index)
686
- {
687
- if (git_index__enforce_unsaved_safety && index->dirty) {
688
- giterr_set(GITERR_INDEX,
689
- "the index has unsaved changes that would be overwritten by this operation");
690
- return GIT_EINDEXDIRTY;
691
- }
692
-
693
- return git_index_read(index, false);
694
- }
695
-
696
675
  int git_index__changed_relative_to(
697
676
  git_index *index, const git_oid *checksum)
698
677
  {
@@ -756,10 +735,8 @@ static int truncate_racily_clean(git_index *index)
756
735
  /* Ensure that we have a stage 0 for this file (ie, it's not a
757
736
  * conflict), otherwise smudging it is quite pointless.
758
737
  */
759
- if (entry) {
738
+ if (entry)
760
739
  entry->file_size = 0;
761
- index->dirty = 1;
762
- }
763
740
  }
764
741
 
765
742
  done:
@@ -797,9 +774,8 @@ int git_index_write(git_index *index)
797
774
 
798
775
  truncate_racily_clean(index);
799
776
 
800
- if ((error = git_indexwriter_init(&writer, index)) == 0 &&
801
- (error = git_indexwriter_commit(&writer)) == 0)
802
- index->dirty = 0;
777
+ if ((error = git_indexwriter_init(&writer, index)) == 0)
778
+ error = git_indexwriter_commit(&writer);
803
779
 
804
780
  git_indexwriter_cleanup(&writer);
805
781
 
@@ -973,7 +949,7 @@ static int index_entry_init(
973
949
  return -1;
974
950
 
975
951
  error = git_path_lstat(path.ptr, &st);
976
- git_buf_dispose(&path);
952
+ git_buf_free(&path);
977
953
 
978
954
  if (error < 0)
979
955
  return error;
@@ -1413,8 +1389,6 @@ static int index_insert(
1413
1389
  if (error < 0) {
1414
1390
  index_entry_free(*entry_ptr);
1415
1391
  *entry_ptr = NULL;
1416
- } else {
1417
- index->dirty = 1;
1418
1392
  }
1419
1393
 
1420
1394
  return error;
@@ -1535,7 +1509,7 @@ static int add_repo_as_submodule(git_index_entry **out, git_index *index, const
1535
1509
 
1536
1510
  git_reference_free(head);
1537
1511
  git_repository_free(sub);
1538
- git_buf_dispose(&abspath);
1512
+ git_buf_free(&abspath);
1539
1513
 
1540
1514
  *out = entry;
1541
1515
  return 0;
@@ -1642,8 +1616,6 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
1642
1616
  INSERT_IN_MAP(index, entry, &ret);
1643
1617
  if (ret < 0)
1644
1618
  break;
1645
-
1646
- index->dirty = 1;
1647
1619
  }
1648
1620
 
1649
1621
  if (!ret)
@@ -1721,7 +1693,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage)
1721
1693
  /* removed entry at 'pos' so we don't need to increment */
1722
1694
  }
1723
1695
 
1724
- git_buf_dispose(&pfx);
1696
+ git_buf_free(&pfx);
1725
1697
 
1726
1698
  return error;
1727
1699
  }
@@ -1802,7 +1774,8 @@ int git_index_conflict_add(git_index *index,
1802
1774
  if (entries[i] && !valid_filemode(entries[i]->mode)) {
1803
1775
  giterr_set(GITERR_INDEX, "invalid filemode for stage %d entry",
1804
1776
  i + 1);
1805
- return -1;
1777
+ ret = -1;
1778
+ goto on_error;
1806
1779
  }
1807
1780
  }
1808
1781
 
@@ -2081,7 +2054,6 @@ int git_index_name_add(git_index *index,
2081
2054
  return -1;
2082
2055
  }
2083
2056
 
2084
- index->dirty = 1;
2085
2057
  return 0;
2086
2058
  }
2087
2059
 
@@ -2096,8 +2068,6 @@ void git_index_name_clear(git_index *index)
2096
2068
  index_name_entry_free(conflict_name);
2097
2069
 
2098
2070
  git_vector_clear(&index->names);
2099
-
2100
- index->dirty = 1;
2101
2071
  }
2102
2072
 
2103
2073
  size_t git_index_reuc_entrycount(git_index *index)
@@ -2123,8 +2093,6 @@ static int index_reuc_insert(
2123
2093
  assert(git_vector_is_sorted(&index->reuc));
2124
2094
 
2125
2095
  res = git_vector_insert_sorted(&index->reuc, reuc, &index_reuc_on_dup);
2126
- index->dirty = 1;
2127
-
2128
2096
  return res == GIT_EEXISTS ? 0 : res;
2129
2097
  }
2130
2098
 
@@ -2190,7 +2158,6 @@ int git_index_reuc_remove(git_index *index, size_t position)
2190
2158
  if (!error)
2191
2159
  index_entry_reuc_free(reuc);
2192
2160
 
2193
- index->dirty = 1;
2194
2161
  return error;
2195
2162
  }
2196
2163
 
@@ -2204,8 +2171,6 @@ void git_index_reuc_clear(git_index *index)
2204
2171
  index_entry_reuc_free(git__swap(index->reuc.contents[i], NULL));
2205
2172
 
2206
2173
  git_vector_clear(&index->reuc);
2207
-
2208
- index->dirty = 1;
2209
2174
  }
2210
2175
 
2211
2176
  static int index_error_invalid(const char *message)
@@ -2242,7 +2207,7 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
2242
2207
  for (i = 0; i < 3; i++) {
2243
2208
  int64_t tmp;
2244
2209
 
2245
- if (git__strtol64(&tmp, buffer, &endptr, 8) < 0 ||
2210
+ if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
2246
2211
  !endptr || endptr == buffer || *endptr ||
2247
2212
  tmp < 0 || tmp > UINT32_MAX) {
2248
2213
  index_entry_reuc_free(lost);
@@ -2640,7 +2605,6 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
2640
2605
  git_vector_set_sorted(&index->entries, !index->ignore_case);
2641
2606
  git_vector_sort(&index->entries);
2642
2607
 
2643
- index->dirty = 0;
2644
2608
  done:
2645
2609
  return error;
2646
2610
  }
@@ -2666,7 +2630,7 @@ static bool is_index_extended(git_index *index)
2666
2630
  static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const char *last)
2667
2631
  {
2668
2632
  void *mem = NULL;
2669
- struct entry_short ondisk;
2633
+ struct entry_short *ondisk;
2670
2634
  size_t path_len, disk_size;
2671
2635
  int varint_len = 0;
2672
2636
  char *path;
@@ -2694,7 +2658,9 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
2694
2658
  if (git_filebuf_reserve(file, &mem, disk_size) < 0)
2695
2659
  return -1;
2696
2660
 
2697
- memset(mem, 0x0, disk_size);
2661
+ ondisk = (struct entry_short *)mem;
2662
+
2663
+ memset(ondisk, 0x0, disk_size);
2698
2664
 
2699
2665
  /**
2700
2666
  * Yes, we have to truncate.
@@ -2706,32 +2672,30 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
2706
2672
  *
2707
2673
  * In 2038 I will be either too dead or too rich to care about this
2708
2674
  */
2709
- ondisk.ctime.seconds = htonl((uint32_t)entry->ctime.seconds);
2710
- ondisk.mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
2711
- ondisk.ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
2712
- ondisk.mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
2713
- ondisk.dev = htonl(entry->dev);
2714
- ondisk.ino = htonl(entry->ino);
2715
- ondisk.mode = htonl(entry->mode);
2716
- ondisk.uid = htonl(entry->uid);
2717
- ondisk.gid = htonl(entry->gid);
2718
- ondisk.file_size = htonl((uint32_t)entry->file_size);
2675
+ ondisk->ctime.seconds = htonl((uint32_t)entry->ctime.seconds);
2676
+ ondisk->mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
2677
+ ondisk->ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
2678
+ ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
2679
+ ondisk->dev = htonl(entry->dev);
2680
+ ondisk->ino = htonl(entry->ino);
2681
+ ondisk->mode = htonl(entry->mode);
2682
+ ondisk->uid = htonl(entry->uid);
2683
+ ondisk->gid = htonl(entry->gid);
2684
+ ondisk->file_size = htonl((uint32_t)entry->file_size);
2719
2685
 
2720
- git_oid_cpy(&ondisk.oid, &entry->id);
2686
+ git_oid_cpy(&ondisk->oid, &entry->id);
2721
2687
 
2722
- ondisk.flags = htons(entry->flags);
2688
+ ondisk->flags = htons(entry->flags);
2723
2689
 
2724
2690
  if (entry->flags & GIT_IDXENTRY_EXTENDED) {
2725
- struct entry_long ondisk_ext;
2726
- memcpy(&ondisk_ext, &ondisk, sizeof(struct entry_short));
2727
- ondisk_ext.flags_extended = htons(entry->flags_extended &
2691
+ struct entry_long *ondisk_ext;
2692
+ ondisk_ext = (struct entry_long *)ondisk;
2693
+ ondisk_ext->flags_extended = htons(entry->flags_extended &
2728
2694
  GIT_IDXENTRY_EXTENDED_FLAGS);
2729
- memcpy(mem, &ondisk_ext, offsetof(struct entry_long, path));
2730
- path = ((struct entry_long*)mem)->path;
2695
+ path = ondisk_ext->path;
2731
2696
  disk_size -= offsetof(struct entry_long, path);
2732
2697
  } else {
2733
- memcpy(mem, &ondisk, offsetof(struct entry_short, path));
2734
- path = ((struct entry_short*)mem)->path;
2698
+ path = ondisk->path;
2735
2699
  disk_size -= offsetof(struct entry_short, path);
2736
2700
  }
2737
2701
 
@@ -2856,7 +2820,7 @@ static int write_name_extension(git_index *index, git_filebuf *file)
2856
2820
 
2857
2821
  error = write_extension(file, &extension, &name_buf);
2858
2822
 
2859
- git_buf_dispose(&name_buf);
2823
+ git_buf_free(&name_buf);
2860
2824
 
2861
2825
  done:
2862
2826
  return error;
@@ -2904,7 +2868,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
2904
2868
 
2905
2869
  error = write_extension(file, &extension, &reuc_buf);
2906
2870
 
2907
- git_buf_dispose(&reuc_buf);
2871
+ git_buf_free(&reuc_buf);
2908
2872
 
2909
2873
  done:
2910
2874
  return error;
@@ -2928,7 +2892,7 @@ static int write_tree_extension(git_index *index, git_filebuf *file)
2928
2892
 
2929
2893
  error = write_extension(file, &extension, &buf);
2930
2894
 
2931
- git_buf_dispose(&buf);
2895
+ git_buf_free(&buf);
2932
2896
 
2933
2897
  return error;
2934
2898
  }
@@ -3045,7 +3009,7 @@ static int read_tree_cb(
3045
3009
  }
3046
3010
 
3047
3011
  index_entry_adjust_namemask(entry, path.size);
3048
- git_buf_dispose(&path);
3012
+ git_buf_free(&path);
3049
3013
 
3050
3014
  if (git_vector_insert(data->new_entries, entry) < 0) {
3051
3015
  index_entry_free(entry);
@@ -3107,8 +3071,6 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
3107
3071
  entries_map = git__swap(index->entries_map, entries_map);
3108
3072
  }
3109
3073
 
3110
- index->dirty = 1;
3111
-
3112
3074
  cleanup:
3113
3075
  git_vector_free(&entries);
3114
3076
  git_idxmap_free(entries_map);
@@ -3248,7 +3210,6 @@ static int git_index_read_iterator(
3248
3210
 
3249
3211
  clear_uptodate(index);
3250
3212
 
3251
- index->dirty = 1;
3252
3213
  error = 0;
3253
3214
 
3254
3215
  done:
@@ -3503,7 +3464,7 @@ static int index_apply_to_all(
3503
3464
  }
3504
3465
  }
3505
3466
 
3506
- git_buf_dispose(&path);
3467
+ git_buf_free(&path);
3507
3468
  git_pathspec__clear(&ps);
3508
3469
 
3509
3470
  return error;
@@ -3549,7 +3510,7 @@ int git_index_snapshot_new(git_vector *snap, git_index *index)
3549
3510
  error = git_vector_dup(snap, &index->entries, index->entries._cmp);
3550
3511
 
3551
3512
  if (error < 0)
3552
- git_index_free(index);
3513
+ git_index_snapshot_release(snap, index);
3553
3514
 
3554
3515
  return error;
3555
3516
  }
@@ -3641,7 +3602,6 @@ int git_indexwriter_commit(git_indexwriter *writer)
3641
3602
  return -1;
3642
3603
  }
3643
3604
 
3644
- writer->index->dirty = 0;
3645
3605
  writer->index->on_disk = 1;
3646
3606
  git_oid_cpy(&writer->index->checksum, &checksum);
3647
3607