rugged 1.0.1 → 1.1.0

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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_commit.c +1 -1
  3. data/lib/rugged/commit.rb +16 -2
  4. data/lib/rugged/version.rb +1 -1
  5. data/vendor/libgit2/CMakeLists.txt +31 -69
  6. data/vendor/libgit2/cmake/{Modules/AddCFlagIfSupported.cmake → AddCFlagIfSupported.cmake} +0 -0
  7. data/vendor/libgit2/cmake/{Modules/EnableWarnings.cmake → EnableWarnings.cmake} +0 -0
  8. data/vendor/libgit2/cmake/{Modules/FindCoreFoundation.cmake → FindCoreFoundation.cmake} +0 -0
  9. data/vendor/libgit2/cmake/{Modules/FindGSSAPI.cmake → FindGSSAPI.cmake} +0 -0
  10. data/vendor/libgit2/cmake/{Modules/FindGSSFramework.cmake → FindGSSFramework.cmake} +0 -0
  11. data/vendor/libgit2/cmake/{Modules/FindHTTP_Parser.cmake → FindHTTP_Parser.cmake} +0 -0
  12. data/vendor/libgit2/cmake/{Modules/FindIconv.cmake → FindIconv.cmake} +0 -0
  13. data/vendor/libgit2/cmake/{Modules/FindPCRE.cmake → FindPCRE.cmake} +0 -0
  14. data/vendor/libgit2/cmake/{Modules/FindPCRE2.cmake → FindPCRE2.cmake} +0 -0
  15. data/vendor/libgit2/cmake/{Modules/FindPkgLibraries.cmake → FindPkgLibraries.cmake} +0 -0
  16. data/vendor/libgit2/cmake/{Modules/FindSecurity.cmake → FindSecurity.cmake} +0 -0
  17. data/vendor/libgit2/cmake/{Modules/FindStatNsec.cmake → FindStatNsec.cmake} +0 -0
  18. data/vendor/libgit2/cmake/{Modules/FindmbedTLS.cmake → FindmbedTLS.cmake} +0 -0
  19. data/vendor/libgit2/cmake/{Modules/IdeSplitSources.cmake → IdeSplitSources.cmake} +0 -0
  20. data/vendor/libgit2/cmake/{Modules/PkgBuildConfig.cmake → PkgBuildConfig.cmake} +0 -0
  21. data/vendor/libgit2/cmake/{Modules/SanitizeBool.cmake → SanitizeBool.cmake} +0 -0
  22. data/vendor/libgit2/cmake/{Modules/SelectGSSAPI.cmake → SelectGSSAPI.cmake} +18 -26
  23. data/vendor/libgit2/cmake/{Modules/SelectHTTPSBackend.cmake → SelectHTTPSBackend.cmake} +25 -32
  24. data/vendor/libgit2/cmake/{Modules/SelectHashes.cmake → SelectHashes.cmake} +20 -28
  25. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +4 -3
  26. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +6 -5
  27. data/vendor/libgit2/deps/ntlmclient/compat.h +8 -1
  28. data/vendor/libgit2/deps/ntlmclient/ntlm.c +8 -11
  29. data/vendor/libgit2/deps/pcre/LICENCE +93 -0
  30. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  31. data/vendor/libgit2/deps/pcre/pcre_compile.c +29 -17
  32. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +4 -4
  33. data/vendor/libgit2/deps/pcre/pcreposix.c +2 -3
  34. data/vendor/libgit2/deps/zlib/CMakeLists.txt +6 -5
  35. data/vendor/libgit2/deps/zlib/deflate.c +1 -0
  36. data/vendor/libgit2/include/git2/annotated_commit.h +1 -1
  37. data/vendor/libgit2/include/git2/blame.h +2 -0
  38. data/vendor/libgit2/include/git2/common.h +15 -3
  39. data/vendor/libgit2/include/git2/deprecated.h +42 -2
  40. data/vendor/libgit2/include/git2/errors.h +2 -1
  41. data/vendor/libgit2/include/git2/index.h +1 -2
  42. data/vendor/libgit2/include/git2/pack.h +1 -1
  43. data/vendor/libgit2/include/git2/strarray.h +6 -10
  44. data/vendor/libgit2/include/git2/version.h +4 -4
  45. data/vendor/libgit2/src/CMakeLists.txt +53 -41
  46. data/vendor/libgit2/src/apply.c +5 -1
  47. data/vendor/libgit2/src/assert_safe.h +58 -0
  48. data/vendor/libgit2/src/attr_file.c +8 -3
  49. data/vendor/libgit2/src/attrcache.c +2 -3
  50. data/vendor/libgit2/src/blame.c +2 -0
  51. data/vendor/libgit2/src/blame_git.c +6 -3
  52. data/vendor/libgit2/src/blob.c +2 -0
  53. data/vendor/libgit2/src/branch.c +19 -21
  54. data/vendor/libgit2/src/buffer.c +6 -3
  55. data/vendor/libgit2/src/cache.c +1 -22
  56. data/vendor/libgit2/src/checkout.c +49 -72
  57. data/vendor/libgit2/src/cherrypick.c +2 -0
  58. data/vendor/libgit2/src/clone.c +78 -18
  59. data/vendor/libgit2/src/common.h +1 -0
  60. data/vendor/libgit2/src/config.c +3 -7
  61. data/vendor/libgit2/src/config_entries.c +35 -27
  62. data/vendor/libgit2/src/config_parse.c +1 -1
  63. data/vendor/libgit2/src/config_snapshot.c +2 -1
  64. data/vendor/libgit2/src/describe.c +5 -1
  65. data/vendor/libgit2/src/diff.c +12 -11
  66. data/vendor/libgit2/src/diff_file.c +3 -1
  67. data/vendor/libgit2/src/diff_generate.c +10 -11
  68. data/vendor/libgit2/src/diff_parse.c +2 -3
  69. data/vendor/libgit2/src/diff_print.c +63 -60
  70. data/vendor/libgit2/src/diff_stats.c +12 -11
  71. data/vendor/libgit2/src/diff_tform.c +2 -3
  72. data/vendor/libgit2/src/errors.c +2 -0
  73. data/vendor/libgit2/src/fetch.c +2 -0
  74. data/vendor/libgit2/src/filter.c +3 -3
  75. data/vendor/libgit2/src/futils.c +3 -3
  76. data/vendor/libgit2/src/futils.h +3 -3
  77. data/vendor/libgit2/src/global.c +3 -1
  78. data/vendor/libgit2/src/idxmap.c +0 -22
  79. data/vendor/libgit2/src/index.c +12 -7
  80. data/vendor/libgit2/src/indexer.c +10 -4
  81. data/vendor/libgit2/src/iterator.c +4 -4
  82. data/vendor/libgit2/src/merge.c +13 -7
  83. data/vendor/libgit2/src/merge_file.c +4 -6
  84. data/vendor/libgit2/src/midx.c +418 -0
  85. data/vendor/libgit2/src/midx.h +83 -0
  86. data/vendor/libgit2/src/mwindow.c +124 -51
  87. data/vendor/libgit2/src/net.c +6 -1
  88. data/vendor/libgit2/src/object.c +2 -1
  89. data/vendor/libgit2/src/odb.c +9 -6
  90. data/vendor/libgit2/src/odb_loose.c +3 -3
  91. data/vendor/libgit2/src/odb_mempack.c +2 -0
  92. data/vendor/libgit2/src/oid.c +2 -0
  93. data/vendor/libgit2/src/pack-objects.c +29 -21
  94. data/vendor/libgit2/src/pack.c +47 -28
  95. data/vendor/libgit2/src/pack.h +19 -2
  96. data/vendor/libgit2/src/patch_generate.c +1 -3
  97. data/vendor/libgit2/src/patch_parse.c +4 -2
  98. data/vendor/libgit2/src/path.c +4 -4
  99. data/vendor/libgit2/src/pathspec.c +4 -3
  100. data/vendor/libgit2/src/pool.c +21 -15
  101. data/vendor/libgit2/src/pool.h +9 -1
  102. data/vendor/libgit2/src/proxy.c +2 -0
  103. data/vendor/libgit2/src/push.c +2 -0
  104. data/vendor/libgit2/src/rebase.c +2 -0
  105. data/vendor/libgit2/src/refdb.c +135 -0
  106. data/vendor/libgit2/src/refdb.h +69 -0
  107. data/vendor/libgit2/src/refdb_fs.c +19 -81
  108. data/vendor/libgit2/src/reflog.c +2 -6
  109. data/vendor/libgit2/src/refs.c +60 -188
  110. data/vendor/libgit2/src/refs.h +1 -19
  111. data/vendor/libgit2/src/regexp.c +2 -2
  112. data/vendor/libgit2/src/remote.c +32 -17
  113. data/vendor/libgit2/src/repository.c +168 -79
  114. data/vendor/libgit2/src/repository.h +10 -27
  115. data/vendor/libgit2/src/revert.c +2 -0
  116. data/vendor/libgit2/src/revparse.c +5 -4
  117. data/vendor/libgit2/src/revwalk.c +3 -5
  118. data/vendor/libgit2/src/settings.c +9 -0
  119. data/vendor/libgit2/src/sortedcache.c +2 -3
  120. data/vendor/libgit2/src/stash.c +2 -0
  121. data/vendor/libgit2/src/status.c +2 -0
  122. data/vendor/libgit2/src/strarray.c +63 -0
  123. data/vendor/libgit2/src/streams/openssl.c +12 -6
  124. data/vendor/libgit2/src/streams/registry.c +5 -3
  125. data/vendor/libgit2/src/submodule.c +6 -4
  126. data/vendor/libgit2/src/sysdir.c +4 -20
  127. data/vendor/libgit2/src/sysdir.h +0 -11
  128. data/vendor/libgit2/src/tag.c +2 -0
  129. data/vendor/libgit2/src/thread-utils.h +139 -21
  130. data/vendor/libgit2/src/transaction.c +2 -1
  131. data/vendor/libgit2/src/transports/credential.c +2 -0
  132. data/vendor/libgit2/src/transports/credential_helpers.c +2 -0
  133. data/vendor/libgit2/src/transports/httpclient.c +6 -8
  134. data/vendor/libgit2/src/transports/local.c +2 -2
  135. data/vendor/libgit2/src/transports/smart.c +2 -2
  136. data/vendor/libgit2/src/transports/winhttp.c +18 -7
  137. data/vendor/libgit2/src/unix/posix.h +13 -1
  138. data/vendor/libgit2/src/util.c +25 -58
  139. data/vendor/libgit2/src/util.h +2 -2
  140. data/vendor/libgit2/src/win32/git2.rc +18 -3
  141. data/vendor/libgit2/src/win32/path_w32.c +2 -2
  142. data/vendor/libgit2/src/worktree.c +4 -0
  143. metadata +27 -25
  144. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +0 -29
  145. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +0 -96
  146. data/vendor/libgit2/src/refdb_fs.h +0 -19
@@ -155,7 +155,9 @@ int git_fetch_options_init(git_fetch_options *opts, unsigned int version)
155
155
  return 0;
156
156
  }
157
157
 
158
+ #ifndef GIT_DEPRECATE_HARD
158
159
  int git_fetch_init_options(git_fetch_options *opts, unsigned int version)
159
160
  {
160
161
  return git_fetch_options_init(opts, version);
161
162
  }
163
+ #endif
@@ -941,7 +941,7 @@ out:
941
941
  return error;
942
942
  }
943
943
 
944
- void stream_list_free(git_vector *streams)
944
+ static void filter_streams_free(git_vector *streams)
945
945
  {
946
946
  git_writestream *stream;
947
947
  size_t i;
@@ -990,7 +990,7 @@ done:
990
990
 
991
991
  if (fd >= 0)
992
992
  p_close(fd);
993
- stream_list_free(&filter_streams);
993
+ filter_streams_free(&filter_streams);
994
994
  git_buf_dispose(&abspath);
995
995
  return error;
996
996
  }
@@ -1018,7 +1018,7 @@ out:
1018
1018
  if (initialized)
1019
1019
  error |= stream_start->close(stream_start);
1020
1020
 
1021
- stream_list_free(&filter_streams);
1021
+ filter_streams_free(&filter_streams);
1022
1022
  return error;
1023
1023
  }
1024
1024
 
@@ -834,12 +834,12 @@ int git_futils_rmdir_r(
834
834
  return error;
835
835
  }
836
836
 
837
- int git_futils_fake_symlink(const char *old, const char *new)
837
+ int git_futils_fake_symlink(const char *target, const char *path)
838
838
  {
839
839
  int retcode = GIT_ERROR;
840
- int fd = git_futils_creat_withpath(new, 0755, 0644);
840
+ int fd = git_futils_creat_withpath(path, 0755, 0644);
841
841
  if (fd >= 0) {
842
- retcode = p_write(fd, old, strlen(old));
842
+ retcode = p_write(fd, target, strlen(target));
843
843
  p_close(fd);
844
844
  }
845
845
  return retcode;
@@ -316,11 +316,11 @@ extern void git_futils_mmap_free(git_map *map);
316
316
  /**
317
317
  * Create a "fake" symlink (text file containing the target path).
318
318
  *
319
- * @param new symlink file to be created
320
- * @param old original symlink target
319
+ * @param target original symlink target
320
+ * @param path symlink file to be created
321
321
  * @return 0 on success, -1 on error
322
322
  */
323
- extern int git_futils_fake_symlink(const char *new, const char *old);
323
+ extern int git_futils_fake_symlink(const char *target, const char *path);
324
324
 
325
325
  /**
326
326
  * A file stamp represents a snapshot of information about a file that can
@@ -12,6 +12,7 @@
12
12
  #include "sysdir.h"
13
13
  #include "filter.h"
14
14
  #include "merge_driver.h"
15
+ #include "pool.h"
15
16
  #include "streams/registry.h"
16
17
  #include "streams/mbedtls.h"
17
18
  #include "streams/openssl.h"
@@ -38,7 +39,8 @@ static git_global_init_fn git__init_callbacks[] = {
38
39
  git_stream_registry_global_init,
39
40
  git_openssl_stream_global_init,
40
41
  git_mbedtls_stream_global_init,
41
- git_mwindow_global_init
42
+ git_mwindow_global_init,
43
+ git_pool_global_init
42
44
  };
43
45
 
44
46
  static git_global_shutdown_fn git__shutdown_callbacks[ARRAY_SIZE(git__init_callbacks)];
@@ -138,28 +138,6 @@ void *git_idxmap_icase_get(git_idxmap_icase *map, const git_index_entry *key)
138
138
  return kh_val(map, idx);
139
139
  }
140
140
 
141
- void git_idxmap_insert(git_idxmap *map, const git_index_entry *key, void *value, int *rval)
142
- {
143
- khiter_t idx = kh_put(idx, map, key, rval);
144
-
145
- if ((*rval) >= 0) {
146
- if ((*rval) == 0)
147
- kh_key(map, idx) = key;
148
- kh_val(map, idx) = value;
149
- }
150
- }
151
-
152
- void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key, void *value, int *rval)
153
- {
154
- khiter_t idx = kh_put(idxicase, map, key, rval);
155
-
156
- if ((*rval) >= 0) {
157
- if ((*rval) == 0)
158
- kh_key(map, idx) = key;
159
- kh_val(map, idx) = value;
160
- }
161
- }
162
-
163
141
  int git_idxmap_delete(git_idxmap *map, const git_index_entry *key)
164
142
  {
165
143
  khiter_t idx = kh_get(idx, map, key);
@@ -411,7 +411,8 @@ int git_index_open(git_index **index_out, const char *index_path)
411
411
  index = git__calloc(1, sizeof(git_index));
412
412
  GIT_ERROR_CHECK_ALLOC(index);
413
413
 
414
- git_pool_init(&index->tree_pool, 1);
414
+ if (git_pool_init(&index->tree_pool, 1) < 0)
415
+ goto fail;
415
416
 
416
417
  if (index_path != NULL) {
417
418
  index->index_file_path = git__strdup(index_path);
@@ -2780,17 +2781,19 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
2780
2781
  ondisk.flags = htons(entry->flags);
2781
2782
 
2782
2783
  if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
2784
+ const size_t path_offset = offsetof(struct entry_long, path);
2783
2785
  struct entry_long ondisk_ext;
2784
2786
  memcpy(&ondisk_ext, &ondisk, sizeof(struct entry_short));
2785
2787
  ondisk_ext.flags_extended = htons(entry->flags_extended &
2786
2788
  GIT_INDEX_ENTRY_EXTENDED_FLAGS);
2787
- memcpy(mem, &ondisk_ext, offsetof(struct entry_long, path));
2788
- path = ((struct entry_long*)mem)->path;
2789
- disk_size -= offsetof(struct entry_long, path);
2789
+ memcpy(mem, &ondisk_ext, path_offset);
2790
+ path = (char *)mem + path_offset;
2791
+ disk_size -= path_offset;
2790
2792
  } else {
2791
- memcpy(mem, &ondisk, offsetof(struct entry_short, path));
2792
- path = ((struct entry_short*)mem)->path;
2793
- disk_size -= offsetof(struct entry_short, path);
2793
+ const size_t path_offset = offsetof(struct entry_short, path);
2794
+ memcpy(mem, &ondisk, path_offset);
2795
+ path = (char *)mem + path_offset;
2796
+ disk_size -= path_offset;
2794
2797
  }
2795
2798
 
2796
2799
  if (last) {
@@ -3716,9 +3719,11 @@ void git_indexwriter_cleanup(git_indexwriter *writer)
3716
3719
 
3717
3720
  /* Deprecated functions */
3718
3721
 
3722
+ #ifndef GIT_DEPRECATE_HARD
3719
3723
  int git_index_add_frombuffer(
3720
3724
  git_index *index, const git_index_entry *source_entry,
3721
3725
  const void *buffer, size_t len)
3722
3726
  {
3723
3727
  return git_index_add_from_buffer(index, source_entry, buffer, len);
3724
3728
  }
3729
+ #endif
@@ -123,10 +123,12 @@ int git_indexer_options_init(git_indexer_options *opts, unsigned int version)
123
123
  return 0;
124
124
  }
125
125
 
126
+ #ifndef GIT_DEPRECATE_HARD
126
127
  int git_indexer_init_options(git_indexer_options *opts, unsigned int version)
127
128
  {
128
129
  return git_indexer_options_init(opts, version);
129
130
  }
131
+ #endif
130
132
 
131
133
  int git_indexer_new(
132
134
  git_indexer **out,
@@ -265,10 +267,11 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type)
265
267
  if (type == GIT_OBJECT_REF_DELTA) {
266
268
  idx->off += GIT_OID_RAWSZ;
267
269
  } else {
268
- off64_t base_off = get_delta_base(idx->pack, &w, &idx->off, type, idx->entry_start);
270
+ off64_t base_off;
271
+ int error = get_delta_base(&base_off, idx->pack, &w, &idx->off, type, idx->entry_start);
269
272
  git_mwindow_close(&w);
270
- if (base_off < 0)
271
- return (int)base_off;
273
+ if (error < 0)
274
+ return error;
272
275
  }
273
276
 
274
277
  return 0;
@@ -424,7 +427,10 @@ static int store_object(git_indexer *idx)
424
427
  pentry = git__calloc(1, sizeof(struct git_pack_entry));
425
428
  GIT_ERROR_CHECK_ALLOC(pentry);
426
429
 
427
- git_hash_final(&oid, &idx->hash_ctx);
430
+ if (git_hash_final(&oid, &idx->hash_ctx)) {
431
+ git__free(pentry);
432
+ goto on_error;
433
+ }
428
434
  entry_size = idx->off - entry_start;
429
435
  if (entry_start > UINT31_MAX) {
430
436
  entry->offset = UINT32_MAX;
@@ -897,9 +897,8 @@ static int tree_iterator_init(tree_iterator *iter)
897
897
  {
898
898
  int error;
899
899
 
900
- git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry));
901
-
902
- if ((error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
900
+ if ((error = git_pool_init(&iter->entry_pool, sizeof(tree_iterator_entry))) < 0 ||
901
+ (error = tree_iterator_frame_init(iter, iter->root, NULL)) < 0)
903
902
  return error;
904
903
 
905
904
  iter->base.flags &= ~GIT_ITERATOR_FIRST_ACCESS;
@@ -1376,7 +1375,8 @@ static int filesystem_iterator_frame_push(
1376
1375
  filesystem_iterator_entry_cmp)) < 0)
1377
1376
  goto done;
1378
1377
 
1379
- git_pool_init(&new_frame->entry_pool, 1);
1378
+ if ((error = git_pool_init(&new_frame->entry_pool, 1)) < 0)
1379
+ goto done;
1380
1380
 
1381
1381
  /* check if this directory is ignored */
1382
1382
  filesystem_iterator_frame_push_ignores(iter, frame_entry, new_frame);
@@ -80,7 +80,7 @@ static int cache_invalid_marker;
80
80
 
81
81
  /* Merge base computation */
82
82
 
83
- int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_repository *repo, size_t length, const git_oid input_array[])
83
+ static int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_repository *repo, size_t length, const git_oid input_array[])
84
84
  {
85
85
  git_revwalk *walk = NULL;
86
86
  git_vector list;
@@ -1810,12 +1810,12 @@ git_merge_diff_list *git_merge_diff_list__alloc(git_repository *repo)
1810
1810
 
1811
1811
  diff_list->repo = repo;
1812
1812
 
1813
- git_pool_init(&diff_list->pool, 1);
1814
1813
 
1815
- if (git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
1816
- git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
1817
- git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
1818
- git_merge_diff_list__free(diff_list);
1814
+ if (git_pool_init(&diff_list->pool, 1) < 0 ||
1815
+ git_vector_init(&diff_list->staged, 0, NULL) < 0 ||
1816
+ git_vector_init(&diff_list->conflicts, 0, NULL) < 0 ||
1817
+ git_vector_init(&diff_list->resolved, 0, NULL) < 0) {
1818
+ git_merge_diff_list__free(diff_list);
1819
1819
  return NULL;
1820
1820
  }
1821
1821
 
@@ -2845,7 +2845,7 @@ on_error:
2845
2845
  return error;
2846
2846
  }
2847
2847
 
2848
- const char *merge_their_label(const char *branchname)
2848
+ static const char *merge_their_label(const char *branchname)
2849
2849
  {
2850
2850
  const char *slash;
2851
2851
 
@@ -3351,10 +3351,12 @@ int git_merge_options_init(git_merge_options *opts, unsigned int version)
3351
3351
  return 0;
3352
3352
  }
3353
3353
 
3354
+ #ifndef GIT_DEPRECATE_HARD
3354
3355
  int git_merge_init_options(git_merge_options *opts, unsigned int version)
3355
3356
  {
3356
3357
  return git_merge_options_init(opts, version);
3357
3358
  }
3359
+ #endif
3358
3360
 
3359
3361
  int git_merge_file_input_init(git_merge_file_input *input, unsigned int version)
3360
3362
  {
@@ -3363,10 +3365,12 @@ int git_merge_file_input_init(git_merge_file_input *input, unsigned int version)
3363
3365
  return 0;
3364
3366
  }
3365
3367
 
3368
+ #ifndef GIT_DEPRECATE_HARD
3366
3369
  int git_merge_file_init_input(git_merge_file_input *input, unsigned int version)
3367
3370
  {
3368
3371
  return git_merge_file_input_init(input, version);
3369
3372
  }
3373
+ #endif
3370
3374
 
3371
3375
  int git_merge_file_options_init(
3372
3376
  git_merge_file_options *opts, unsigned int version)
@@ -3376,8 +3380,10 @@ int git_merge_file_options_init(
3376
3380
  return 0;
3377
3381
  }
3378
3382
 
3383
+ #ifndef GIT_DEPRECATE_HARD
3379
3384
  int git_merge_file_init_options(
3380
3385
  git_merge_file_options *opts, unsigned int version)
3381
3386
  {
3382
3387
  return git_merge_file_options_init(opts, version);
3383
3388
  }
3389
+ #endif
@@ -28,7 +28,7 @@
28
28
 
29
29
  #define GIT_MERGE_FILE_SIDE_EXISTS(X) ((X)->mode != 0)
30
30
 
31
- int git_merge_file__input_from_index(
31
+ static int merge_file_input_from_index(
32
32
  git_merge_file_input *input_out,
33
33
  git_odb_object **odb_object_out,
34
34
  git_odb *odb,
@@ -276,17 +276,15 @@ int git_merge_file_from_index(
276
276
  goto done;
277
277
 
278
278
  if (ancestor) {
279
- if ((error = git_merge_file__input_from_index(
279
+ if ((error = merge_file_input_from_index(
280
280
  &ancestor_input, &odb_object[0], odb, ancestor)) < 0)
281
281
  goto done;
282
282
 
283
283
  ancestor_ptr = &ancestor_input;
284
284
  }
285
285
 
286
- if ((error = git_merge_file__input_from_index(
287
- &our_input, &odb_object[1], odb, ours)) < 0 ||
288
- (error = git_merge_file__input_from_index(
289
- &their_input, &odb_object[2], odb, theirs)) < 0)
286
+ if ((error = merge_file_input_from_index(&our_input, &odb_object[1], odb, ours)) < 0 ||
287
+ (error = merge_file_input_from_index(&their_input, &odb_object[2], odb, theirs)) < 0)
290
288
  goto done;
291
289
 
292
290
  error = merge_file__from_inputs(out,
@@ -0,0 +1,418 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "midx.h"
9
+
10
+ #include "buffer.h"
11
+ #include "futils.h"
12
+ #include "hash.h"
13
+ #include "odb.h"
14
+ #include "pack.h"
15
+
16
+ #define GIT_MIDX_FILE_MODE 0444
17
+
18
+ #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
19
+ #define MIDX_VERSION 1
20
+ #define MIDX_OBJECT_ID_VERSION 1
21
+ struct git_midx_header {
22
+ uint32_t signature;
23
+ uint8_t version;
24
+ uint8_t object_id_version;
25
+ uint8_t chunks;
26
+ uint8_t base_midx_files;
27
+ uint32_t packfiles;
28
+ };
29
+
30
+ #define MIDX_PACKFILE_NAMES_ID 0x504e414d /* "PNAM" */
31
+ #define MIDX_OID_FANOUT_ID 0x4f494446 /* "OIDF" */
32
+ #define MIDX_OID_LOOKUP_ID 0x4f49444c /* "OIDL" */
33
+ #define MIDX_OBJECT_OFFSETS_ID 0x4f4f4646 /* "OOFF" */
34
+ #define MIDX_OBJECT_LARGE_OFFSETS_ID 0x4c4f4646 /* "LOFF" */
35
+
36
+ struct git_midx_chunk {
37
+ off64_t offset;
38
+ size_t length;
39
+ };
40
+
41
+ static int midx_error(const char *message)
42
+ {
43
+ git_error_set(GIT_ERROR_ODB, "invalid multi-pack-index file - %s", message);
44
+ return -1;
45
+ }
46
+
47
+ static int midx_parse_packfile_names(
48
+ git_midx_file *idx,
49
+ const unsigned char *data,
50
+ uint32_t packfiles,
51
+ struct git_midx_chunk *chunk)
52
+ {
53
+ int error;
54
+ uint32_t i;
55
+ char *packfile_name = (char *)(data + chunk->offset);
56
+ size_t chunk_size = chunk->length, len;
57
+ if (chunk->offset == 0)
58
+ return midx_error("missing Packfile Names chunk");
59
+ if (chunk->length == 0)
60
+ return midx_error("empty Packfile Names chunk");
61
+ if ((error = git_vector_init(&idx->packfile_names, packfiles, git__strcmp_cb)) < 0)
62
+ return error;
63
+ for (i = 0; i < packfiles; ++i) {
64
+ len = p_strnlen(packfile_name, chunk_size);
65
+ if (len == 0)
66
+ return midx_error("empty packfile name");
67
+ if (len + 1 > chunk_size)
68
+ return midx_error("unterminated packfile name");
69
+ git_vector_insert(&idx->packfile_names, packfile_name);
70
+ if (i && strcmp(git_vector_get(&idx->packfile_names, i - 1), packfile_name) >= 0)
71
+ return midx_error("packfile names are not sorted");
72
+ if (strlen(packfile_name) <= strlen(".idx") || git__suffixcmp(packfile_name, ".idx") != 0)
73
+ return midx_error("non-.idx packfile name");
74
+ if (strchr(packfile_name, '/') != NULL || strchr(packfile_name, '\\') != NULL)
75
+ return midx_error("non-local packfile");
76
+ packfile_name += len + 1;
77
+ chunk_size -= len + 1;
78
+ }
79
+ return 0;
80
+ }
81
+
82
+ static int midx_parse_oid_fanout(
83
+ git_midx_file *idx,
84
+ const unsigned char *data,
85
+ struct git_midx_chunk *chunk_oid_fanout)
86
+ {
87
+ uint32_t i, nr;
88
+ if (chunk_oid_fanout->offset == 0)
89
+ return midx_error("missing OID Fanout chunk");
90
+ if (chunk_oid_fanout->length == 0)
91
+ return midx_error("empty OID Fanout chunk");
92
+ if (chunk_oid_fanout->length != 256 * 4)
93
+ return midx_error("OID Fanout chunk has wrong length");
94
+
95
+ idx->oid_fanout = (const uint32_t *)(data + chunk_oid_fanout->offset);
96
+ nr = 0;
97
+ for (i = 0; i < 256; ++i) {
98
+ uint32_t n = ntohl(idx->oid_fanout[i]);
99
+ if (n < nr)
100
+ return midx_error("index is non-monotonic");
101
+ nr = n;
102
+ }
103
+ idx->num_objects = nr;
104
+ return 0;
105
+ }
106
+
107
+ static int midx_parse_oid_lookup(
108
+ git_midx_file *idx,
109
+ const unsigned char *data,
110
+ struct git_midx_chunk *chunk_oid_lookup)
111
+ {
112
+ uint32_t i;
113
+ git_oid *oid, *prev_oid, zero_oid = {{0}};
114
+
115
+ if (chunk_oid_lookup->offset == 0)
116
+ return midx_error("missing OID Lookup chunk");
117
+ if (chunk_oid_lookup->length == 0)
118
+ return midx_error("empty OID Lookup chunk");
119
+ if (chunk_oid_lookup->length != idx->num_objects * 20)
120
+ return midx_error("OID Lookup chunk has wrong length");
121
+
122
+ idx->oid_lookup = oid = (git_oid *)(data + chunk_oid_lookup->offset);
123
+ prev_oid = &zero_oid;
124
+ for (i = 0; i < idx->num_objects; ++i, ++oid) {
125
+ if (git_oid_cmp(prev_oid, oid) >= 0)
126
+ return midx_error("OID Lookup index is non-monotonic");
127
+ prev_oid = oid;
128
+ }
129
+
130
+ return 0;
131
+ }
132
+
133
+ static int midx_parse_object_offsets(
134
+ git_midx_file *idx,
135
+ const unsigned char *data,
136
+ struct git_midx_chunk *chunk_object_offsets)
137
+ {
138
+ if (chunk_object_offsets->offset == 0)
139
+ return midx_error("missing Object Offsets chunk");
140
+ if (chunk_object_offsets->length == 0)
141
+ return midx_error("empty Object Offsets chunk");
142
+ if (chunk_object_offsets->length != idx->num_objects * 8)
143
+ return midx_error("Object Offsets chunk has wrong length");
144
+
145
+ idx->object_offsets = data + chunk_object_offsets->offset;
146
+
147
+ return 0;
148
+ }
149
+
150
+ static int midx_parse_object_large_offsets(
151
+ git_midx_file *idx,
152
+ const unsigned char *data,
153
+ struct git_midx_chunk *chunk_object_large_offsets)
154
+ {
155
+ if (chunk_object_large_offsets->length == 0)
156
+ return 0;
157
+ if (chunk_object_large_offsets->length % 8 != 0)
158
+ return midx_error("malformed Object Large Offsets chunk");
159
+
160
+ idx->object_large_offsets = data + chunk_object_large_offsets->offset;
161
+ idx->num_object_large_offsets = chunk_object_large_offsets->length / 8;
162
+
163
+ return 0;
164
+ }
165
+
166
+ int git_midx_parse(
167
+ git_midx_file *idx,
168
+ const unsigned char *data,
169
+ size_t size)
170
+ {
171
+ struct git_midx_header *hdr;
172
+ const unsigned char *chunk_hdr;
173
+ struct git_midx_chunk *last_chunk;
174
+ uint32_t i;
175
+ off64_t last_chunk_offset, chunk_offset, trailer_offset;
176
+ git_oid idx_checksum = {{0}};
177
+ int error;
178
+ struct git_midx_chunk chunk_packfile_names = {0},
179
+ chunk_oid_fanout = {0},
180
+ chunk_oid_lookup = {0},
181
+ chunk_object_offsets = {0},
182
+ chunk_object_large_offsets = {0};
183
+
184
+ assert(idx);
185
+
186
+ if (size < sizeof(struct git_midx_header) + 20)
187
+ return midx_error("multi-pack index is too short");
188
+
189
+ hdr = ((struct git_midx_header *)data);
190
+
191
+ if (hdr->signature != htonl(MIDX_SIGNATURE) ||
192
+ hdr->version != MIDX_VERSION ||
193
+ hdr->object_id_version != MIDX_OBJECT_ID_VERSION) {
194
+ return midx_error("unsupported multi-pack index version");
195
+ }
196
+ if (hdr->chunks == 0)
197
+ return midx_error("no chunks in multi-pack index");
198
+
199
+ /*
200
+ * The very first chunk's offset should be after the header, all the chunk
201
+ * headers, and a special zero chunk.
202
+ */
203
+ last_chunk_offset =
204
+ sizeof(struct git_midx_header) +
205
+ (1 + hdr->chunks) * 12;
206
+ trailer_offset = size - 20;
207
+ if (trailer_offset < last_chunk_offset)
208
+ return midx_error("wrong index size");
209
+ git_oid_cpy(&idx->checksum, (git_oid *)(data + trailer_offset));
210
+
211
+ if (git_hash_buf(&idx_checksum, data, (size_t)trailer_offset) < 0)
212
+ return midx_error("could not calculate signature");
213
+ if (!git_oid_equal(&idx_checksum, &idx->checksum))
214
+ return midx_error("index signature mismatch");
215
+
216
+ chunk_hdr = data + sizeof(struct git_midx_header);
217
+ last_chunk = NULL;
218
+ for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) {
219
+ chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 |
220
+ ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
221
+ if (chunk_offset < last_chunk_offset)
222
+ return midx_error("chunks are non-monotonic");
223
+ if (chunk_offset >= trailer_offset)
224
+ return midx_error("chunks extend beyond the trailer");
225
+ if (last_chunk != NULL)
226
+ last_chunk->length = (size_t)(chunk_offset - last_chunk_offset);
227
+ last_chunk_offset = chunk_offset;
228
+
229
+ switch (ntohl(*((uint32_t *)(chunk_hdr + 0)))) {
230
+ case MIDX_PACKFILE_NAMES_ID:
231
+ chunk_packfile_names.offset = last_chunk_offset;
232
+ last_chunk = &chunk_packfile_names;
233
+ break;
234
+
235
+ case MIDX_OID_FANOUT_ID:
236
+ chunk_oid_fanout.offset = last_chunk_offset;
237
+ last_chunk = &chunk_oid_fanout;
238
+ break;
239
+
240
+ case MIDX_OID_LOOKUP_ID:
241
+ chunk_oid_lookup.offset = last_chunk_offset;
242
+ last_chunk = &chunk_oid_lookup;
243
+ break;
244
+
245
+ case MIDX_OBJECT_OFFSETS_ID:
246
+ chunk_object_offsets.offset = last_chunk_offset;
247
+ last_chunk = &chunk_object_offsets;
248
+ break;
249
+
250
+ case MIDX_OBJECT_LARGE_OFFSETS_ID:
251
+ chunk_object_large_offsets.offset = last_chunk_offset;
252
+ last_chunk = &chunk_object_large_offsets;
253
+ break;
254
+
255
+ default:
256
+ return midx_error("unrecognized chunk ID");
257
+ }
258
+ }
259
+ last_chunk->length = (size_t)(trailer_offset - last_chunk_offset);
260
+
261
+ error = midx_parse_packfile_names(
262
+ idx, data, ntohl(hdr->packfiles), &chunk_packfile_names);
263
+ if (error < 0)
264
+ return error;
265
+ error = midx_parse_oid_fanout(idx, data, &chunk_oid_fanout);
266
+ if (error < 0)
267
+ return error;
268
+ error = midx_parse_oid_lookup(idx, data, &chunk_oid_lookup);
269
+ if (error < 0)
270
+ return error;
271
+ error = midx_parse_object_offsets(idx, data, &chunk_object_offsets);
272
+ if (error < 0)
273
+ return error;
274
+ error = midx_parse_object_large_offsets(idx, data, &chunk_object_large_offsets);
275
+ if (error < 0)
276
+ return error;
277
+
278
+ return 0;
279
+ }
280
+
281
+ int git_midx_open(
282
+ git_midx_file **idx_out,
283
+ const char *path)
284
+ {
285
+ git_midx_file *idx;
286
+ git_file fd = -1;
287
+ size_t idx_size;
288
+ struct stat st;
289
+ int error;
290
+
291
+ /* TODO: properly open the file without access time using O_NOATIME */
292
+ fd = git_futils_open_ro(path);
293
+ if (fd < 0)
294
+ return fd;
295
+
296
+ if (p_fstat(fd, &st) < 0) {
297
+ p_close(fd);
298
+ git_error_set(GIT_ERROR_ODB, "multi-pack-index file not found - '%s'", path);
299
+ return -1;
300
+ }
301
+
302
+ if (!S_ISREG(st.st_mode) || !git__is_sizet(st.st_size)) {
303
+ p_close(fd);
304
+ git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path);
305
+ return -1;
306
+ }
307
+ idx_size = (size_t)st.st_size;
308
+
309
+ idx = git__calloc(1, sizeof(git_midx_file));
310
+ GIT_ERROR_CHECK_ALLOC(idx);
311
+
312
+ error = git_futils_mmap_ro(&idx->index_map, fd, 0, idx_size);
313
+ p_close(fd);
314
+ if (error < 0) {
315
+ git_midx_free(idx);
316
+ return error;
317
+ }
318
+
319
+ if ((error = git_midx_parse(idx, idx->index_map.data, idx_size)) < 0) {
320
+ git_midx_free(idx);
321
+ return error;
322
+ }
323
+
324
+ *idx_out = idx;
325
+ return 0;
326
+ }
327
+
328
+ int git_midx_entry_find(
329
+ git_midx_entry *e,
330
+ git_midx_file *idx,
331
+ const git_oid *short_oid,
332
+ size_t len)
333
+ {
334
+ int pos, found = 0;
335
+ size_t pack_index;
336
+ uint32_t hi, lo;
337
+ const git_oid *current = NULL;
338
+ const unsigned char *object_offset;
339
+ off64_t offset;
340
+
341
+ assert(idx);
342
+
343
+ hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]);
344
+ lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1]));
345
+
346
+ pos = git_pack__lookup_sha1(idx->oid_lookup, 20, lo, hi, short_oid->id);
347
+
348
+ if (pos >= 0) {
349
+ /* An object matching exactly the oid was found */
350
+ found = 1;
351
+ current = idx->oid_lookup + pos;
352
+ } else {
353
+ /* No object was found */
354
+ /* pos refers to the object with the "closest" oid to short_oid */
355
+ pos = -1 - pos;
356
+ if (pos < (int)idx->num_objects) {
357
+ current = idx->oid_lookup + pos;
358
+
359
+ if (!git_oid_ncmp(short_oid, current, len))
360
+ found = 1;
361
+ }
362
+ }
363
+
364
+ if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)idx->num_objects) {
365
+ /* Check for ambiguousity */
366
+ const git_oid *next = current + 1;
367
+
368
+ if (!git_oid_ncmp(short_oid, next, len)) {
369
+ found = 2;
370
+ }
371
+ }
372
+
373
+ if (!found)
374
+ return git_odb__error_notfound("failed to find offset for multi-pack index entry", short_oid, len);
375
+ if (found > 1)
376
+ return git_odb__error_ambiguous("found multiple offsets for multi-pack index entry");
377
+
378
+ object_offset = idx->object_offsets + pos * 8;
379
+ offset = ntohl(*((uint32_t *)(object_offset + 4)));
380
+ if (offset & 0x80000000) {
381
+ uint32_t object_large_offsets_pos = offset & 0x7fffffff;
382
+ const unsigned char *object_large_offsets_index = idx->object_large_offsets;
383
+
384
+ /* Make sure we're not being sent out of bounds */
385
+ if (object_large_offsets_pos >= idx->num_object_large_offsets)
386
+ return git_odb__error_notfound("invalid index into the object large offsets table", short_oid, len);
387
+
388
+ object_large_offsets_index += 8 * object_large_offsets_pos;
389
+
390
+ offset = (((uint64_t)ntohl(*((uint32_t *)(object_large_offsets_index + 0)))) << 32) |
391
+ ntohl(*((uint32_t *)(object_large_offsets_index + 4)));
392
+ }
393
+ pack_index = ntohl(*((uint32_t *)(object_offset + 0)));
394
+ if (pack_index >= git_vector_length(&idx->packfile_names))
395
+ return midx_error("invalid index into the packfile names table");
396
+ e->pack_index = pack_index;
397
+ e->offset = offset;
398
+ git_oid_cpy(&e->sha1, current);
399
+ return 0;
400
+ }
401
+
402
+ void git_midx_close(git_midx_file *idx)
403
+ {
404
+ assert(idx);
405
+
406
+ if (idx->index_map.data)
407
+ git_futils_mmap_free(&idx->index_map);
408
+ git_vector_free(&idx->packfile_names);
409
+ }
410
+
411
+ void git_midx_free(git_midx_file *idx)
412
+ {
413
+ if (!idx)
414
+ return;
415
+
416
+ git_midx_close(idx);
417
+ git__free(idx);
418
+ }