rugged 0.26.0b5 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged.c +24 -0
  3. data/ext/rugged/rugged.h +2 -0
  4. data/ext/rugged/rugged_signature.c +15 -2
  5. data/lib/rugged/version.rb +1 -1
  6. data/vendor/libgit2/CMakeLists.txt +9 -8
  7. data/vendor/libgit2/include/git2/common.h +29 -0
  8. data/vendor/libgit2/include/git2/errors.h +2 -0
  9. data/vendor/libgit2/include/git2/global.h +1 -1
  10. data/vendor/libgit2/include/git2/odb.h +2 -2
  11. data/vendor/libgit2/include/git2/odb_backend.h +1 -1
  12. data/vendor/libgit2/include/git2/remote.h +3 -3
  13. data/vendor/libgit2/include/git2/repository.h +2 -2
  14. data/vendor/libgit2/include/git2/sys/filter.h +11 -0
  15. data/vendor/libgit2/include/git2/sys/merge.h +5 -5
  16. data/vendor/libgit2/include/git2/sys/transport.h +10 -0
  17. data/vendor/libgit2/include/git2/transport.h +6 -6
  18. data/vendor/libgit2/include/git2/version.h +3 -3
  19. data/vendor/libgit2/include/git2/worktree.h +69 -10
  20. data/vendor/libgit2/libgit2.pc.in +2 -2
  21. data/vendor/libgit2/src/attr_file.c +6 -2
  22. data/vendor/libgit2/src/attrcache.c +7 -5
  23. data/vendor/libgit2/src/blame_git.c +12 -8
  24. data/vendor/libgit2/src/branch.c +17 -48
  25. data/vendor/libgit2/src/buffer.c +11 -12
  26. data/vendor/libgit2/src/buffer.h +2 -2
  27. data/vendor/libgit2/src/checkout.c +3 -6
  28. data/vendor/libgit2/src/config.c +42 -35
  29. data/vendor/libgit2/src/config_cache.c +1 -0
  30. data/vendor/libgit2/src/config_file.c +19 -11
  31. data/vendor/libgit2/src/config_file.h +1 -0
  32. data/vendor/libgit2/src/diff.c +35 -0
  33. data/vendor/libgit2/src/diff_parse.c +7 -1
  34. data/vendor/libgit2/src/filebuf.c +12 -1
  35. data/vendor/libgit2/src/filebuf.h +3 -1
  36. data/vendor/libgit2/src/fileops.c +83 -22
  37. data/vendor/libgit2/src/fileops.h +25 -0
  38. data/vendor/libgit2/src/filter.c +30 -14
  39. data/vendor/libgit2/src/global.c +1 -1
  40. data/vendor/libgit2/src/hash/hash_collisiondetect.h +1 -11
  41. data/vendor/libgit2/src/hash/sha1dc/sha1.c +894 -187
  42. data/vendor/libgit2/src/hash/sha1dc/sha1.h +69 -53
  43. data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +13 -2
  44. data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +20 -3
  45. data/vendor/libgit2/src/idxmap.c +1 -1
  46. data/vendor/libgit2/src/idxmap.h +1 -2
  47. data/vendor/libgit2/src/index.c +75 -42
  48. data/vendor/libgit2/src/indexer.c +31 -11
  49. data/vendor/libgit2/src/indexer.h +12 -0
  50. data/vendor/libgit2/src/merge.c +20 -0
  51. data/vendor/libgit2/src/merge_driver.c +29 -0
  52. data/vendor/libgit2/src/odb.c +96 -19
  53. data/vendor/libgit2/src/odb.h +25 -0
  54. data/vendor/libgit2/src/odb_loose.c +20 -6
  55. data/vendor/libgit2/src/odb_pack.c +1 -1
  56. data/vendor/libgit2/src/offmap.c +1 -1
  57. data/vendor/libgit2/src/offmap.h +1 -2
  58. data/vendor/libgit2/src/oidmap.c +1 -1
  59. data/vendor/libgit2/src/oidmap.h +1 -2
  60. data/vendor/libgit2/src/openssl_stream.c +11 -4
  61. data/vendor/libgit2/src/pack-objects.c +4 -0
  62. data/vendor/libgit2/src/pack-objects.h +1 -0
  63. data/vendor/libgit2/src/pack.c +5 -3
  64. data/vendor/libgit2/src/patch_generate.c +8 -79
  65. data/vendor/libgit2/src/patch_parse.c +5 -4
  66. data/vendor/libgit2/src/path.c +9 -7
  67. data/vendor/libgit2/src/posix.c +2 -0
  68. data/vendor/libgit2/src/posix.h +10 -0
  69. data/vendor/libgit2/src/rebase.c +12 -10
  70. data/vendor/libgit2/src/refdb_fs.c +33 -10
  71. data/vendor/libgit2/src/refs.c +89 -8
  72. data/vendor/libgit2/src/refs.h +14 -0
  73. data/vendor/libgit2/src/remote.c +9 -10
  74. data/vendor/libgit2/src/repository.c +178 -146
  75. data/vendor/libgit2/src/repository.h +25 -0
  76. data/vendor/libgit2/src/revparse.c +22 -3
  77. data/vendor/libgit2/src/revwalk.c +6 -3
  78. data/vendor/libgit2/src/settings.c +22 -1
  79. data/vendor/libgit2/src/signature.c +4 -1
  80. data/vendor/libgit2/src/socket_stream.c +2 -4
  81. data/vendor/libgit2/src/strmap.c +1 -1
  82. data/vendor/libgit2/src/strmap.h +1 -3
  83. data/vendor/libgit2/src/submodule.c +27 -7
  84. data/vendor/libgit2/src/sysdir.c +11 -0
  85. data/vendor/libgit2/src/sysdir.h +12 -0
  86. data/vendor/libgit2/src/transports/http.c +3 -0
  87. data/vendor/libgit2/src/transports/smart.c +6 -0
  88. data/vendor/libgit2/src/transports/smart_protocol.c +2 -1
  89. data/vendor/libgit2/src/transports/ssh.c +13 -1
  90. data/vendor/libgit2/src/transports/winhttp.c +1 -2
  91. data/vendor/libgit2/src/tree.c +13 -11
  92. data/vendor/libgit2/src/unix/posix.h +6 -1
  93. data/vendor/libgit2/src/varint.c +1 -1
  94. data/vendor/libgit2/src/win32/posix.h +3 -0
  95. data/vendor/libgit2/src/win32/posix_w32.c +334 -111
  96. data/vendor/libgit2/src/worktree.c +174 -48
  97. data/vendor/libgit2/src/worktree.h +1 -1
  98. metadata +77 -76
@@ -31,6 +31,8 @@
31
31
  /* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */
32
32
  #define GIT_DIR_SHORTNAME "GIT~1"
33
33
 
34
+ extern bool git_repository__fsync_gitdir;
35
+
34
36
  /** Cvar cache identifiers */
35
37
  typedef enum {
36
38
  GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
@@ -46,6 +48,7 @@ typedef enum {
46
48
  GIT_CVAR_LOGALLREFUPDATES, /* core.logallrefupdates */
47
49
  GIT_CVAR_PROTECTHFS, /* core.protectHFS */
48
50
  GIT_CVAR_PROTECTNTFS, /* core.protectNTFS */
51
+ GIT_CVAR_FSYNCOBJECTFILES, /* core.fsyncObjectFiles */
49
52
  GIT_CVAR_CACHE_MAX
50
53
  } git_cvar_cached;
51
54
 
@@ -106,6 +109,8 @@ typedef enum {
106
109
  GIT_PROTECTHFS_DEFAULT = GIT_CVAR_FALSE,
107
110
  /* core.protectNTFS */
108
111
  GIT_PROTECTNTFS_DEFAULT = GIT_CVAR_FALSE,
112
+ /* core.fsyncObjectFiles */
113
+ GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CVAR_FALSE,
109
114
  } git_cvar_value;
110
115
 
111
116
  /* internal repository init flags */
@@ -156,6 +161,26 @@ GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
156
161
  int git_repository_head_tree(git_tree **tree, git_repository *repo);
157
162
  int git_repository_create_head(const char *git_dir, const char *ref_name);
158
163
 
164
+ /*
165
+ * Called for each HEAD.
166
+ *
167
+ * Can return either 0, causing the iteration over HEADs to
168
+ * continue, or a non-0 value causing the iteration to abort. The
169
+ * return value is passed back to the caller of
170
+ * `git_repository_foreach_head`
171
+ */
172
+ typedef int (*git_repository_foreach_head_cb)(git_repository *repo, const char *path, void *payload);
173
+
174
+ /*
175
+ * Iterate over repository and all worktree HEADs.
176
+ *
177
+ * This function will be called for the repository HEAD and for
178
+ * all HEADS of linked worktrees. For each HEAD, the callback is
179
+ * executed with the given payload. The return value equals the
180
+ * return value of the last executed callback function.
181
+ */
182
+ int git_repository_foreach_head(git_repository *repo, git_repository_foreach_head_cb cb, void *payload);
183
+
159
184
  /*
160
185
  * Weak pointers to repository internals.
161
186
  *
@@ -892,6 +892,17 @@ int git_revparse(
892
892
  const char *rstr;
893
893
  revspec->flags = GIT_REVPARSE_RANGE;
894
894
 
895
+ /*
896
+ * Following git.git, don't allow '..' because it makes command line
897
+ * arguments which can be either paths or revisions ambiguous when the
898
+ * path is almost certainly intended. The empty range '...' is still
899
+ * allowed.
900
+ */
901
+ if (!git__strcmp(spec, "..")) {
902
+ giterr_set(GITERR_INVALID, "Invalid pattern '..'");
903
+ return GIT_EINVALIDSPEC;
904
+ }
905
+
895
906
  lstr = git__substrdup(spec, dotdot - spec);
896
907
  rstr = dotdot + 2;
897
908
  if (dotdot[2] == '.') {
@@ -899,9 +910,17 @@ int git_revparse(
899
910
  rstr++;
900
911
  }
901
912
 
902
- error = git_revparse_single(&revspec->from, repo, lstr);
903
- if (!error)
904
- error = git_revparse_single(&revspec->to, repo, rstr);
913
+ error = git_revparse_single(
914
+ &revspec->from,
915
+ repo,
916
+ *lstr == '\0' ? "HEAD" : lstr);
917
+
918
+ if (!error) {
919
+ error = git_revparse_single(
920
+ &revspec->to,
921
+ repo,
922
+ *rstr == '\0' ? "HEAD" : rstr);
923
+ }
905
924
 
906
925
  git__free((void*)lstr);
907
926
  } else {
@@ -231,9 +231,12 @@ static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk
231
231
  {
232
232
  git_commit_list_node *next;
233
233
 
234
- if ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
235
- *object_out = next;
236
- return 0;
234
+ while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
235
+ /* Some commits might become uninteresting after being added to the list */
236
+ if (!next->uninteresting) {
237
+ *object_out = next;
238
+ return 0;
239
+ }
237
240
  }
238
241
 
239
242
  giterr_clear();
@@ -15,6 +15,7 @@
15
15
  #include "cache.h"
16
16
  #include "global.h"
17
17
  #include "object.h"
18
+ #include "odb.h"
18
19
  #include "refs.h"
19
20
  #include "transports/smart.h"
20
21
 
@@ -31,7 +32,7 @@ int git_libgit2_features(void)
31
32
  #ifdef GIT_THREADS
32
33
  | GIT_FEATURE_THREADS
33
34
  #endif
34
- #if defined(GIT_OPENSSL) || defined(GIT_WINHTTP) || defined(GIT_SECURE_TRANSPORT)
35
+ #ifdef GIT_HTTPS
35
36
  | GIT_FEATURE_HTTPS
36
37
  #endif
37
38
  #if defined(GIT_SSH)
@@ -227,6 +228,26 @@ int git_libgit2_opts(int key, ...)
227
228
  git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0);
228
229
  break;
229
230
 
231
+ case GIT_OPT_ENABLE_FSYNC_GITDIR:
232
+ git_repository__fsync_gitdir = (va_arg(ap, int) != 0);
233
+ break;
234
+
235
+ case GIT_OPT_GET_WINDOWS_SHAREMODE:
236
+ #ifdef GIT_WIN32
237
+ *(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode;
238
+ #endif
239
+ break;
240
+
241
+ case GIT_OPT_SET_WINDOWS_SHAREMODE:
242
+ #ifdef GIT_WIN32
243
+ git_win32__createfile_sharemode = va_arg(ap, unsigned long);
244
+ #endif
245
+ break;
246
+
247
+ case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION:
248
+ git_odb__strict_hash_verification = (va_arg(ap, int) != 0);
249
+ break;
250
+
230
251
  default:
231
252
  giterr_set(GITERR_INVALID, "invalid option key");
232
253
  error = -1;
@@ -228,8 +228,11 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
228
228
  const char *time_start = email_end + 2;
229
229
  const char *time_end;
230
230
 
231
- if (git__strtol64(&sig->when.time, time_start, &time_end, 10) < 0)
231
+ if (git__strtol64(&sig->when.time, time_start, &time_end, 10) < 0) {
232
+ git__free(sig->name);
233
+ git__free(sig->email);
232
234
  return signature_error("invalid Unix timestamp");
235
+ }
233
236
 
234
237
  /* do we have a timezone? */
235
238
  if (time_end + 1 < buffer_end) {
@@ -106,10 +106,8 @@ int socket_connect(git_stream *stream)
106
106
  for (p = info; p != NULL; p = p->ai_next) {
107
107
  s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
108
108
 
109
- if (s == INVALID_SOCKET) {
110
- net_set_error("error creating socket");
111
- break;
112
- }
109
+ if (s == INVALID_SOCKET)
110
+ continue;
113
111
 
114
112
  if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0)
115
113
  break;
@@ -19,7 +19,7 @@ int git_strmap_alloc(git_strmap **map)
19
19
  return 0;
20
20
  }
21
21
 
22
- void git_strmap__free(git_strmap *map)
22
+ void git_strmap_free(git_strmap *map)
23
23
  {
24
24
  kh_destroy(str, map);
25
25
  }
@@ -21,9 +21,7 @@ typedef khash_t(str) git_strmap;
21
21
  typedef khiter_t git_strmap_iter;
22
22
 
23
23
  int git_strmap_alloc(git_strmap **map);
24
-
25
- #define git_strmap_free(h) git_strmap__free(h); (h) = NULL
26
- void git_strmap__free(git_strmap *map);
24
+ void git_strmap_free(git_strmap *map);
27
25
  void git_strmap_clear(git_strmap *map);
28
26
 
29
27
  size_t git_strmap_num_entries(git_strmap *map);
@@ -22,6 +22,7 @@
22
22
  #include "iterator.h"
23
23
  #include "path.h"
24
24
  #include "index.h"
25
+ #include "worktree.h"
25
26
 
26
27
  #define GIT_MODULES_FILE ".gitmodules"
27
28
 
@@ -1212,6 +1213,8 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
1212
1213
  (error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0)
1213
1214
  goto done;
1214
1215
  } else {
1216
+ const git_oid *oid;
1217
+
1215
1218
  /**
1216
1219
  * Work dir is initialized - look up the commit in the parent repository's index,
1217
1220
  * update the workdir contents of the subrepository, and set the subrepository's
@@ -1220,8 +1223,14 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
1220
1223
  if ((error = git_submodule_open(&sub_repo, sm)) < 0)
1221
1224
  goto done;
1222
1225
 
1226
+ if ((oid = git_submodule_index_id(sm)) == NULL) {
1227
+ giterr_set(GITERR_SUBMODULE, "could not get ID of submodule in index");
1228
+ error = -1;
1229
+ goto done;
1230
+ }
1231
+
1223
1232
  /* Look up the target commit in the submodule. */
1224
- if ((error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJ_COMMIT)) < 0) {
1233
+ if ((error = git_object_lookup(&target_commit, sub_repo, oid, GIT_OBJ_COMMIT)) < 0) {
1225
1234
  /* If it isn't found then fetch and try again. */
1226
1235
  if (error != GIT_ENOTFOUND || !update_options.allow_fetch ||
1227
1236
  (error = lookup_default_remote(&remote, sub_repo)) < 0 ||
@@ -2030,17 +2039,28 @@ static int lookup_default_remote(git_remote **remote, git_repository *repo)
2030
2039
  static int get_url_base(git_buf *url, git_repository *repo)
2031
2040
  {
2032
2041
  int error;
2042
+ git_worktree *wt = NULL;
2033
2043
  git_remote *remote = NULL;
2034
2044
 
2035
- if (!(error = lookup_default_remote(&remote, repo))) {
2045
+ if ((error = lookup_default_remote(&remote, repo)) == 0) {
2036
2046
  error = git_buf_sets(url, git_remote_url(remote));
2037
- git_remote_free(remote);
2038
- }
2039
- else if (error == GIT_ENOTFOUND) {
2040
- /* if repository does not have a default remote, use workdir instead */
2047
+ goto out;
2048
+ } else if (error != GIT_ENOTFOUND)
2049
+ goto out;
2050
+ else
2041
2051
  giterr_clear();
2052
+
2053
+ /* if repository does not have a default remote, use workdir instead */
2054
+ if (git_repository_is_worktree(repo)) {
2055
+ if ((error = git_worktree_open_from_repository(&wt, repo)) < 0)
2056
+ goto out;
2057
+ error = git_buf_sets(url, wt->parent_path);
2058
+ } else
2042
2059
  error = git_buf_sets(url, git_repository_workdir(repo));
2043
- }
2060
+
2061
+ out:
2062
+ git_remote_free(remote);
2063
+ git_worktree_free(wt);
2044
2064
 
2045
2065
  return error;
2046
2066
  }
@@ -275,3 +275,14 @@ int git_sysdir_find_template_dir(git_buf *path)
275
275
  path, NULL, GIT_SYSDIR_TEMPLATE, "template");
276
276
  }
277
277
 
278
+ int git_sysdir_expand_global_file(git_buf *path, const char *filename)
279
+ {
280
+ int error;
281
+
282
+ if ((error = git_sysdir_find_global_file(path, NULL)) == 0) {
283
+ if (filename)
284
+ error = git_buf_joinpath(path, path->ptr, filename);
285
+ }
286
+
287
+ return error;
288
+ }
@@ -55,6 +55,18 @@ extern int git_sysdir_find_programdata_file(git_buf *path, const char *filename)
55
55
  */
56
56
  extern int git_sysdir_find_template_dir(git_buf *path);
57
57
 
58
+ /**
59
+ * Expand the name of a "global" file (i.e. one in a user's home
60
+ * directory). Unlike `find_global_file` (above), this makes no
61
+ * attempt to check for the existence of the file, and is useful if
62
+ * you want the full path regardless of existence.
63
+ *
64
+ * @param path buffer to write the full path into
65
+ * @param filename name of file in the home directory
66
+ * @return 0 on success or -1 on error
67
+ */
68
+ extern int git_sysdir_expand_global_file(git_buf *path, const char *filename);
69
+
58
70
  typedef enum {
59
71
  GIT_SYSDIR_SYSTEM = 0,
60
72
  GIT_SYSDIR_GLOBAL = 1,
@@ -575,6 +575,9 @@ static int apply_proxy_config(http_subtransport *t)
575
575
  if ((error = git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &url)) < 0)
576
576
  return error;
577
577
 
578
+ opts.credentials = t->owner->proxy.credentials;
579
+ opts.certificate_check = t->owner->proxy.certificate_check;
580
+ opts.payload = t->owner->proxy.payload;
578
581
  opts.type = GIT_PROXY_SPECIFIED;
579
582
  opts.url = url;
580
583
  error = git_stream_set_proxy(t->io, &opts);
@@ -472,6 +472,12 @@ int git_transport_smart_credentials(git_cred **out, git_transport *transport, co
472
472
  return t->cred_acquire_cb(out, t->url, user, methods, t->cred_acquire_payload);
473
473
  }
474
474
 
475
+ int git_transport_smart_proxy_options(git_proxy_options *out, git_transport *transport)
476
+ {
477
+ transport_smart *t = (transport_smart *) transport;
478
+ return git_proxy_options_dup(out, &t->proxy);
479
+ }
480
+
475
481
  int git_transport_smart(git_transport **out, git_remote *owner, void *param)
476
482
  {
477
483
  transport_smart *t;
@@ -325,7 +325,8 @@ static int wait_while_ack(gitno_buffer *buf)
325
325
 
326
326
  if (pkt->type == GIT_PKT_ACK &&
327
327
  (pkt->status != GIT_ACK_CONTINUE &&
328
- pkt->status != GIT_ACK_COMMON)) {
328
+ pkt->status != GIT_ACK_COMMON &&
329
+ pkt->status != GIT_ACK_READY)) {
329
330
  git__free(pkt);
330
331
  return 0;
331
332
  }
@@ -9,6 +9,7 @@
9
9
  #include <libssh2.h>
10
10
  #endif
11
11
 
12
+ #include "global.h"
12
13
  #include "git2.h"
13
14
  #include "buffer.h"
14
15
  #include "netops.h"
@@ -893,11 +894,22 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
893
894
  #endif
894
895
  }
895
896
 
897
+ #ifdef GIT_SSH
898
+ static void shutdown_ssh(void)
899
+ {
900
+ libssh2_exit();
901
+ }
902
+ #endif
903
+
896
904
  int git_transport_ssh_global_init(void)
897
905
  {
898
906
  #ifdef GIT_SSH
907
+ if (libssh2_init(0) < 0) {
908
+ giterr_set(GITERR_SSH, "unable to initialize libssh2");
909
+ return -1;
910
+ }
899
911
 
900
- libssh2_init(0);
912
+ git__on_shutdown(shutdown_ssh);
901
913
  return 0;
902
914
 
903
915
  #else
@@ -429,7 +429,6 @@ static int winhttp_stream_connect(winhttp_stream *s)
429
429
  git_buf_printf(&processed_url, ":%s", t->proxy_connection_data.port);
430
430
 
431
431
  if (git_buf_oom(&processed_url)) {
432
- giterr_set_oom();
433
432
  error = -1;
434
433
  goto on_error;
435
434
  }
@@ -881,7 +880,7 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length)
881
880
  }
882
881
 
883
882
  if ((error = do_send_request(s, len, ignore_length)) < 0)
884
- giterr_set(GITERR_OS, "failed to send request");
883
+ giterr_set(GITERR_OS, "failed to send request with unchecked certificate");
885
884
 
886
885
  return error;
887
886
  }
@@ -818,7 +818,7 @@ int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_bu
818
818
  size_t i, entrycount;
819
819
  git_odb *odb;
820
820
  git_tree_entry *entry;
821
- git_vector entries;
821
+ git_vector entries = GIT_VECTOR_INIT;
822
822
 
823
823
  assert(bld);
824
824
  assert(tree);
@@ -826,35 +826,37 @@ int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_bu
826
826
  git_buf_clear(tree);
827
827
 
828
828
  entrycount = git_strmap_num_entries(bld->map);
829
- if (git_vector_init(&entries, entrycount, entry_sort_cmp) < 0)
830
- return -1;
829
+ if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
830
+ goto out;
831
831
 
832
832
  if (tree->asize == 0 &&
833
- (error = git_buf_grow(tree, entrycount * 72)) < 0)
834
- return error;
833
+ (error = git_buf_grow(tree, entrycount * 72)) < 0)
834
+ goto out;
835
835
 
836
836
  git_strmap_foreach_value(bld->map, entry, {
837
- if (git_vector_insert(&entries, entry) < 0)
838
- return -1;
837
+ if ((error = git_vector_insert(&entries, entry)) < 0)
838
+ goto out;
839
839
  });
840
840
 
841
841
  git_vector_sort(&entries);
842
842
 
843
843
  for (i = 0; i < entries.length && !error; ++i) {
844
- git_tree_entry *entry = git_vector_get(&entries, i);
844
+ entry = git_vector_get(&entries, i);
845
845
 
846
846
  git_buf_printf(tree, "%o ", entry->attr);
847
847
  git_buf_put(tree, entry->filename, entry->filename_len + 1);
848
848
  git_buf_put(tree, (char *)entry->oid->id, GIT_OID_RAWSZ);
849
849
 
850
- if (git_buf_oom(tree))
850
+ if (git_buf_oom(tree)) {
851
851
  error = -1;
852
+ goto out;
853
+ }
852
854
  }
853
855
 
854
- if (!error &&
855
- !(error = git_repository_odb__weakptr(&odb, bld->repo)))
856
+ if ((error = git_repository_odb__weakptr(&odb, bld->repo)) == 0)
856
857
  error = git_odb_write(oid, odb, tree->ptr, tree->size, GIT_OBJ_TREE);
857
858
 
859
+ out:
858
860
  git_vector_free(&entries);
859
861
 
860
862
  return error;
@@ -40,9 +40,14 @@ typedef int GIT_SOCKET;
40
40
  #define p_link(o,n) link(o, n)
41
41
  #define p_unlink(p) unlink(p)
42
42
  #define p_mkdir(p,m) mkdir(p, m)
43
- #define p_fsync(fd) fsync(fd)
44
43
  extern char *p_realpath(const char *, char *);
45
44
 
45
+ GIT_INLINE(int) p_fsync(int fd)
46
+ {
47
+ p_fsync__cnt++;
48
+ return fsync(fd);
49
+ }
50
+
46
51
  #define p_recv(s,b,l,f) recv(s,b,l,f)
47
52
  #define p_send(s,b,l,f) send(s,b,l,f)
48
53
  #define p_inet_pton(a, b, c) inet_pton(a, b, c)