summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-05 10:39:01 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-05 10:39:01 +0100
commit751887211b9f9fde4eff15018d2b524da55274d2 (patch)
treec59f9815cd971168a9bc2c90ef9a2066ebdd8d43
parentf7fd9ce947fc2189ce80abc31fdc6077df94f73b (diff)
downloadlibgit2-ethomson/sha256_index.tar.gz
index: add sha256 supportethomson/sha256_index
-rw-r--r--include/git2/index.h9
-rw-r--r--src/libgit2/apply.c7
-rw-r--r--src/libgit2/index.c433
-rw-r--r--src/libgit2/index.h15
-rw-r--r--src/libgit2/merge.c15
-rw-r--r--src/libgit2/repository.c3
-rw-r--r--src/libgit2/stash.c17
-rw-r--r--src/libgit2/tree-cache.c42
-rw-r--r--src/libgit2/tree-cache.h8
-rw-r--r--src/libgit2/tree.c2
-rw-r--r--tests/libgit2/checkout/index.c3
-rw-r--r--tests/libgit2/clone/nonetwork.c3
-rw-r--r--tests/libgit2/diff/index.c3
-rw-r--r--tests/libgit2/index/cache.c10
-rw-r--r--tests/libgit2/index/inmemory.c5
-rw-r--r--tests/libgit2/index/racy.c4
-rw-r--r--tests/libgit2/index/read_index.c12
-rw-r--r--tests/libgit2/index/tests.c30
-rw-r--r--tests/libgit2/index/tests256.c1109
-rw-r--r--tests/libgit2/object/tree/update.c13
-rw-r--r--tests/libgit2/repo/setters.c3
-rw-r--r--tests/libgit2/reset/hard.c3
-rw-r--r--tests/libgit2/status/worktree_init.c13
-rw-r--r--tests/libgit2/submodule/lookup.c3
-rw-r--r--tests/resources/git-sha256.indexbin0 -> 458900 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/HEAD1
-rw-r--r--tests/resources/testrepo_256/.gitted/config15
-rw-r--r--tests/resources/testrepo_256/.gitted/description1
-rw-r--r--tests/resources/testrepo_256/.gitted/indexbin0 -> 361 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/info/exclude6
-rw-r--r--tests/resources/testrepo_256/.gitted/logs/HEAD1
-rw-r--r--tests/resources/testrepo_256/.gitted/logs/refs/heads/master1
-rw-r--r--tests/resources/testrepo_256/.gitted/logs/refs/remotes/origin/HEAD1
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045bin0 -> 267 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f781
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065bbin0 -> 103 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750bin0 -> 21 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f1
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498bin0 -> 64 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09ebin0 -> 92 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24bin0 -> 236 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61bin0 -> 162 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950abin0 -> 143 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352abin0 -> 202 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2bin0 -> 238 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8bin0 -> 19 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b1
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60bin0 -> 21 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869bin0 -> 106 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1bin0 -> 38 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b1
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813bin0 -> 15 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5bin0 -> 28 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fdbin0 -> 57 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9bbin0 -> 64 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d268481
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f3
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446ebin0 -> 157 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3bin0 -> 24 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7bin0 -> 107 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411edbin0 -> 181 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6bin0 -> 108 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6fbin0 -> 141 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c2
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa471
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bfbin0 -> 108 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e1007241
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbebin0 -> 137 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5bin0 -> 188 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045bin0 -> 18 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54bin0 -> 221 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b1
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95bin0 -> 244 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640bin0 -> 63 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5bin0 -> 26 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebdbin0 -> 54 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d718271
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890bin0 -> 37 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022bin0 -> 190 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23bin0 -> 23 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19bin0 -> 57 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5bin0 -> 198 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef62
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269bin0 -> 182 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0bin0 -> 187 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9fbin0 -> 21 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c03
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca1
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4fbin0 -> 181 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1bin0 -> 21 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736bin0 -> 157 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978bin0 -> 192 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562bin0 -> 157 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idxbin0 -> 1336 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.packbin0 -> 569 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idxbin0 -> 66216 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.packbin0 -> 562646 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idxbin0 -> 1336 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.packbin0 -> 612 bytes
-rw-r--r--tests/resources/testrepo_256/.gitted/packed-refs27
-rw-r--r--tests/resources/testrepo_256/.gitted/refs/heads/master1
-rw-r--r--tests/resources/testrepo_256/.gitted/refs/remotes/origin/HEAD1
-rw-r--r--tests/resources/testrepo_256/README1
-rw-r--r--tests/resources/testrepo_256/branch_file.txt2
-rw-r--r--tests/resources/testrepo_256/new.txt1
105 files changed, 1640 insertions, 204 deletions
diff --git a/include/git2/index.h b/include/git2/index.h
index 981535dad..6e806371b 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -184,7 +184,12 @@ typedef enum {
* @param index_path the path to the index file in disk
* @return 0 or an error code
*/
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path, git_oid_t oid_type);
+#else
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
+#endif
/**
* Create an in-memory index object.
@@ -197,7 +202,11 @@ GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
* @param out the pointer for the new index
* @return 0 or an error code
*/
+#ifdef GIT_EXPERIMENTAL_SHA256
+GIT_EXTERN(int) git_index_new(git_index **out, git_oid_t oid_type);
+#else
GIT_EXTERN(int) git_index_new(git_index **out);
+#endif
/**
* Free an existing index object.
diff --git a/src/libgit2/apply.c b/src/libgit2/apply.c
index 18304da4d..6b55b812f 100644
--- a/src/libgit2/apply.c
+++ b/src/libgit2/apply.c
@@ -19,6 +19,7 @@
#include "zstream.h"
#include "reader.h"
#include "index.h"
+#include "repository.h"
#include "apply.h"
typedef struct {
@@ -644,7 +645,7 @@ int git_apply_to_tree(
* put the current tree into the postimage as-is - the diff will
* replace any entries contained therein
*/
- if ((error = git_index_new(&postimage)) < 0 ||
+ if ((error = git_index__new(&postimage, repo->oid_type)) < 0 ||
(error = git_index_read_tree(postimage, preimage)) < 0 ||
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
goto done;
@@ -851,8 +852,8 @@ int git_apply(
* having the full repo index, so we will limit our checkout
* to only write these files that were affected by the diff.
*/
- if ((error = git_index_new(&preimage)) < 0 ||
- (error = git_index_new(&postimage)) < 0 ||
+ if ((error = git_index__new(&preimage, repo->oid_type)) < 0 ||
+ (error = git_index__new(&postimage, repo->oid_type)) < 0 ||
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
goto done;
diff --git a/src/libgit2/index.c b/src/libgit2/index.c
index 6777f0358..9d919093b 100644
--- a/src/libgit2/index.c
+++ b/src/libgit2/index.c
@@ -32,8 +32,6 @@ static int index_apply_to_wd_diff(git_index *index, int action, const git_strarr
unsigned int flags,
git_index_matched_path_cb cb, void *payload);
-#define minimal_entry_size (offsetof(struct entry_short, path))
-
static const size_t INDEX_HEADER_SIZE = 12;
static const unsigned int INDEX_VERSION_NUMBER_DEFAULT = 2;
@@ -65,7 +63,7 @@ struct entry_time {
uint32_t nanoseconds;
};
-struct entry_short {
+struct entry_common {
struct entry_time ctime;
struct entry_time mtime;
uint32_t dev;
@@ -74,25 +72,35 @@ struct entry_short {
uint32_t uid;
uint32_t gid;
uint32_t file_size;
- unsigned char oid[GIT_OID_SHA1_SIZE];
- uint16_t flags;
- char path[1]; /* arbitrary length */
};
-struct entry_long {
- struct entry_time ctime;
- struct entry_time mtime;
- uint32_t dev;
- uint32_t ino;
- uint32_t mode;
- uint32_t uid;
- uint32_t gid;
- uint32_t file_size;
- unsigned char oid[GIT_OID_SHA1_SIZE];
- uint16_t flags;
- uint16_t flags_extended;
- char path[1]; /* arbitrary length */
-};
+#define entry_short(oid_size) \
+ struct { \
+ struct entry_common common; \
+ unsigned char oid[oid_size]; \
+ uint16_t flags; \
+ char path[1]; /* arbitrary length */ \
+ }
+
+#define entry_long(oid_size) \
+ struct { \
+ struct entry_common common; \
+ unsigned char oid[oid_size]; \
+ uint16_t flags; \
+ uint16_t flags_extended; \
+ char path[1]; /* arbitrary length */ \
+ }
+
+typedef entry_short(GIT_OID_SHA1_SIZE) index_entry_short_sha1;
+typedef entry_long(GIT_OID_SHA1_SIZE) index_entry_long_sha1;
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+typedef entry_short(GIT_OID_SHA256_SIZE) index_entry_short_sha256;
+typedef entry_long(GIT_OID_SHA256_SIZE) index_entry_long_sha256;
+#endif
+
+#undef entry_short
+#undef entry_long
struct entry_srch_key {
const char *path;
@@ -115,12 +123,12 @@ struct reuc_entry_internal {
bool git_index__enforce_unsaved_safety = false;
/* local declarations */
-static int read_extension(size_t *read_len, git_index *index, const char *buffer, size_t buffer_size);
+static int read_extension(size_t *read_len, git_index *index, size_t checksum_size, const char *buffer, size_t buffer_size);
static int read_header(struct index_header *dest, const void *buffer);
static int parse_index(git_index *index, const char *buffer, size_t buffer_size);
static bool is_index_extended(git_index *index);
-static int write_index(unsigned char checksum[GIT_HASH_SHA1_SIZE], size_t *checksum_size, git_index *index, git_filebuf *file);
+static int write_index(unsigned char checksum[GIT_HASH_MAX_SIZE], size_t *checksum_size, git_index *index, git_filebuf *file);
static void index_entry_free(git_index_entry *entry);
static void index_entry_reuc_free(git_index_reuc_entry *reuc);
@@ -401,7 +409,10 @@ void git_index__set_ignore_case(git_index *index, bool ignore_case)
git_vector_sort(&index->reuc);
}
-int git_index_open(git_index **index_out, const char *index_path)
+int git_index__open(
+ git_index **index_out,
+ const char *index_path,
+ git_oid_t oid_type)
{
git_index *index;
int error = -1;
@@ -411,6 +422,8 @@ int git_index_open(git_index **index_out, const char *index_path)
index = git__calloc(1, sizeof(git_index));
GIT_ERROR_CHECK_ALLOC(index);
+ index->oid_type = oid_type;
+
if (git_pool_init(&index->tree_pool, 1) < 0)
goto fail;
@@ -451,10 +464,34 @@ fail:
return error;
}
+#ifdef GIT_EXPERIMENTAL_SHA256
+int git_index_open(git_index **index_out, const char *index_path, git_oid_t oid_type)
+{
+ return git_index__open(index_out, index_path, oid_type);
+}
+#else
+int git_index_open(git_index **index_out, const char *index_path)
+{
+ return git_index__open(index_out, index_path, GIT_OID_SHA1);
+}
+#endif
+
+int git_index__new(git_index **out, git_oid_t oid_type)
+{
+ return git_index__open(out, NULL, oid_type);
+}
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+int git_index_new(git_index **out, git_oid_t oid_type)
+{
+ return git_index__new(out, oid_type);
+}
+#else
int git_index_new(git_index **out)
{
- return git_index_open(out, NULL);
+ return git_index__new(out, GIT_OID_SHA1);
}
+#endif
static void index_free(git_index *index)
{
@@ -620,8 +657,8 @@ static int compare_checksum(git_index *index)
{
int fd;
ssize_t bytes_read;
- unsigned char checksum[GIT_HASH_SHA1_SIZE];
- size_t checksum_size = GIT_HASH_SHA1_SIZE;
+ unsigned char checksum[GIT_HASH_MAX_SIZE];
+ size_t checksum_size = git_oid_size(index->oid_type);
if ((fd = p_open(index->index_file_path, O_RDONLY)) < 0)
return fd;
@@ -2306,6 +2343,7 @@ static int index_error_invalid(const char *message)
static int read_reuc(git_index *index, const char *buffer, size_t size)
{
const char *endptr;
+ size_t oid_size = git_oid_size(index->oid_type);
size_t len;
int i;
@@ -2354,16 +2392,16 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
for (i = 0; i < 3; i++) {
if (!lost->mode[i])
continue;
- if (size < GIT_OID_SHA1_SIZE) {
+ if (size < oid_size) {
index_entry_reuc_free(lost);
return index_error_invalid("reading reuc entry oid");
}
- if (git_oid__fromraw(&lost->oid[i], (const unsigned char *) buffer, GIT_OID_SHA1) < 0)
+ if (git_oid__fromraw(&lost->oid[i], (const unsigned char *) buffer, index->oid_type) < 0)
return -1;
- size -= GIT_OID_SHA1_SIZE;
- buffer += GIT_OID_SHA1_SIZE;
+ size -= oid_size;
+ buffer += oid_size;
}
/* entry was read successfully - insert into reuc vector */
@@ -2433,73 +2471,157 @@ out_err:
return 0;
}
-static size_t index_entry_size(size_t path_len, size_t varint_len, uint32_t flags)
+GIT_INLINE(size_t) index_entry_path_offset(
+ git_oid_t oid_type,
+ uint32_t flags)
{
+ if (oid_type == GIT_OID_SHA1)
+ return (flags & GIT_INDEX_ENTRY_EXTENDED) ?
+ offsetof(index_entry_long_sha1, path) :
+ offsetof(index_entry_short_sha1, path);
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ else if (oid_type == GIT_OID_SHA256)
+ return (flags & GIT_INDEX_ENTRY_EXTENDED) ?
+ offsetof(index_entry_long_sha256, path) :
+ offsetof(index_entry_short_sha256, path);
+#endif
+
+ git_error_set(GIT_ERROR_INTERNAL, "invalid oid type");
+ return 0;
+}
+
+GIT_INLINE(size_t) index_entry_flags_offset(git_oid_t oid_type)
+{
+ if (oid_type == GIT_OID_SHA1)
+ return offsetof(index_entry_long_sha1, flags_extended);
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ else if (oid_type == GIT_OID_SHA256)
+ return offsetof(index_entry_long_sha256, flags_extended);
+#endif
+
+ git_error_set(GIT_ERROR_INTERNAL, "invalid oid type");
+ return 0;
+}
+
+static size_t index_entry_size(
+ size_t path_len,
+ size_t varint_len,
+ git_oid_t oid_type,
+ uint32_t flags)
+{
+ size_t offset, size;
+
+ if (!(offset = index_entry_path_offset(oid_type, flags)))
+ return 0;
+
if (varint_len) {
- if (flags & GIT_INDEX_ENTRY_EXTENDED)
- return offsetof(struct entry_long, path) + path_len + 1 + varint_len;
- else
- return offsetof(struct entry_short, path) + path_len + 1 + varint_len;
+ if (GIT_ADD_SIZET_OVERFLOW(&size, offset, path_len) ||
+ GIT_ADD_SIZET_OVERFLOW(&size, size, 1) ||
+ GIT_ADD_SIZET_OVERFLOW(&size, size, varint_len))
+ return 0;
} else {
-#define entry_size(type,len) ((offsetof(type, path) + (len) + 8) & ~7)
- if (flags & GIT_INDEX_ENTRY_EXTENDED)
- return entry_size(struct entry_long, path_len);
- else
- return entry_size(struct entry_short, path_len);
-#undef entry_size
+ if (GIT_ADD_SIZET_OVERFLOW(&size, offset, path_len) ||
+ GIT_ADD_SIZET_OVERFLOW(&size, size, 8))
+ return 0;
+
+ size &= ~7;
}
+
+ return size;
}
static int read_entry(
git_index_entry **out,
size_t *out_size,
git_index *index,
+ size_t checksum_size,
const void *buffer,
size_t buffer_size,
const char *last)
{
- size_t path_length, entry_size;
+ size_t path_length, path_offset, entry_size;
const char *path_ptr;
- struct entry_short source;
+ struct entry_common *source_common;
+ index_entry_short_sha1 source_sha1;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ index_entry_short_sha256 source_sha256;
+#endif
git_index_entry entry = {{0}};
bool compressed = index->version >= INDEX_VERSION_NUMBER_COMP;
char *tmp_path = NULL;
- size_t checksum_size = GIT_HASH_SHA1_SIZE;
+
+ size_t minimal_entry_size = index_entry_path_offset(index->oid_type, 0);
if (checksum_size + minimal_entry_size > buffer_size)
return -1;
/* buffer is not guaranteed to be aligned */
- memcpy(&source, buffer, sizeof(struct entry_short));
-
- entry.ctime.seconds = (git_time_t)ntohl(source.ctime.seconds);
- entry.ctime.nanoseconds = ntohl(source.ctime.nanoseconds);
- entry.mtime.seconds = (git_time_t)ntohl(source.mtime.seconds);
- entry.mtime.nanoseconds = ntohl(source.mtime.nanoseconds);
- entry.dev = ntohl(source.dev);
- entry.ino = ntohl(source.ino);
- entry.mode = ntohl(source.mode);
- entry.uid = ntohl(source.uid);
- entry.gid = ntohl(source.gid);
- entry.file_size = ntohl(source.file_size);
- entry.flags = ntohs(source.flags);
-
- if (git_oid__fromraw(&entry.id, source.oid, GIT_OID_SHA1) < 0)
+ switch (index->oid_type) {
+ case GIT_OID_SHA1:
+ source_common = &source_sha1.common;
+ memcpy(&source_sha1, buffer, sizeof(source_sha1));
+ break;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ case GIT_OID_SHA256:
+ source_common = &source_sha256.common;
+ memcpy(&source_sha256, buffer, sizeof(source_sha256));
+ break;
+#endif
+ default:
+ GIT_ASSERT(!"invalid oid type");
+ }
+
+ entry.ctime.seconds = (git_time_t)ntohl(source_common->ctime.seconds);
+ entry.ctime.nanoseconds = ntohl(source_common->ctime.nanoseconds);
+ entry.mtime.seconds = (git_time_t)ntohl(source_common->mtime.seconds);
+ entry.mtime.nanoseconds = ntohl(source_common->mtime.nanoseconds);
+ entry.dev = ntohl(source_common->dev);
+ entry.ino = ntohl(source_common->ino);
+ entry.mode = ntohl(source_common->mode);
+ entry.uid = ntohl(source_common->uid);
+ entry.gid = ntohl(source_common->gid);
+ entry.file_size = ntohl(source_common->file_size);
+
+ switch (index->oid_type) {
+ case GIT_OID_SHA1:
+ if (git_oid__fromraw(&entry.id, source_sha1.oid,
+ GIT_OID_SHA1) < 0)
+ return -1;
+ entry.flags = ntohs(source_sha1.flags);
+ break;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ case GIT_OID_SHA256:
+ if (git_oid__fromraw(&entry.id, source_sha256.oid,
+ GIT_OID_SHA256) < 0)
+ return -1;
+ entry.flags = ntohs(source_sha256.flags);
+ break;
+#endif
+ default:
+ GIT_ASSERT(!"invalid oid type");
+ }
+
+ if (!(path_offset = index_entry_path_offset(index->oid_type, entry.flags)))
return -1;
+
if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) {
uint16_t flags_raw;
size_t flags_offset;
- flags_offset = offsetof(struct entry_long, flags_extended);
- memcpy(&flags_raw, (const char *) buffer + flags_offset,
- sizeof(flags_raw));
+ if (!(flags_offset = index_entry_flags_offset(index->oid_type)))
+ return -1;
+
+ memcpy(&flags_raw, (const char *)buffer + flags_offset, sizeof(flags_raw));
flags_raw = ntohs(flags_raw);
memcpy(&entry.flags_extended, &flags_raw, sizeof(flags_raw));
- path_ptr = (const char *) buffer + offsetof(struct entry_long, path);
- } else
- path_ptr = (const char *) buffer + offsetof(struct entry_short, path);
+ path_ptr = (const char *)buffer + path_offset;
+ } else {
+ path_ptr = (const char *)buffer + path_offset;
+ }
if (!compressed) {
path_length = entry.flags & GIT_INDEX_ENTRY_NAMEMASK;
@@ -2511,12 +2633,12 @@ static int read_entry(
path_end = memchr(path_ptr, '\0', buffer_size);
if (path_end == NULL)
- return -1;
+ return index_error_invalid("invalid path name");
path_length = path_end - path_ptr;
}
- entry_size = index_entry_size(path_length, 0, entry.flags);
+ entry_size = index_entry_size(path_length, 0, index->oid_type, entry.flags);
entry.path = (char *)path_ptr;
} else {
size_t varint_len, last_len, prefix_len, suffix_len, path_len;
@@ -2542,15 +2664,18 @@ static int read_entry(
memcpy(tmp_path, last, prefix_len);
memcpy(tmp_path + prefix_len, path_ptr + varint_len, suffix_len + 1);
- entry_size = index_entry_size(suffix_len, varint_len, entry.flags);
+
+ entry_size = index_entry_size(suffix_len, varint_len, index->oid_type, entry.flags);
entry.path = tmp_path;
}
if (entry_size == 0)
return -1;
- if (checksum_size + entry_size > buffer_size)
+ if (checksum_size + entry_size > buffer_size) {
+ git_error_set(GIT_ERROR_INTERNAL, "invalid index checksum");
return -1;
+ }
if (index_entry_dup(out, index, &entry) < 0) {
git__free(tmp_path);
@@ -2579,11 +2704,10 @@ static int read_header(struct index_header *dest, const void *buffer)
return 0;
}
-static int read_extension(size_t *read_len, git_index *index, const char *buffer, size_t buffer_size)
+static int read_extension(size_t *read_len, git_index *index, size_t checksum_size, const char *buffer, size_t buffer_size)
{
struct index_extension dest;
size_t total_size;
- size_t checksum_size = GIT_HASH_SHA1_SIZE;
/* buffer is not guaranteed to be aligned */
memcpy(&dest, buffer, sizeof(struct index_extension));
@@ -2602,7 +2726,7 @@ static int read_extension(size_t *read_len, git_index *index, const char *buffer
if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') {
/* tree cache */
if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) {
- if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size, &index->tree_pool) < 0)
+ if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size, index->oid_type, &index->tree_pool) < 0)
return -1;
} else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) {
if (read_reuc(index, buffer + 8, dest.extension_size) < 0)
@@ -2630,8 +2754,8 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
int error = 0;
unsigned int i;
struct index_header header = { 0 };
- unsigned char checksum[GIT_HASH_SHA1_SIZE];
- size_t checksum_size = GIT_HASH_SHA1_SIZE;
+ unsigned char checksum[GIT_HASH_MAX_SIZE];
+ size_t checksum_size = git_hash_size(git_oid_algorithm(index->oid_type));
const char *last = NULL;
const char *empty = "";
@@ -2646,9 +2770,12 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
if (buffer_size < INDEX_HEADER_SIZE + checksum_size)
return index_error_invalid("insufficient buffer space");
- /* Precalculate the SHA1 of the files's contents -- we'll match it to
- * the provided SHA1 in the footer */
- git_hash_buf(checksum, buffer, buffer_size - checksum_size, GIT_HASH_ALGORITHM_SHA1);
+ /*
+ * Precalculate the hash of the files's contents -- we'll match
+ * it to the provided checksum in the footer.
+ */
+ git_hash_buf(checksum, buffer, buffer_size - checksum_size,
+ git_oid_algorithm(index->oid_type));
/* Parse header */
if ((error = read_header(&header, buffer)) < 0)
@@ -2670,7 +2797,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
git_index_entry *entry = NULL;
size_t entry_size;
- if ((error = read_entry(&entry, &entry_size, index, buffer, buffer_size, last)) < 0) {
+ if ((error = read_entry(&entry, &entry_size, index, checksum_size, buffer, buffer_size, last)) < 0) {
error = index_error_invalid("invalid entry");
goto done;
}
@@ -2701,7 +2828,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
while (buffer_size > checksum_size) {
size_t extension_size;
- if ((error = read_extension(&extension_size, index, buffer, buffer_size)) < 0) {
+ if ((error = read_extension(&extension_size, index, checksum_size, buffer, buffer_size)) < 0) {
goto done;
}
@@ -2714,7 +2841,10 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
goto done;
}
- /* 160-bit SHA-1 over the content of the index file before this checksum. */
+ /*
+ * SHA-1 or SHA-256 (depending on the repository's object format)
+ * over the content of the index file before this checksum.
+ */
if (memcmp(checksum, buffer, checksum_size) != 0) {
error = index_error_invalid(
"calculated checksum does not match expected");
@@ -2754,16 +2884,40 @@ static bool is_index_extended(git_index *index)
return (extended > 0);
}
-static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const char *last)
+static int write_disk_entry(
+ git_index *index,
+ git_filebuf *file,
+ git_index_entry *entry,
+ const char *last)
{
void *mem = NULL;
- struct entry_short ondisk;
- size_t path_len, disk_size;
+ struct entry_common *ondisk_common;
+ size_t path_len, path_offset, disk_size;
int varint_len = 0;
char *path;
const char *path_start = entry->path;
size_t same_len = 0;
+ index_entry_short_sha1 ondisk_sha1;
+ index_entry_long_sha1 ondisk_ext_sha1;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ index_entry_short_sha256 ondisk_sha256;
+ index_entry_long_sha256 ondisk_ext_sha256;
+#endif
+
+ switch (index->oid_type) {
+ case GIT_OID_SHA1:
+ ondisk_common = &ondisk_sha1.common;
+ break;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ case GIT_OID_SHA256:
+ ondisk_common = &ondisk_sha256.common;
+ break;
+#endif
+ default:
+ GIT_ASSERT(!"invalid oid type");
+ }
+
path_len = ((struct entry_internal *)entry)->pathlen;
if (last) {
@@ -2780,9 +2934,9 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
varint_len = git_encode_varint(NULL, 0, strlen(last) - same_len);
}
- disk_size = index_entry_size(path_len, varint_len, entry->flags);
+ disk_size = index_entry_size(path_len, varint_len, index->oid_type, entry->flags);
- if (git_filebuf_reserve(file, &mem, disk_size) < 0)
+ if (!disk_size || git_filebuf_reserve(file, &mem, disk_size) < 0)
return -1;
memset(mem, 0x0, disk_size);
@@ -2797,35 +2951,77 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
*
* In 2038 I will be either too dead or too rich to care about this
*/
- ondisk.ctime.seconds = htonl((uint32_t)entry->ctime.seconds);
- ondisk.mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
- ondisk.ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
- ondisk.mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
- ondisk.dev = htonl(entry->dev);
- ondisk.ino = htonl(entry->ino);
- ondisk.mode = htonl(entry->mode);
- ondisk.uid = htonl(entry->uid);
- ondisk.gid = htonl(entry->gid);
- ondisk.file_size = htonl((uint32_t)entry->file_size);
- git_oid_raw_cpy(ondisk.oid, entry->id.id, GIT_OID_SHA1_SIZE);
- ondisk.flags = htons(entry->flags);
+ ondisk_common->ctime.seconds = htonl((uint32_t)entry->ctime.seconds);
+ ondisk_common->mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
+ ondisk_common->ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
+ ondisk_common->mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
+ ondisk_common->dev = htonl(entry->dev);
+ ondisk_common->ino = htonl(entry->ino);
+ ondisk_common->mode = htonl(entry->mode);
+ ondisk_common->uid = htonl(entry->uid);
+ ondisk_common->gid = htonl(entry->gid);
+ ondisk_common->file_size = htonl((uint32_t)entry->file_size);
+
+ switch (index->oid_type) {
+ case GIT_OID_SHA1:
+ git_oid_raw_cpy(ondisk_sha1.oid, entry->id.id, GIT_OID_SHA1_SIZE);
+ ondisk_sha1.flags = htons(entry->flags);
+ break;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ case GIT_OID_SHA256:
+ git_oid_raw_cpy(ondisk_sha256.oid, entry->id.id, GIT_OID_SHA256_SIZE);
+ ondisk_sha256.flags = htons(entry->flags);
+ break;
+#endif
+ default:
+ GIT_ASSERT(!"invalid oid type");
+ }
+
+ path_offset = index_entry_path_offset(index->oid_type, entry->flags);
if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) {
- const size_t path_offset = offsetof(struct entry_long, path);
- struct entry_long ondisk_ext;
- memcpy(&ondisk_ext, &ondisk, sizeof(struct entry_short));
- ondisk_ext.flags_extended = htons(entry->flags_extended &
+ struct entry_common *ondisk_ext;
+ uint16_t flags_extended = htons(entry->flags_extended &
GIT_INDEX_ENTRY_EXTENDED_FLAGS);
- memcpy(mem, &ondisk_ext, path_offset);
- path = (char *)mem + path_offset;
- disk_size -= path_offset;
+
+ switch (index->oid_type) {
+ case GIT_OID_SHA1:
+ memcpy(&ondisk_ext_sha1, &ondisk_sha1,
+ sizeof(index_entry_short_sha1));
+ ondisk_ext_sha1.flags_extended = flags_extended;
+ ondisk_ext = &ondisk_ext_sha1.common;
+ break;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ case GIT_OID_SHA256:
+ memcpy(&ondisk_ext_sha256, &ondisk_sha256,
+ sizeof(index_entry_short_sha256));
+ ondisk_ext_sha256.flags_extended = flags_extended;
+ ondisk_ext = &ondisk_ext_sha256.common;
+ break;
+#endif
+ default:
+ GIT_ASSERT(!"invalid oid type");
+ }
+
+ memcpy(mem, ondisk_ext, path_offset);
} else {
- const size_t path_offset = offsetof(struct entry_short, path);
- memcpy(mem, &ondisk, path_offset);
- path = (char *)mem + path_offset;
- disk_size -= path_offset;
+ switch (index->oid_type) {
+ case GIT_OID_SHA1:
+ memcpy(mem, &ondisk_sha1, path_offset);
+ break;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ case GIT_OID_SHA256:
+ memcpy(mem, &ondisk_sha256, path_offset);
+ break;
+#endif
+ default:
+ GIT_ASSERT(!"invalid oid type");
+ }
}
+ path = (char *)mem + path_offset;
+ disk_size -= path_offset;
+
if (last) {
varint_len = git_encode_varint((unsigned char *) path,
disk_size, strlen(last) - same_len);
@@ -2877,7 +3073,7 @@ static int write_entries(git_index *index, git_filebuf *file)
last = "";
git_vector_foreach(entries, i, entry) {
- if ((error = write_disk_entry(file, entry, last)) < 0)
+ if ((error = write_disk_entry(index, file, entry, last)) < 0)
break;
if (index->version >= INDEX_VERSION_NUMBER_COMP)
last = entry->path;
@@ -2955,8 +3151,9 @@ done:
return error;
}
-static int create_reuc_extension_data(git_str *reuc_buf, git_index_reuc_entry *reuc)
+static int create_reuc_extension_data(git_str *reuc_buf, git_index *index, git_index_reuc_entry *reuc)
{
+ size_t oid_size = git_oid_size(index->oid_type);
int i;
int error = 0;
@@ -2970,7 +3167,7 @@ static int create_reuc_extension_data(git_str *reuc_buf, git_index_reuc_entry *r
}
for (i = 0; i < 3; i++) {
- if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_SHA1_SIZE)) < 0)
+ if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, oid_size)) < 0)
return error;
}
@@ -2987,7 +3184,7 @@ static int write_reuc_extension(git_index *index, git_filebuf *file)
int error = 0;
git_vector_foreach(out, i, reuc) {
- if ((error = create_reuc_extension_data(&reuc_buf, reuc)) < 0)
+ if ((error = create_reuc_extension_data(&reuc_buf, index, reuc)) < 0)
goto done;
}
@@ -3036,7 +3233,7 @@ static void clear_uptodate(git_index *index)
}
static int write_index(
- unsigned char checksum[GIT_HASH_SHA1_SIZE],
+ unsigned char checksum[GIT_HASH_MAX_SIZE],
size_t *checksum_size,
git_index *index,
git_filebuf *file)
@@ -3048,7 +3245,9 @@ static int write_index(
GIT_ASSERT_ARG(index);
GIT_ASSERT_ARG(file);
- *checksum_size = GIT_HASH_SHA1_SIZE;
+ GIT_ASSERT(index->oid_type);
+
+ *checksum_size = git_hash_size(git_oid_algorithm(index->oid_type));
if (index->version <= INDEX_VERSION_NUMBER_EXT) {
is_extended = is_index_extended(index);
@@ -3209,7 +3408,7 @@ cleanup:
if (error < 0)
return error;
- error = git_tree_cache_read_tree(&index->tree, tree, &index->tree_pool);
+ error = git_tree_cache_read_tree(&index->tree, tree, index->oid_type, &index->tree_pool);
return error;
}
@@ -3674,7 +3873,7 @@ int git_indexwriter_init(
writer->index = index;
- filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(GIT_OID_SHA1));
+ filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(index->oid_type));
GIT_ASSERT(filebuf_hash);
if (!index->index_file_path)
@@ -3716,7 +3915,7 @@ int git_indexwriter_init_for_operation(
int git_indexwriter_commit(git_indexwriter *writer)
{
- unsigned char checksum[GIT_HASH_SHA1_SIZE];
+ unsigned char checksum[GIT_HASH_MAX_SIZE];
size_t checksum_size;
int error;
diff --git a/src/libgit2/index.h b/src/libgit2/index.h
index 71bb096f7..53c29977d 100644
--- a/src/libgit2/index.h
+++ b/src/libgit2/index.h
@@ -27,7 +27,7 @@ struct git_index {
char *index_file_path;
git_futils_filestamp stamp;
- unsigned char checksum[GIT_HASH_SHA1_SIZE];
+ unsigned char checksum[GIT_HASH_MAX_SIZE];
git_vector entries;
git_idxmap *entries_map;
@@ -35,6 +35,8 @@ struct git_index {
git_vector deleted; /* deleted entries if readers > 0 */
git_atomic32 readers; /* number of active iterators */
+ git_oid_t oid_type;
+
unsigned int on_disk:1;
unsigned int ignore_case:1;
unsigned int distrust_filemode:1;
@@ -141,6 +143,17 @@ GIT_INLINE(unsigned char *) git_index__checksum(git_index *index)
return index->checksum;
}
+/* SHA256-aware internal functions */
+
+extern int git_index__new(
+ git_index **index_out,
+ git_oid_t oid_type);
+
+extern int git_index__open(
+ git_index **index_out,
+ const char *index_path,
+ git_oid_t oid_type);
+
/* Copy the current entries vector *and* increment the index refcount.
* Call `git_index__release_snapshot` when done.
*/
diff --git a/src/libgit2/merge.c b/src/libgit2/merge.c
index df2cefb29..9a52b9f78 100644
--- a/src/libgit2/merge.c
+++ b/src/libgit2/merge.c
@@ -1997,8 +1997,11 @@ static int index_update_reuc(git_index *index, git_merge_diff_list *diff_list)
return 0;
}
-static int index_from_diff_list(git_index **out,
- git_merge_diff_list *diff_list, bool skip_reuc)
+static int index_from_diff_list(
+ git_index **out,
+ git_merge_diff_list *diff_list,
+ git_oid_t oid_type,
+ bool skip_reuc)
{
git_index *index;
size_t i;
@@ -2007,7 +2010,7 @@ static int index_from_diff_list(git_index **out,
*out = NULL;
- if ((error = git_index_new(&index)) < 0)
+ if ((error = git_index__new(&index, oid_type)) < 0)
return error;
if ((error = git_index__fill(index, &diff_list->staged)) < 0)
@@ -2157,7 +2160,7 @@ int git_merge__iterators(
}
}
- error = index_from_diff_list(out, diff_list,
+ error = index_from_diff_list(out, diff_list, repo->oid_type,
(opts.flags & GIT_MERGE_SKIP_REUC));
done:
@@ -2200,8 +2203,8 @@ int git_merge_trees(
result = our_tree;
if (result) {
- if ((error = git_index_new(out)) == 0)
- error = git_index_read_tree(*out, result);
+ if ((error = git_index__new(out, repo->oid_type)) == 0)
+ error = git_index_read_tree(*out, result);
return error;
}
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 3f57fb23c..4bf92dcdc 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -1547,7 +1547,8 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
if ((error = repository_index_path(&index_path, repo)) < 0)
return error;
- error = git_index_open(&index, index_path.ptr);
+ error = git_index__open(&index, index_path.ptr, repo->oid_type);
+
if (!error) {
GIT_REFCOUNT_OWN(index, repo);
diff --git a/src/libgit2/stash.c b/src/libgit2/stash.c
index 319ae3a3f..b49e95cdb 100644
--- a/src/libgit2/stash.c
+++ b/src/libgit2/stash.c
@@ -284,7 +284,7 @@ static int build_untracked_tree(
struct stash_update_rules data = {0};
int error;
- if ((error = git_index_new(&i_index)) < 0)
+ if ((error = git_index__new(&i_index, repo->oid_type)) < 0)
goto cleanup;
if (flags & GIT_STASH_INCLUDE_UNTRACKED) {
@@ -487,7 +487,7 @@ static int commit_worktree(
int error = 0, ignorecase;
if ((error = git_repository_index(&r_index, repo) < 0) ||
- (error = git_index_new(&i_index)) < 0 ||
+ (error = git_index__new(&i_index, repo->oid_type)) < 0 ||
(error = git_index__fill(i_index, &r_index->entries) < 0) ||
(error = git_repository__configmap_lookup(&ignorecase, repo, GIT_CONFIGMAP_IGNORECASE)) < 0)
goto cleanup;
@@ -732,7 +732,7 @@ int git_stash_save_with_opts(
i_commit, b_commit, u_commit)) < 0)
goto cleanup;
} else {
- if ((error = git_index_new(&paths_index)) < 0 ||
+ if ((error = git_index__new(&paths_index, repo->oid_type)) < 0 ||
(error = retrieve_head(&head, repo)) < 0 ||
(error = git_reference_peel((git_object**)&tree, head, GIT_OBJECT_TREE)) < 0 ||
(error = git_index_read_tree(paths_index, tree)) < 0 ||
@@ -1003,6 +1003,7 @@ static int stage_new_file(const git_index_entry **entries, void *data)
static int stage_new_files(
git_index **out,
+ git_repository *repo,
git_tree *parent_tree,
git_tree *tree)
{
@@ -1011,7 +1012,7 @@ static int stage_new_files(
git_index *index = NULL;
int error;
- if ((error = git_index_new(&index)) < 0 ||
+ if ((error = git_index__new(&index, repo->oid_type)) < 0 ||
(error = git_iterator_for_tree(
&iterators[0], parent_tree, &iterator_options)) < 0 ||
(error = git_iterator_for_tree(
@@ -1095,10 +1096,10 @@ int git_stash_apply(
* previously unstaged contents are staged, not the previously staged.)
*/
} else if ((opts.flags & GIT_STASH_APPLY_REINSTATE_INDEX) == 0) {
- if ((error = stage_new_files(
- &stash_adds, stash_parent_tree, stash_tree)) < 0 ||
- (error = merge_indexes(
- &unstashed_index, repo, stash_parent_tree, repo_index, stash_adds)) < 0)
+ if ((error = stage_new_files(&stash_adds, repo,
+ stash_parent_tree, stash_tree)) < 0 ||
+ (error = merge_indexes(&unstashed_index, repo,
+ stash_parent_tree, repo_index, stash_adds)) < 0)
goto cleanup;
}
diff --git a/src/libgit2/tree-cache.c b/src/libgit2/tree-cache.c
index 19fad85ae..95d879860 100644
--- a/src/libgit2/tree-cache.c
+++ b/src/libgit2/tree-cache.c
@@ -71,12 +71,16 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char
}
}
-static int read_tree_internal(git_tree_cache **out,
- const char **buffer_in, const char *buffer_end,
- git_pool *pool)
+static int read_tree_internal(
+ git_tree_cache **out,
+ const char **buffer_in,
+ const char *buffer_end,
+ git_oid_t oid_type,
+ git_pool *pool)
{
git_tree_cache *tree = NULL;
const char *name_start, *buffer;
+ size_t oid_size = git_oid_size(oid_type);
int count;
buffer = name_start = *buffer_in;
@@ -87,7 +91,7 @@ static int read_tree_internal(git_tree_cache **out,
if (++buffer >= buffer_end)
goto corrupted;
- if (git_tree_cache_new(&tree, name_start, pool) < 0)
+ if (git_tree_cache_new(&tree, name_start, oid_type, pool) < 0)
return -1;
/* Blank-terminated ASCII decimal number of entries in this tree */
@@ -108,14 +112,14 @@ static int read_tree_internal(git_tree_cache **out,
if (*buffer != '\n' || ++buffer > buffer_end)
goto corrupted;
- /* The SHA1 is only there if it's not invalidated */
+ /* The OID is only there if it's not invalidated */
if (tree->entry_count >= 0) {
/* 160-bit SHA-1 for this tree and it's children */
- if (buffer + GIT_OID_SHA1_SIZE > buffer_end)
+ if (buffer + oid_size > buffer_end)
goto corrupted;
- git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, GIT_OID_SHA1);
- buffer += GIT_OID_SHA1_SIZE;
+ git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, oid_type);
+ buffer += oid_size;
}
/* Parse children: */
@@ -130,7 +134,7 @@ static int read_tree_internal(git_tree_cache **out,
memset(tree->children, 0x0, bufsize);
for (i = 0; i < tree->children_count; ++i) {
- if (read_tree_internal(&tree->children[i], &buffer, buffer_end, pool) < 0)
+ if (read_tree_internal(&tree->children[i], &buffer, buffer_end, oid_type, pool) < 0)
goto corrupted;
}
}
@@ -144,11 +148,16 @@ static int read_tree_internal(git_tree_cache **out,
return -1;
}
-int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool)
+int git_tree_cache_read(
+ git_tree_cache **tree,
+ const char *buffer,
+ size_t buffer_size,
+ git_oid_t oid_type,
+ git_pool *pool)
{
const char *buffer_end = buffer + buffer_size;
- if (read_tree_internal(tree, &buffer, buffer_end, pool) < 0)
+ if (read_tree_internal(tree, &buffer, buffer_end, oid_type, pool) < 0)
return -1;
if (buffer < buffer_end) {
@@ -201,7 +210,7 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
continue;
}
- if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), pool)) < 0)
+ if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), cache->oid_type, pool)) < 0)
return error;
if ((error = git_tree_lookup(&subtree, repo, git_tree_entry_id(entry))) < 0)
@@ -219,12 +228,12 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
return 0;
}
-int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool)
+int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool)
{
int error;
git_tree_cache *cache;
- if ((error = git_tree_cache_new(&cache, "", pool)) < 0)
+ if ((error = git_tree_cache_new(&cache, "", oid_type, pool)) < 0)
return error;
if ((error = read_tree_recursive(cache, tree, pool)) < 0)
@@ -234,7 +243,7 @@ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_poo
return 0;
}
-int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
+int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool)
{
size_t name_len, alloc_size;
git_tree_cache *tree;
@@ -248,6 +257,7 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
memset(tree, 0x0, sizeof(git_tree_cache));
/* NUL-terminated tree name */
+ tree->oid_type = oid_type;
tree->namelen = name_len;
memcpy(tree->name, name, name_len);
tree->name[name_len] = '\0';
@@ -263,7 +273,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
if (tree->entry_count != -1)
- git_str_put(out, (char *)&tree->oid.id, GIT_OID_SHA1_SIZE);
+ git_str_put(out, (char *)&tree->oid.id, git_oid_size(tree->oid_type));
for (i = 0; i < tree->children_count; i++)
write_tree(out, tree->children[i]);
diff --git a/src/libgit2/tree-cache.h b/src/libgit2/tree-cache.h
index a27e30466..e4a73f277 100644
--- a/src/libgit2/tree-cache.h
+++ b/src/libgit2/tree-cache.h
@@ -18,6 +18,8 @@ typedef struct git_tree_cache {
struct git_tree_cache **children;
size_t children_count;
+ git_oid_t oid_type;
+
ssize_t entry_count;
git_oid oid;
size_t namelen;
@@ -25,14 +27,14 @@ typedef struct git_tree_cache {
} git_tree_cache;
int git_tree_cache_write(git_str *out, git_tree_cache *tree);
-int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool);
+int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_oid_t oid_type, git_pool *pool);
void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path);
const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path);
-int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool);
+int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool);
/**
* Read a tree as the root of the tree cache (like for `git read-tree`)
*/
-int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool);
+int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool);
void git_tree_cache_free(git_tree_cache *tree);
#endif
diff --git a/src/libgit2/tree.c b/src/libgit2/tree.c
index 9293d9422..236a87f7e 100644
--- a/src/libgit2/tree.c
+++ b/src/libgit2/tree.c
@@ -731,7 +731,7 @@ int git_tree__write_index(
return ret;
/* Read the tree cache into the index */
- ret = git_tree_cache_read_tree(&index->tree, tree, &index->tree_pool);
+ ret = git_tree_cache_read_tree(&index->tree, tree, index->oid_type, &index->tree_pool);
git_tree_free(tree);
return ret;
diff --git a/tests/libgit2/checkout/index.c b/tests/libgit2/checkout/index.c
index 6432cba84..3dfdaa630 100644
--- a/tests/libgit2/checkout/index.c
+++ b/tests/libgit2/checkout/index.c
@@ -4,6 +4,7 @@
#include "git2/checkout.h"
#include "futils.h"
#include "repository.h"
+#include "index.h"
#include "remote.h"
#include "repo/repo_helpers.h"
@@ -834,7 +835,7 @@ void test_checkout_index__adding_conflict_removes_stage_0(void)
git_index *new_index, *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- cl_git_pass(git_index_new(&new_index));
+ cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
add_conflict(new_index, "new.txt");
cl_git_pass(git_checkout_index(g_repo, new_index, &opts));
diff --git a/tests/libgit2/clone/nonetwork.c b/tests/libgit2/clone/nonetwork.c
index eab633635..5316003f8 100644
--- a/tests/libgit2/clone/nonetwork.c
+++ b/tests/libgit2/clone/nonetwork.c
@@ -5,6 +5,7 @@
#include "remote.h"
#include "futils.h"
#include "repository.h"
+#include "index.h"
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
@@ -271,7 +272,7 @@ void test_clone_nonetwork__clone_tag_to_tree(void)
stage = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_odb(&odb, stage));
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
memset(&entry, 0, sizeof(git_index_entry));
entry.path = file_path;
diff --git a/tests/libgit2/diff/index.c b/tests/libgit2/diff/index.c
index 5773b748e..b7866750b 100644
--- a/tests/libgit2/diff/index.c
+++ b/tests/libgit2/diff/index.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
+#include "index.h"
static git_repository *g_repo = NULL;
@@ -278,7 +279,7 @@ void test_diff_index__to_index(void)
git_diff *diff;
diff_expects exp;
- cl_git_pass(git_index_new(&old_index));
+ cl_git_pass(git_index__new(&old_index, GIT_OID_SHA1));
old_tree = resolve_commit_oid_to_tree(g_repo, a_commit);
cl_git_pass(git_index_read_tree(old_index, old_tree));
diff --git a/tests/libgit2/index/cache.c b/tests/libgit2/index/cache.c
index 7576331b0..77f19a50b 100644
--- a/tests/libgit2/index/cache.c
+++ b/tests/libgit2/index/cache.c
@@ -24,7 +24,7 @@ void test_index_cache__write_extension_at_root(void)
const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6";
const char *index_file = "index-tree";
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
@@ -35,7 +35,7 @@ void test_index_cache__write_extension_at_root(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree);
cl_assert_equal_i(git_index_entrycount(index), index->tree->entry_count);
@@ -56,7 +56,7 @@ void test_index_cache__write_extension_invalidated_root(void)
const char *index_file = "index-tree-invalidated";
git_index_entry entry;
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
@@ -77,7 +77,7 @@ void test_index_cache__write_extension_invalidated_root(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree);
cl_assert_equal_i(-1, index->tree->entry_count);
@@ -96,7 +96,7 @@ void test_index_cache__read_tree_no_children(void)
git_tree *tree;
git_oid id;
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, "45dd856fdd4d89b884c340ba0e047752d9b085d6", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
diff --git a/tests/libgit2/index/inmemory.c b/tests/libgit2/index/inmemory.c
index 38e91e0fd..39374af67 100644
--- a/tests/libgit2/index/inmemory.c
+++ b/tests/libgit2/index/inmemory.c
@@ -1,10 +1,11 @@
#include "clar_libgit2.h"
+#include "index.h"
void test_index_inmemory__can_create_an_inmemory_index(void)
{
git_index *index;
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert_equal_i(0, (int)git_index_entrycount(index));
git_index_free(index);
@@ -14,7 +15,7 @@ void test_index_inmemory__cannot_add_bypath_to_an_inmemory_index(void)
{
git_index *index;
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert_equal_i(GIT_ERROR, git_index_add_bypath(index, "test.txt"));
diff --git a/tests/libgit2/index/racy.c b/tests/libgit2/index/racy.c
index 07b3b73d4..a1d6f9c6e 100644
--- a/tests/libgit2/index/racy.c
+++ b/tests/libgit2/index/racy.c
@@ -287,7 +287,7 @@ void test_index_racy__read_index_smudges(void)
setup_race();
cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_index_new(&newindex));
+ cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1));
cl_git_pass(git_index_read_index(newindex, index));
cl_assert(entry = git_index_get_bypath(newindex, "A", 0));
@@ -305,7 +305,7 @@ void test_index_racy__read_index_clears_uptodate_bit(void)
setup_uptodate_files();
cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_index_new(&newindex));
+ cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1));
cl_git_pass(git_index_read_index(newindex, index));
/* ensure that files brought in from the other index are not uptodate */
diff --git a/tests/libgit2/index/read_index.c b/tests/libgit2/index/read_index.c
index ac03cf177..9c80be299 100644
--- a/tests/libgit2/index/read_index.c
+++ b/tests/libgit2/index/read_index.c
@@ -42,7 +42,7 @@ void test_index_read_index__maintains_stat_cache(void)
/* read-tree, then read index */
git_tree_lookup(&tree, _repo, &index_id);
- cl_git_pass(git_index_new(&new_index));
+ cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(new_index, tree));
git_tree_free(tree);
@@ -81,7 +81,7 @@ static bool roundtrip_with_read_index(const char *tree_idstr)
cl_git_pass(git_oid__fromstr(&tree_id, tree_idstr, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
- cl_git_pass(git_index_new(&tree_index));
+ cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(tree_index, tree));
cl_git_pass(git_index_read_index(_index, tree_index));
cl_git_pass(git_index_write_tree(&new_tree_id, _index));
@@ -113,12 +113,12 @@ void test_index_read_index__read_and_writes(void)
cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
- cl_git_pass(git_index_new(&tree_index));
+ cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(tree_index, tree));
cl_git_pass(git_index_read_index(_index, tree_index));
cl_git_pass(git_index_write(_index));
- cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
+ cl_git_pass(git_index__open(&new_index, git_index_path(_index), GIT_OID_SHA1));
cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
cl_assert_equal_oid(&tree_id, &new_tree_id);
@@ -174,8 +174,8 @@ void test_index_read_index__handles_conflicts(void)
cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
- cl_git_pass(git_index_new(&index));
- cl_git_pass(git_index_new(&new_index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
+ cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(index, tree));
cl_git_pass(git_index_read_tree(new_index, tree));
diff --git a/tests/libgit2/index/tests.c b/tests/libgit2/index/tests.c
index da3ff6dd7..b48eb0fc1 100644
--- a/tests/libgit2/index/tests.c
+++ b/tests/libgit2/index/tests.c
@@ -81,7 +81,7 @@ void test_index_tests__empty_index(void)
{
git_index *index;
- cl_git_pass(git_index_open(&index, "in-memory-index"));
+ cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA1));
cl_assert(index->on_disk == 0);
cl_assert(git_index_entrycount(index) == 0);
@@ -96,7 +96,7 @@ void test_index_tests__default_test_index(void)
unsigned int i;
git_index_entry **entries;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count);
@@ -119,7 +119,7 @@ void test_index_tests__gitgit_index(void)
{
git_index *index;
- cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX2_PATH, GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count_2);
@@ -134,7 +134,7 @@ void test_index_tests__find_in_existing(void)
git_index *index;
unsigned int i;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
size_t idx;
@@ -151,7 +151,7 @@ void test_index_tests__find_in_empty(void)
git_index *index;
unsigned int i;
- cl_git_pass(git_index_open(&index, "fake-index"));
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
@@ -166,7 +166,7 @@ void test_index_tests__find_prefix(void)
const git_index_entry *entry;
size_t pos;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_find_prefix(&pos, index, "src"));
entry = git_index_get_byindex(index, pos);
@@ -187,7 +187,7 @@ void test_index_tests__write(void)
copy_file(TEST_INDEXBIG_PATH, "index_rewrite");
- cl_git_pass(git_index_open(&index, "index_rewrite"));
+ cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_git_pass(git_index_write(index));
@@ -218,7 +218,7 @@ void test_index_tests__sort1(void)
/* sort the entries in an empty index */
git_index *index;
- cl_git_pass(git_index_open(&index, "fake-index"));
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1));
/* FIXME: this test is slightly dumb */
cl_assert(git_vector_is_sorted(&index->entries));
@@ -703,7 +703,7 @@ void test_index_tests__write_tree_invalid_unowned_index(void)
git_index_entry entry = {{0}};
git_oid tree_id;
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_oid__fromstr(&entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318", GIT_OID_SHA1));
entry.path = "foo";
@@ -966,7 +966,7 @@ void test_index_tests__reload_from_disk(void)
cl_git_pass(git_repository_index(&write_index, repo));
cl_assert_equal_i(false, write_index->on_disk);
- cl_git_pass(git_index_open(&read_index, write_index->index_file_path));
+ cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA1));
cl_assert_equal_i(false, read_index->on_disk);
/* Stage two new files against the write_index */
@@ -1004,7 +1004,7 @@ void test_index_tests__corrupted_extension(void)
{
git_index *index;
- cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR);
+ cl_git_fail_with(git_index__open(&index, TEST_INDEXBAD_PATH, GIT_OID_SHA1), GIT_ERROR);
}
void test_index_tests__reload_while_ignoring_case(void)
@@ -1012,7 +1012,7 @@ void test_index_tests__reload_while_ignoring_case(void)
git_index *index;
unsigned int caps;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_vector_verify_sorted(&index->entries));
caps = git_index_caps(index);
@@ -1037,7 +1037,7 @@ void test_index_tests__change_icase_on_instance(void)
unsigned int caps;
const git_index_entry *e;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_vector_verify_sorted(&index->entries));
caps = git_index_caps(index);
@@ -1093,7 +1093,7 @@ void test_index_tests__can_iterate(void)
size_t i, iterator_idx = 0, found = 0;
int ret;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_iterator_new(&iterator, index));
cl_assert(git_vector_is_sorted(&iterator->snap));
@@ -1136,7 +1136,7 @@ void test_index_tests__can_modify_while_iterating(void)
size_t expected = 0, seen = 0;
int ret;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_iterator_new(&iterator, index));
expected = git_index_entrycount(index);
diff --git a/tests/libgit2/index/tests256.c b/tests/libgit2/index/tests256.c
new file mode 100644
index 000000000..68a17a6f0
--- /dev/null
+++ b/tests/libgit2/index/tests256.c
@@ -0,0 +1,1109 @@
+#include "clar_libgit2.h"
+#include "index.h"
+
+static const size_t index_entry_count = 4344;
+#define TEST_INDEX_PATH cl_fixture("git-sha256.index")
+
+static git_repository_init_options repo_init_opts =
+ GIT_REPOSITORY_INIT_OPTIONS_INIT;
+
+/* Suite data */
+struct test_entry {
+ size_t index;
+ char path[128];
+ off64_t file_size;
+ git_time_t mtime;
+};
+
+static struct test_entry test_entries[] = {
+ { 892, "Makefile", 120084, 0x642c3a6e },
+ { 1542, "git.c", 27432, 0x642c3a6e },
+ { 1737, "perl/Git.pm", 48084, 0x642c3a6e },
+ { 1961, "t/Makefile", 4711, 0x642c3a6e },
+ { 4343, "zlib.c", 6271, 0x642c3a6f }
+};
+
+/* Helpers */
+static void copy_file(const char *src, const char *dst)
+{
+ git_str source_buf = GIT_STR_INIT;
+ git_file dst_fd;
+
+ cl_git_pass(git_futils_readbuffer(&source_buf, src));
+
+ dst_fd = git_futils_creat_withpath(dst, 0777, 0666); /* -V536 */
+ if (dst_fd < 0)
+ goto cleanup;
+
+ cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size));
+
+cleanup:
+ git_str_dispose(&source_buf);
+ p_close(dst_fd);
+}
+
+static void files_are_equal(const char *a, const char *b)
+{
+ git_str buf_a = GIT_STR_INIT;
+ git_str buf_b = GIT_STR_INIT;
+
+ if (git_futils_readbuffer(&buf_a, a) < 0)
+ cl_assert(0);
+
+ if (git_futils_readbuffer(&buf_b, b) < 0) {
+ git_str_dispose(&buf_a);
+ cl_assert(0);
+ }
+
+ cl_assert_equal_sz(buf_a.size, buf_b.size);
+ cl_assert(!memcmp(buf_a.ptr, buf_b.ptr, buf_a.size));
+
+ git_str_dispose(&buf_a);
+ git_str_dispose(&buf_b);
+}
+
+
+/* Fixture setup and teardown */
+void test_index_tests256__initialize(void)
+{
+ repo_init_opts.flags |= GIT_REPOSITORY_INIT_MKPATH;
+ repo_init_opts.oid_type = GIT_OID_SHA256;
+}
+
+void test_index_tests256__cleanup(void)
+{
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 0));
+}
+
+void test_index_tests256__empty_index(void)
+{
+ git_index *index;
+
+ cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA256));
+ cl_assert(index->on_disk == 0);
+
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_vector_is_sorted(&index->entries));
+
+ git_index_free(index);
+}
+
+void test_index_tests256__default_test_index(void)
+{
+ git_index *index;
+ unsigned int i;
+ git_index_entry **entries;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_assert(index->on_disk);
+
+ cl_assert_equal_sz(git_index_entrycount(index), index_entry_count);
+ cl_assert(git_vector_is_sorted(&index->entries));
+
+ entries = (git_index_entry **)index->entries.contents;
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
+ git_index_entry *e = entries[test_entries[i].index];
+
+ cl_assert_equal_s(e->path, test_entries[i].path);
+ cl_assert_equal_i(e->mtime.seconds, test_entries[i].mtime);
+ cl_assert_equal_i(e->file_size, test_entries[i].file_size);
+ }
+
+ git_index_free(index);
+}
+
+void test_index_tests256__find_in_existing(void)
+{
+ git_index *index;
+ unsigned int i;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
+ size_t idx;
+
+ cl_assert(!git_index_find(&idx, index, test_entries[i].path));
+ cl_assert(idx == test_entries[i].index);
+ }
+
+ git_index_free(index);
+}
+
+void test_index_tests256__find_in_empty(void)
+{
+ git_index *index;
+ unsigned int i;
+
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA256));
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
+ cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
+ }
+
+ git_index_free(index);
+}
+
+void test_index_tests256__find_prefix(void)
+{
+ git_index *index;
+ const git_index_entry *entry;
+ size_t pos;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+
+ cl_git_pass(git_index_find_prefix(&pos, index, "Documentation"));
+ entry = git_index_get_byindex(index, pos);
+ cl_assert(git__strcmp(entry->path, "Documentation/.gitattributes") == 0);
+
+ cl_git_pass(git_index_find_prefix(&pos, index, "contrib/RE"));
+ entry = git_index_get_byindex(index, pos);
+ cl_assert(git__strcmp(entry->path, "contrib/README") == 0);
+
+ cl_assert(GIT_ENOTFOUND == git_index_find_prefix(NULL, index, "blah"));
+
+ git_index_free(index);
+}
+
+void test_index_tests256__write(void)
+{
+ git_index *index;
+
+ copy_file(TEST_INDEX_PATH, "index_rewrite");
+
+ cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA256));
+ cl_assert(index->on_disk);
+
+ cl_git_pass(git_index_write(index));
+ files_are_equal(TEST_INDEX_PATH, "index_rewrite");
+
+ git_index_free(index);
+
+ p_unlink("index_rewrite");
+}
+
+void test_index_tests256__sort0(void)
+{
+ /* sort the entries in an index */
+
+ /*
+ * TODO: This no longer applies:
+ * index sorting in Git uses some specific changes to the way
+ * directories are sorted.
+ *
+ * We need to specifically check for this by creating a new
+ * index, adding entries in random order and then
+ * checking for consistency
+ */
+}
+
+void test_index_tests256__sort1(void)
+{
+ /* sort the entries in an empty index */
+ git_index *index;
+
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA256));
+
+ /* FIXME: this test is slightly dumb */
+ cl_assert(git_vector_is_sorted(&index->entries));
+
+ git_index_free(index);
+}
+
+static void cleanup_myrepo(void *opaque)
+{
+ GIT_UNUSED(opaque);
+ cl_fixture_cleanup("myrepo");
+}
+
+void test_index_tests256__add(void)
+{
+ git_index *index;
+ git_filebuf file = GIT_FILEBUF_INIT;
+ git_repository *repo;
+ const git_index_entry *entry;
+ git_oid id1;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ /* Initialize a new repository */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ /* Create a new file in the working directory */
+ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0, 0666));
+ cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
+ cl_git_pass(git_filebuf_commit(&file));
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid__fromstr(&id1, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ /* Add the new file to the index */
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ entry = git_index_get_byindex(index, 0);
+
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert_equal_oid(&id1, &entry->id);
+
+ /* Test access by path instead of index */
+ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert_equal_oid(&id1, &entry->id);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__add_frombuffer(void)
+{
+ git_index *index;
+ git_repository *repo;
+ git_index_entry entry;
+ const git_index_entry *returned_entry;
+
+ git_oid id1;
+ git_blob *blob;
+
+ const char *content = "hey there\n";
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ /* Initialize a new repository */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid__fromstr(&id1, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ /* Add the new file to the index */
+ memset(&entry, 0x0, sizeof(git_index_entry));
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry,
+ content, strlen(content)));
+
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ returned_entry = git_index_get_byindex(index, 0);
+
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+ /* And mode is the one asked */
+ cl_assert_equal_i(GIT_FILEMODE_BLOB, returned_entry->mode);
+
+ /* Test access by path instead of index */
+ cl_assert((returned_entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+
+ /* Test the blob is in the repository */
+ cl_git_pass(git_blob_lookup(&blob, repo, &id1));
+ cl_assert_equal_s(
+ content, git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__dirty_and_clean(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_index_entry entry = {{0}};
+
+ /* Index is not dirty after opening */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index is dirty after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_is_dirty(index));
+
+ /* Index is not dirty after write */
+ cl_git_pass(git_index_write(index));
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index is dirty after removing an entry */
+ cl_git_pass(git_index_remove_bypath(index, "test.txt"));
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_index_is_dirty(index));
+
+ /* Index is not dirty after write */
+ cl_git_pass(git_index_write(index));
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index remains not dirty after read */
+ cl_git_pass(git_index_read(index, 0));
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index is dirty when we do an unforced read with dirty content */
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_pass(git_index_read(index, 0));
+ cl_assert(git_index_is_dirty(index));
+
+ /* Index is clean when we force a read with dirty content */
+ cl_git_pass(git_index_read(index, 1));
+ cl_assert(!git_index_is_dirty(index));
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__dirty_fails_optionally(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_index_entry entry = {{0}};
+
+ /* Index is not dirty after opening */
+ repo = cl_git_sandbox_init("testrepo");
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /* Index is dirty after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_pass(git_checkout_head(repo, NULL));
+
+ /* Index is dirty (again) after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 1));
+ cl_git_fail_with(GIT_EINDEXDIRTY, git_checkout_head(repo, NULL));
+
+ git_index_free(index);
+ cl_git_sandbox_cleanup();
+}
+
+void test_index_tests256__add_frombuffer_reset_entry(void)
+{
+ git_index *index;
+ git_repository *repo;
+ git_index_entry entry;
+ const git_index_entry *returned_entry;
+ git_filebuf file = GIT_FILEBUF_INIT;
+
+ git_oid id1;
+ git_blob *blob;
+ const char *old_content = "here\n";
+ const char *content = "hey there\n";
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ /* Initialize a new repository */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0, 0666));
+ cl_git_pass(git_filebuf_write(&file, old_content, strlen(old_content)));
+ cl_git_pass(git_filebuf_commit(&file));
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid__fromstr(&id1, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+ /* Add the new file to the index */
+ memset(&entry, 0x0, sizeof(git_index_entry));
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry,
+ content, strlen(content)));
+
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ returned_entry = git_index_get_byindex(index, 0);
+
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+ /* And mode is the one asked */
+ cl_assert_equal_i(GIT_FILEMODE_BLOB, returned_entry->mode);
+
+ /* Test access by path instead of index */
+ cl_assert((returned_entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+ cl_assert_equal_i(0, returned_entry->dev);
+ cl_assert_equal_i(0, returned_entry->ino);
+ cl_assert_equal_i(0, returned_entry->uid);
+ cl_assert_equal_i(0, returned_entry->uid);
+ cl_assert_equal_i(10, returned_entry->file_size);
+
+ /* Test the blob is in the repository */
+ cl_git_pass(git_blob_lookup(&blob, repo, &id1));
+ cl_assert_equal_s(content, git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
+{
+ git_repository *bare_repo;
+ git_index *index;
+
+ cl_git_pass(git_repository_open(&bare_repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_index(&index, bare_repo));
+
+ cl_assert_equal_i(GIT_EBAREREPO, git_index_add_bypath(index, "test.txt"));
+
+ git_index_free(index);
+ git_repository_free(bare_repo);
+}
+
+static void assert_add_bypath_fails(git_repository *repo, const char *fn)
+{
+ git_index *index;
+ git_str path = GIT_STR_INIT;
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_str_joinpath(&path, "./invalid", fn);
+
+ cl_git_mkfile(path.ptr, NULL);
+ cl_git_fail(git_index_add_bypath(index, fn));
+ cl_must_pass(p_unlink(path.ptr));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_str_dispose(&path);
+ git_index_free(index);
+}
+
+/* Test that writing an invalid filename fails */
+void test_index_tests256__cannot_add_invalid_filename(void)
+{
+ git_repository *repo;
+
+ cl_must_pass(p_mkdir("invalid", 0700));
+ cl_git_pass(git_repository_init_ext(&repo, "./invalid", &repo_init_opts));
+ cl_must_pass(p_mkdir("./invalid/subdir", 0777));
+
+ /* cl_git_mkfile() needs the dir to exist */
+ if (!git_fs_path_exists("./invalid/.GIT"))
+ cl_must_pass(p_mkdir("./invalid/.GIT", 0777));
+ if (!git_fs_path_exists("./invalid/.GiT"))
+ cl_must_pass(p_mkdir("./invalid/.GiT", 0777));
+
+ assert_add_bypath_fails(repo, ".git/hello");
+ assert_add_bypath_fails(repo, ".GIT/hello");
+ assert_add_bypath_fails(repo, ".GiT/hello");
+ assert_add_bypath_fails(repo, "./.git/hello");
+ assert_add_bypath_fails(repo, "./foo");
+ assert_add_bypath_fails(repo, "./bar");
+ assert_add_bypath_fails(repo, "subdir/../bar");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+static void assert_add_fails(git_repository *repo, const char *fn)
+{
+ git_index *index;
+ git_str path = GIT_STR_INIT;
+ git_index_entry entry = {{0}};
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ entry.path = fn;
+ entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_oid__fromstr(&entry.id, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ cl_git_fail(git_index_add(index, &entry));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_str_dispose(&path);
+ git_index_free(index);
+}
+
+/*
+ * Test that writing an invalid filename fails on filesystem
+ * specific protected names
+ */
+void test_index_tests256__cannot_add_protected_invalid_filename(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ cl_must_pass(p_mkdir("invalid", 0700));
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ /* add a file to the repository so we can reference it later */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_mkfile("invalid/dummy.txt", "");
+ cl_git_pass(git_index_add_bypath(index, "dummy.txt"));
+ cl_must_pass(p_unlink("invalid/dummy.txt"));
+ cl_git_pass(git_index_remove_bypath(index, "dummy.txt"));
+ git_index_free(index);
+
+ cl_repo_set_bool(repo, "core.protectHFS", true);
+ cl_repo_set_bool(repo, "core.protectNTFS", true);
+
+ assert_add_fails(repo, ".git./hello");
+ assert_add_fails(repo, ".git\xe2\x80\xad/hello");
+ assert_add_fails(repo, "git~1/hello");
+ assert_add_fails(repo, ".git\xe2\x81\xaf/hello");
+ assert_add_fails(repo, ".git::$INDEX_ALLOCATION/dummy-file");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+static void replace_char(char *str, char in, char out)
+{
+ char *c = str;
+
+ while (*c++)
+ if (*c == in)
+ *c = out;
+}
+
+static void assert_write_fails(git_repository *repo, const char *fn_orig)
+{
+ git_index *index;
+ git_oid expected;
+ const git_index_entry *entry;
+ git_str path = GIT_STR_INIT;
+ char *fn;
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ /*
+ * Sneak a valid path into the index, we'll update it
+ * to an invalid path when we try to write the index.
+ */
+ fn = git__strdup(fn_orig);
+ replace_char(fn, '/', '_');
+ replace_char(fn, ':', '!');
+
+ git_str_joinpath(&path, "./invalid", fn);
+
+ cl_git_mkfile(path.ptr, NULL);
+
+ cl_git_pass(git_index_add_bypath(index, fn));
+
+ cl_assert(entry = git_index_get_bypath(index, fn, 0));
+
+ /* kids, don't try this at home */
+ replace_char((char *)entry->path, '_', '/');
+ replace_char((char *)entry->path, '!', ':');
+
+ /* write-tree */
+ cl_git_fail(git_index_write_tree(&expected, index));
+
+ p_unlink(path.ptr);
+
+ cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL));
+ git_str_dispose(&path);
+ git_index_free(index);
+ git__free(fn);
+}
+
+void test_index_tests256__write_tree_invalid_unowned_index(void)
+{
+ git_index *idx;
+ git_repository *repo;
+ git_index_entry entry = {{0}};
+ git_oid tree_id;
+
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA256));
+
+ // TODO: this one is failing
+ cl_git_pass(git_oid__fromstr(&entry.id, "a8c2e0a89a9cbab77c732b6bc39b51a783e3a318a847f46cba7614cac9814291", GIT_OID_SHA256));
+ entry.path = "foo";
+ entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(idx, &entry));
+
+ cl_git_pass(git_repository_init_ext(&repo, "./invalid-id", &repo_init_opts));
+
+ cl_git_fail(git_index_write_tree_to(&tree_id, idx, repo));
+
+ git_index_free(idx);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid-id");
+}
+
+/* Test that writing an invalid filename fails */
+void test_index_tests256__write_invalid_filename(void)
+{
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ assert_write_fails(repo, ".git/hello");
+ assert_write_fails(repo, ".GIT/hello");
+ assert_write_fails(repo, ".GiT/hello");
+ assert_write_fails(repo, "./.git/hello");
+ assert_write_fails(repo, "./foo");
+ assert_write_fails(repo, "./bar");
+ assert_write_fails(repo, "foo/../bar");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+void test_index_tests256__honors_protect_filesystems(void)
+{
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ cl_repo_set_bool(repo, "core.protectHFS", true);
+ cl_repo_set_bool(repo, "core.protectNTFS", true);
+
+ assert_write_fails(repo, ".git./hello");
+ assert_write_fails(repo, ".git\xe2\x80\xad/hello");
+ assert_write_fails(repo, "git~1/hello");
+ assert_write_fails(repo, ".git\xe2\x81\xaf/hello");
+ assert_write_fails(repo, ".git::$INDEX_ALLOCATION/dummy-file");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+void test_index_tests256__protectntfs_on_by_default(void)
+{
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+ assert_write_fails(repo, ".git./hello");
+ assert_write_fails(repo, "git~1/hello");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+void test_index_tests256__can_disable_protectntfs(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ cl_must_pass(p_mkdir("valid", 0700));
+ cl_git_rewritefile("valid/git~1", "steal the shortname");
+
+ cl_git_pass(git_repository_init(&repo, "./valid", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_repo_set_bool(repo, "core.protectNTFS", false);
+
+ cl_git_pass(git_index_add_bypath(index, "git~1"));
+
+ git_index_free(index);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("valid");
+}
+
+void test_index_tests256__remove_entry(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ p_mkdir("index_test", 0770);
+
+ cl_git_pass(git_repository_init(&repo, "index_test", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ cl_git_mkfile("index_test/hello", NULL);
+ cl_git_pass(git_index_add_bypath(index, "hello"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_get_bypath(index, "hello", 0) != NULL);
+
+ cl_git_pass(git_index_remove(index, "hello", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_index_get_bypath(index, "hello", 0) == NULL);
+
+ git_index_free(index);
+ git_repository_free(repo);
+ cl_fixture_cleanup("index_test");
+}
+
+void test_index_tests256__remove_directory(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ p_mkdir("index_test", 0770);
+
+ cl_git_pass(git_repository_init(&repo, "index_test", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert_equal_i(0, (int)git_index_entrycount(index));
+
+ p_mkdir("index_test/a", 0770);
+ cl_git_mkfile("index_test/a/1.txt", NULL);
+ cl_git_mkfile("index_test/a/2.txt", NULL);
+ cl_git_mkfile("index_test/a/3.txt", NULL);
+ cl_git_mkfile("index_test/b.txt", NULL);
+
+ cl_git_pass(git_index_add_bypath(index, "a/1.txt"));
+ cl_git_pass(git_index_add_bypath(index, "a/2.txt"));
+ cl_git_pass(git_index_add_bypath(index, "a/3.txt"));
+ cl_git_pass(git_index_add_bypath(index, "b.txt"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert_equal_i(4, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ cl_git_pass(git_index_remove(index, "a/1.txt", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert_equal_i(3, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ cl_git_pass(git_index_remove_directory(index, "a", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert_equal_i(1, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ git_index_free(index);
+ git_repository_free(repo);
+ cl_fixture_cleanup("index_test");
+}
+
+void test_index_tests256__preserves_case(void)
+{
+ git_repository *repo;
+ git_index *index;
+ const git_index_entry *entry;
+ int index_caps;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ index_caps = git_index_caps(index);
+
+ cl_git_rewritefile("myrepo/test.txt", "hey there\n");
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+ cl_git_pass(p_rename("myrepo/test.txt", "myrepo/TEST.txt"));
+ cl_git_rewritefile("myrepo/TEST.txt", "hello again\n");
+ cl_git_pass(git_index_add_bypath(index, "TEST.txt"));
+
+ if (index_caps & GIT_INDEX_CAPABILITY_IGNORE_CASE)
+ cl_assert_equal_i(1, (int)git_index_entrycount(index));
+ else
+ cl_assert_equal_i(2, (int)git_index_entrycount(index));
+
+ /* Test access by path instead of index */
+ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ /* The path should *not* have changed without an explicit remove */
+ cl_assert(git__strcmp(entry->path, "test.txt") == 0);
+
+ cl_assert((entry = git_index_get_bypath(index, "TEST.txt", 0)) != NULL);
+ if (index_caps & GIT_INDEX_CAPABILITY_IGNORE_CASE)
+ /* The path should *not* have changed without an explicit remove */
+ cl_assert(git__strcmp(entry->path, "test.txt") == 0);
+ else
+ cl_assert(git__strcmp(entry->path, "TEST.txt") == 0);
+
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__elocked(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_filebuf file = GIT_FILEBUF_INIT;
+ const git_error *err;
+ int error;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /* Lock the index file so we fail to lock it */
+ cl_git_pass(git_filebuf_open(&file, index->index_file_path, 0, 0666));
+ error = git_index_write(index);
+ cl_assert_equal_i(GIT_ELOCKED, error);
+
+ err = git_error_last();
+ cl_assert_equal_i(err->klass, GIT_ERROR_INDEX);
+
+ git_filebuf_cleanup(&file);
+ git_index_free(index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__reload_from_disk(void)
+{
+ git_repository *repo;
+ git_index *read_index;
+ git_index *write_index;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_futils_mkdir("./myrepo", 0777, GIT_MKDIR_PATH));
+ cl_git_mkfile("./myrepo/a.txt", "a\n");
+ cl_git_mkfile("./myrepo/b.txt", "b\n");
+
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&write_index, repo));
+ cl_assert_equal_i(false, write_index->on_disk);
+
+ cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA256));
+ cl_assert_equal_i(false, read_index->on_disk);
+
+ /* Stage two new files against the write_index */
+ cl_git_pass(git_index_add_bypath(write_index, "a.txt"));
+ cl_git_pass(git_index_add_bypath(write_index, "b.txt"));
+
+ cl_assert_equal_sz(2, git_index_entrycount(write_index));
+
+ /* Persist the index changes to disk */
+ cl_git_pass(git_index_write(write_index));
+ cl_assert_equal_i(true, write_index->on_disk);
+
+ /* Sync the changes back into the read_index */
+ cl_assert_equal_sz(0, git_index_entrycount(read_index));
+
+ cl_git_pass(git_index_read(read_index, true));
+ cl_assert_equal_i(true, read_index->on_disk);
+
+ cl_assert_equal_sz(2, git_index_entrycount(read_index));
+
+ /* Remove the index file from the filesystem */
+ cl_git_pass(p_unlink(write_index->index_file_path));
+
+ /* Sync the changes back into the read_index */
+ cl_git_pass(git_index_read(read_index, true));
+ cl_assert_equal_i(false, read_index->on_disk);
+ cl_assert_equal_sz(0, git_index_entrycount(read_index));
+
+ git_index_free(read_index);
+ git_index_free(write_index);
+ git_repository_free(repo);
+}
+
+void test_index_tests256__reload_while_ignoring_case(void)
+{
+ git_index *index;
+ unsigned int caps;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+
+ caps = git_index_caps(index);
+ cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(git_index_get_bypath(index, "contrib/README", 0));
+ cl_assert_equal_p(NULL, git_index_get_bypath(index, "CONTRIB/readme", 0));
+
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(git_index_get_bypath(index, "contrib/README", 0));
+ cl_assert(git_index_get_bypath(index, "CONTRIB/readme", 0));
+
+ git_index_free(index);
+}
+
+void test_index_tests256__change_icase_on_instance(void)
+{
+ git_index *index;
+ unsigned int caps;
+ const git_index_entry *e;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+
+ caps = git_index_caps(index);
+ cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_assert_equal_i(false, index->ignore_case);
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(e = git_index_get_bypath(index, "contrib/README", 0));
+ cl_assert_equal_p(NULL, e = git_index_get_bypath(index, "CONTRIB/readme", 0));
+ cl_assert(e = git_index_get_bypath(index, "config.h", 0));
+ cl_assert_equal_p(NULL, e = git_index_get_bypath(index, "CONFIG.H", 0));
+
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_assert_equal_i(true, index->ignore_case);
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(e = git_index_get_bypath(index, "config.h", 0));
+ cl_assert_equal_s("config.h", e->path);
+ cl_assert(e = git_index_get_bypath(index, "CONFIG.H", 0));
+ cl_assert_equal_s("config.h", e->path);
+
+ git_index_free(index);
+}
+
+void test_index_tests256__can_lock_index(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_indexwriter one = GIT_INDEXWRITER_INIT,
+ two = GIT_INDEXWRITER_INIT;
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_indexwriter_init(&one, index));
+
+ cl_git_fail_with(GIT_ELOCKED, git_indexwriter_init(&two, index));
+ cl_git_fail_with(GIT_ELOCKED, git_index_write(index));
+
+ cl_git_pass(git_indexwriter_commit(&one));
+
+ cl_git_pass(git_index_write(index));
+
+ git_indexwriter_cleanup(&one);
+ git_indexwriter_cleanup(&two);
+ git_index_free(index);
+ cl_git_sandbox_cleanup();
+}
+
+void test_index_tests256__can_iterate(void)
+{
+ git_index *index;
+ git_index_iterator *iterator;
+ const git_index_entry *entry;
+ size_t i, iterator_idx = 0, found = 0;
+ int ret;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_index_iterator_new(&iterator, index));
+
+ cl_assert(git_vector_is_sorted(&iterator->snap));
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); i++) {
+ /* Advance iterator to next test entry index */
+ do {
+ ret = git_index_iterator_next(&entry, iterator);
+
+ if (ret == GIT_ITEROVER)
+ cl_fail("iterator did not contain all test entries");
+
+ cl_git_pass(ret);
+ } while (iterator_idx++ < test_entries[i].index);
+
+ cl_assert_equal_s(entry->path, test_entries[i].path);
+ cl_assert_equal_i(entry->mtime.seconds, test_entries[i].mtime);
+ cl_assert_equal_i(entry->file_size, test_entries[i].file_size);
+ found++;
+ }
+
+ while ((ret = git_index_iterator_next(&entry, iterator)) == 0)
+ ;
+
+ if (ret != GIT_ITEROVER)
+ cl_git_fail(ret);
+
+ cl_assert_equal_i(found, ARRAY_SIZE(test_entries));
+
+ git_index_iterator_free(iterator);
+ git_index_free(index);
+}
+
+void test_index_tests256__can_modify_while_iterating(void)
+{
+ git_index *index;
+ git_index_iterator *iterator;
+ const git_index_entry *entry;
+ git_index_entry new_entry = {{0}};
+ size_t expected = 0, seen = 0;
+ int ret;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_index_iterator_new(&iterator, index));
+
+ expected = git_index_entrycount(index);
+ cl_assert(git_vector_is_sorted(&iterator->snap));
+
+ /*
+ * After we've counted the entries, add a new one and change another;
+ * ensure that our iterator is backed by a snapshot and thus returns
+ * the number of entries from when the iterator was created.
+ */
+ cl_git_pass(git_oid__fromstr(&new_entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318a847f46cba7614cac9814291", GIT_OID_SHA256));
+ new_entry.path = "newfile";
+ new_entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(index, &new_entry));
+
+ cl_git_pass(git_oid__fromstr(&new_entry.id, "4141414141414141414141414141414141414141414141414141414141414141", GIT_OID_SHA256));
+ new_entry.path = "Makefile";
+ new_entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(index, &new_entry));
+
+ while (true) {
+ ret = git_index_iterator_next(&entry, iterator);
+
+ if (ret == GIT_ITEROVER)
+ break;
+
+ seen++;
+ }
+
+ cl_assert_equal_i(expected, seen);
+
+ git_index_iterator_free(iterator);
+ git_index_free(index);
+}
diff --git a/tests/libgit2/object/tree/update.c b/tests/libgit2/object/tree/update.c
index 1861ac838..1e82bdcd6 100644
--- a/tests/libgit2/object/tree/update.c
+++ b/tests/libgit2/object/tree/update.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "tree.h"
+#include "index.h"
static git_repository *g_repo;
@@ -28,7 +29,7 @@ void test_object_tree_update__remove_blob(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
@@ -57,7 +58,7 @@ void test_object_tree_update__remove_blob_deeper(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
@@ -88,7 +89,7 @@ void test_object_tree_update__remove_all_entries(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path1, 0));
cl_git_pass(git_index_remove(idx, path2, 0));
@@ -119,7 +120,7 @@ void test_object_tree_update__replace_blob(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
entry.path = path;
@@ -171,7 +172,7 @@ void test_object_tree_update__add_blobs(void)
int j;
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
base_tree = NULL;
if (i == 1) {
@@ -228,7 +229,7 @@ void test_object_tree_update__add_blobs_unsorted(void)
int j;
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
base_tree = NULL;
if (i == 1) {
diff --git a/tests/libgit2/repo/setters.c b/tests/libgit2/repo/setters.c
index 66ec7706c..5c91ed390 100644
--- a/tests/libgit2/repo/setters.c
+++ b/tests/libgit2/repo/setters.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
+#include "index.h"
#include "odb.h"
#include "posix.h"
#include "util.h"
@@ -70,7 +71,7 @@ void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_o
{
git_index *new_index;
- cl_git_pass(git_index_open(&new_index, "./my-index"));
+ cl_git_pass(git_index__open(&new_index, "./my-index", GIT_OID_SHA1));
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_repository_set_index(repo, new_index);
diff --git a/tests/libgit2/reset/hard.c b/tests/libgit2/reset/hard.c
index 0b6342cb2..06a8a049a 100644
--- a/tests/libgit2/reset/hard.c
+++ b/tests/libgit2/reset/hard.c
@@ -3,6 +3,7 @@
#include "reset_helpers.h"
#include "path.h"
#include "futils.h"
+#include "index.h"
static git_repository *repo;
static git_object *target;
@@ -252,7 +253,7 @@ void test_reset_hard__switch_file_to_dir(void)
git_odb_free(odb);
entry.mode = GIT_FILEMODE_BLOB;
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_signature_now(&sig, "foo", "bar"));
/* Create the old tree */
diff --git a/tests/libgit2/status/worktree_init.c b/tests/libgit2/status/worktree_init.c
index 40f1b2a31..db6e71f12 100644
--- a/tests/libgit2/status/worktree_init.c
+++ b/tests/libgit2/status/worktree_init.c
@@ -7,6 +7,7 @@
#include "posix.h"
#include "util.h"
#include "path.h"
+#include "index.h"
static void cleanup_new_repo(void *path)
{
@@ -65,7 +66,7 @@ void test_status_worktree_init__status_file_without_index_or_workdir(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_set_workdir(repo, "wd", false));
- cl_git_pass(git_index_open(&index, "empty-index"));
+ cl_git_pass(git_index__open(&index, "empty-index", GIT_OID_SHA1));
cl_assert_equal_i(0, (int)git_index_entrycount(index));
git_repository_set_index(repo, index);
@@ -106,7 +107,7 @@ void test_status_worktree_init__status_file_with_clean_index_and_empty_workdir(v
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_set_workdir(repo, "wd", false));
- cl_git_pass(git_index_open(&index, "my-index"));
+ cl_git_pass(git_index__open(&index, "my-index", GIT_OID_SHA1));
fill_index_wth_head_entries(repo, index);
git_repository_set_index(repo, index);
@@ -283,7 +284,7 @@ void test_status_worktree_init__disable_pathspec_match(void)
{
git_repository *repo;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
- char *file_with_bracket = "LICENSE[1].md",
+ char *file_with_bracket = "LICENSE[1].md",
*imaginary_file_with_bracket = "LICENSE[1-2].md";
cl_set_cleanup(&cleanup_new_repo, "pathspec");
@@ -291,18 +292,18 @@ void test_status_worktree_init__disable_pathspec_match(void)
cl_git_mkfile("pathspec/LICENSE[1].md", "screaming bracket\n");
cl_git_mkfile("pathspec/LICENSE1.md", "no bracket\n");
- opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
opts.pathspec.count = 1;
opts.pathspec.strings = &file_with_bracket;
cl_git_pass(
- git_status_foreach_ext(repo, &opts, cb_status__expected_path,
+ git_status_foreach_ext(repo, &opts, cb_status__expected_path,
file_with_bracket)
);
/* Test passing a pathspec matching files in the workdir. */
- /* Must not match because pathspecs are disabled. */
+ /* Must not match because pathspecs are disabled. */
opts.pathspec.strings = &imaginary_file_with_bracket;
cl_git_pass(
git_status_foreach_ext(repo, &opts, cb_status__expected_path, NULL)
diff --git a/tests/libgit2/submodule/lookup.c b/tests/libgit2/submodule/lookup.c
index acfdc838c..febb7dfad 100644
--- a/tests/libgit2/submodule/lookup.c
+++ b/tests/libgit2/submodule/lookup.c
@@ -3,6 +3,7 @@
#include "git2/sys/repository.h"
#include "repository.h"
#include "futils.h"
+#include "index.h"
static git_repository *g_repo = NULL;
@@ -210,7 +211,7 @@ void test_submodule_lookup__lookup_even_with_missing_index(void)
git_index *idx;
/* give the repo an empty index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
git_repository_set_index(g_repo, idx);
git_index_free(idx);
diff --git a/tests/resources/git-sha256.index b/tests/resources/git-sha256.index
new file mode 100644
index 000000000..84b5cabd9
--- /dev/null
+++ b/tests/resources/git-sha256.index
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/HEAD b/tests/resources/testrepo_256/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/resources/testrepo_256/.gitted/config b/tests/resources/testrepo_256/.gitted/config
new file mode 100644
index 000000000..ba975e1be
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/config
@@ -0,0 +1,15 @@
+[core]
+ repositoryformatversion = 1
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+ precomposeunicode = true
+[remote "origin"]
+ url = /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
+ fetch = +refs/heads/*:refs/remotes/origin/*
+[extensions]
+ objectformat = sha256
+[branch "master"]
+ remote = origin
+ merge = refs/heads/master
diff --git a/tests/resources/testrepo_256/.gitted/description b/tests/resources/testrepo_256/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests/resources/testrepo_256/.gitted/index b/tests/resources/testrepo_256/.gitted/index
new file mode 100644
index 000000000..6b18426ca
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/index
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/info/exclude b/tests/resources/testrepo_256/.gitted/info/exclude
new file mode 100644
index 000000000..a5196d1be
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests/resources/testrepo_256/.gitted/logs/HEAD b/tests/resources/testrepo_256/.gitted/logs/HEAD
new file mode 100644
index 000000000..359230302
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000000000000000000000000000 decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f Edward Thomson <ethomson@vercel.com> 1680595792 +0100 clone: from /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
diff --git a/tests/resources/testrepo_256/.gitted/logs/refs/heads/master b/tests/resources/testrepo_256/.gitted/logs/refs/heads/master
new file mode 100644
index 000000000..359230302
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000000000000000000000000000 decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f Edward Thomson <ethomson@vercel.com> 1680595792 +0100 clone: from /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
diff --git a/tests/resources/testrepo_256/.gitted/logs/refs/remotes/origin/HEAD b/tests/resources/testrepo_256/.gitted/logs/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..359230302
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/logs/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000000000000000000000000000 decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f Edward Thomson <ethomson@vercel.com> 1680595792 +0100 clone: from /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
diff --git a/tests/resources/testrepo_256/.gitted/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045 b/tests/resources/testrepo_256/.gitted/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045
new file mode 100644
index 000000000..8d8d1d8e8
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78 b/tests/resources/testrepo_256/.gitted/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78
new file mode 100644
index 000000000..c7fbd7e9e
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78
@@ -0,0 +1 @@
+x[N0 *t8Bq iP~Gg42zo /k^rfKFO%BI"NdwVeb8vb<\LB6k< UtŖ%Y#SC\c<5~7:<Ξ:n3&Wl7S>KktkҦ_ \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065b b/tests/resources/testrepo_256/.gitted/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065b
new file mode 100644
index 000000000..cdfafaca7
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065b
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750 b/tests/resources/testrepo_256/.gitted/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750
new file mode 100644
index 000000000..b135eccda
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f b/tests/resources/testrepo_256/.gitted/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f
new file mode 100644
index 000000000..58b2d0932
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f
@@ -0,0 +1 @@
+x ̱0 Ԟ#B k‘ j}(^rݫi3g _ܜ8H֍N] }P8Yo;o\Ww  \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498 b/tests/resources/testrepo_256/.gitted/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498
new file mode 100644
index 000000000..97157644b
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09e b/tests/resources/testrepo_256/.gitted/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09e
new file mode 100644
index 000000000..554d191b3
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09e
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24 b/tests/resources/testrepo_256/.gitted/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24
new file mode 100644
index 000000000..d5c518ecc
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61 b/tests/resources/testrepo_256/.gitted/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61
new file mode 100644
index 000000000..31aa9e5f5
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950a b/tests/resources/testrepo_256/.gitted/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950a
new file mode 100644
index 000000000..66dc15db4
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950a
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352a b/tests/resources/testrepo_256/.gitted/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352a
new file mode 100644
index 000000000..bee6a42d7
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352a
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2 b/tests/resources/testrepo_256/.gitted/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2
new file mode 100644
index 000000000..3dfd5463b
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8 b/tests/resources/testrepo_256/.gitted/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8
new file mode 100644
index 000000000..cedb2a22e
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b b/tests/resources/testrepo_256/.gitted/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b
new file mode 100644
index 000000000..3abc52f41
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b
@@ -0,0 +1 @@
+xM0a=\@3cWнi;-`, ooq~)氄W$E3ζB}#) -$ȄdI9Y;A\i,T{<kO+ -9|q2lT_ fl#:DUYf؍m4 \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60 b/tests/resources/testrepo_256/.gitted/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60
new file mode 100644
index 000000000..df40d99af
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869 b/tests/resources/testrepo_256/.gitted/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869
new file mode 100644
index 000000000..c05cacfed
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1 b/tests/resources/testrepo_256/.gitted/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1
new file mode 100644
index 000000000..1b299dc25
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b b/tests/resources/testrepo_256/.gitted/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b
new file mode 100644
index 000000000..2acf1b607
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b
@@ -0,0 +1 @@
+xQj!D) ڶ{m53Y((x8 2ր} KآZQsVP99GɧƑ} #y.&S.gMЂguHZ#Nx_51'0jRPrF~6N1'\7qˏ>!r`tZ֬t=?~V1fT \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 b/tests/resources/testrepo_256/.gitted/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813
new file mode 100644
index 000000000..711223894
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5 b/tests/resources/testrepo_256/.gitted/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5
new file mode 100644
index 000000000..d0d7e736e
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fd b/tests/resources/testrepo_256/.gitted/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fd
new file mode 100644
index 000000000..8dc193282
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fd
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9b b/tests/resources/testrepo_256/.gitted/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9b
new file mode 100644
index 000000000..dd9931316
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9b
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848 b/tests/resources/testrepo_256/.gitted/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848
new file mode 100644
index 000000000..39e27c06a
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848
@@ -0,0 +1 @@
+x1N1ERKPqx]#Sp'/}.ơj\1KRP8RDImP!D>p[ˡ0ൕD hSf !@-yZ S>\nS ]ɐClT[#GM|->~Sj־n^uGz?_zۛ.y,b0S ˤ/zQvYvɷ죛~/(jrS \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f b/tests/resources/testrepo_256/.gitted/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f
new file mode 100644
index 000000000..17fae64f4
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f
@@ -0,0 +1,3 @@
+xuKj1DS !'H.Og3
+96rݶ2>
+d=-b5싓dŕĄP(De{+6;>4KĆrLf &#9,o} >rޖ/N-\W<[`1hǣ =KݮZN/{"?7bW \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e b/tests/resources/testrepo_256/.gitted/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e
new file mode 100644
index 000000000..0bece845b
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3 b/tests/resources/testrepo_256/.gitted/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3
new file mode 100644
index 000000000..112998d42
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7 b/tests/resources/testrepo_256/.gitted/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7
new file mode 100644
index 000000000..860cad13c
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411ed b/tests/resources/testrepo_256/.gitted/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411ed
new file mode 100644
index 000000000..4c973ea83
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411ed
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6 b/tests/resources/testrepo_256/.gitted/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6
new file mode 100644
index 000000000..67b84c462
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f b/tests/resources/testrepo_256/.gitted/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f
new file mode 100644
index 000000000..993a62b16
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c b/tests/resources/testrepo_256/.gitted/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c
new file mode 100644
index 000000000..70bf64e16
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c
@@ -0,0 +1,2 @@
+xAj1 -i,B(](ti2 =~]znxe_ץf]b$a9)yI '2iYTU[fWVa5su,Q
+:POCp*)?~'x]6x˹\^žz٩<!ű;7:nu70oK_ gV \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa47 b/tests/resources/testrepo_256/.gitted/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa47
new file mode 100644
index 000000000..dec3810fa
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa47
@@ -0,0 +1 @@
+x+)JMU01c040031QrutueXha+|fb ei=^*GO \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf b/tests/resources/testrepo_256/.gitted/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf
new file mode 100644
index 000000000..e610e3be8
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724 b/tests/resources/testrepo_256/.gitted/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724
new file mode 100644
index 000000000..09d0abfa7
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724
@@ -0,0 +1 @@
+xQJ1 })zM<'HZ7mf`t}yN3?R6BYwJeHR(LḾӎA#8z āPԵ5d(:XH2t_7yۗ]O:grrBp{=Zk ?s?TU \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbe b/tests/resources/testrepo_256/.gitted/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbe
new file mode 100644
index 000000000..70431af81
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbe
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5 b/tests/resources/testrepo_256/.gitted/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5
new file mode 100644
index 000000000..41bcd18af
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045 b/tests/resources/testrepo_256/.gitted/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045
new file mode 100644
index 000000000..7ca4ceed5
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54 b/tests/resources/testrepo_256/.gitted/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54
new file mode 100644
index 000000000..6e585cdb2
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b b/tests/resources/testrepo_256/.gitted/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b
new file mode 100644
index 000000000..74b8385ed
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b
@@ -0,0 +1 @@
+x+)JMU0d040031Qrutue0~"tY2_,kx꺤tjsFO+L @!1A+@sJǍ>I]䜾W޵S&%%għeT0L;4q/M[:Ufk:< Pmy`&OwS_8oml PpTO \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95 b/tests/resources/testrepo_256/.gitted/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95
new file mode 100644
index 000000000..2419974cb
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640 b/tests/resources/testrepo_256/.gitted/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640
new file mode 100644
index 000000000..b390250e3
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5 b/tests/resources/testrepo_256/.gitted/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5
new file mode 100644
index 000000000..18a7f61c2
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebd b/tests/resources/testrepo_256/.gitted/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebd
new file mode 100644
index 000000000..d1c032fce
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebd
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d71827 b/tests/resources/testrepo_256/.gitted/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d71827
new file mode 100644
index 000000000..c6da2ff7a
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d71827
@@ -0,0 +1 @@
+xuQj1 DS)WB)e%^q0{0RK:8vO峵lee1rEOL0a8?ڙtBBG'Q**MYɟ'hYL\KN9H*x)a|Z^NpA46xKߡ%ȵ\=/[ϷϓzD7x-uWW \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890 b/tests/resources/testrepo_256/.gitted/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890
new file mode 100644
index 000000000..b1df3bdd5
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022 b/tests/resources/testrepo_256/.gitted/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022
new file mode 100644
index 000000000..3e36331ea
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23 b/tests/resources/testrepo_256/.gitted/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23
new file mode 100644
index 000000000..9bb5b623b
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19 b/tests/resources/testrepo_256/.gitted/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19
new file mode 100644
index 000000000..3cbf7e6b7
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5 b/tests/resources/testrepo_256/.gitted/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5
new file mode 100644
index 000000000..be8b99bba
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6 b/tests/resources/testrepo_256/.gitted/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6
new file mode 100644
index 000000000..9d2ceb1ff
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6
@@ -0,0 +1,2 @@
+x0D=+nbvK[Jb?x֥փ/I^ P1=%+X5IO6u =V*pD]hvG/H,o r1@eLp
+0s>?H!"s}t3,ͳIm3 \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269 b/tests/resources/testrepo_256/.gitted/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269
new file mode 100644
index 000000000..cfcdac306
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0 b/tests/resources/testrepo_256/.gitted/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0
new file mode 100644
index 000000000..77d9ec27d
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9f b/tests/resources/testrepo_256/.gitted/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9f
new file mode 100644
index 000000000..a67d6e647
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9f
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c0 b/tests/resources/testrepo_256/.gitted/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c0
new file mode 100644
index 000000000..ec37060e3
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c0
@@ -0,0 +1,3 @@
+xA
+0E]B$ x dH7xWÏ%޴*<Æ}qV ZFP'q/y(ٚQUx[%
+~8;*XИv`Qkm䯑:&O)Ip]%V Mkɰ./E \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca b/tests/resources/testrepo_256/.gitted/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca
new file mode 100644
index 000000000..6845087e5
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca
@@ -0,0 +1 @@
+x5j0 yPȎ(W#q4R_/=|Çd"MH="2ءFOs.K;%bsiw+VM^g656W[fa{]68I}"{yǬ "}-sߪw\.Zb=B \ No newline at end of file
diff --git a/tests/resources/testrepo_256/.gitted/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f b/tests/resources/testrepo_256/.gitted/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f
new file mode 100644
index 000000000..a53ab84cf
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1 b/tests/resources/testrepo_256/.gitted/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1
new file mode 100644
index 000000000..225c45734
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736 b/tests/resources/testrepo_256/.gitted/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736
new file mode 100644
index 000000000..58d51e502
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978 b/tests/resources/testrepo_256/.gitted/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978
new file mode 100644
index 000000000..04bf5eb06
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562 b/tests/resources/testrepo_256/.gitted/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562
new file mode 100644
index 000000000..37a289ecc
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idx b/tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idx
new file mode 100644
index 000000000..897e8a478
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idx
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.pack b/tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.pack
new file mode 100644
index 000000000..9c8557886
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.pack
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx b/tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx
new file mode 100644
index 000000000..9e2ec99c5
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.pack b/tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.pack
new file mode 100644
index 000000000..66cd292a2
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.pack
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idx b/tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idx
new file mode 100644
index 000000000..1d197e870
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idx
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.pack b/tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.pack
new file mode 100644
index 000000000..5b615e15c
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.pack
Binary files differ
diff --git a/tests/resources/testrepo_256/.gitted/packed-refs b/tests/resources/testrepo_256/.gitted/packed-refs
new file mode 100644
index 000000000..75626adfe
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/packed-refs
@@ -0,0 +1,27 @@
+# pack-refs with: peeled fully-peeled sorted
+a4813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95 refs/remotes/origin/br2
+a4813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95 refs/remotes/origin/cannot-fetch
+4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744 refs/remotes/origin/chomped
+7e9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c refs/remotes/origin/haacked
+decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f refs/remotes/origin/master
+decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f refs/remotes/origin/not-good
+66fe8385c6378bfa5ca5573bd0fdd773e4eadb0e86416b483f2c50c839859ecb refs/remotes/origin/packed
+43e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b refs/remotes/origin/packed-test
+0118010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78 refs/remotes/origin/subtrees
+4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744 refs/remotes/origin/test
+b83624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022 refs/remotes/origin/track-local
+4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744 refs/remotes/origin/trailing
+7e4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f refs/remotes/origin/with-empty-log
+d88b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca refs/tags/annotated_tag_to_blob
+^33e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8
+21e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61 refs/tags/e90810b
+^4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744
+34f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b refs/tags/hard_tag
+^decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f
+33e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8 refs/tags/point_to_blob
+14bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f refs/tags/taggerless
+^4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744
+c258f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6 refs/tags/test
+^4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744
+34f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b refs/tags/wrapped_tag
+^decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f
diff --git a/tests/resources/testrepo_256/.gitted/refs/heads/master b/tests/resources/testrepo_256/.gitted/refs/heads/master
new file mode 100644
index 000000000..106231c4c
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/refs/heads/master
@@ -0,0 +1 @@
+decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f
diff --git a/tests/resources/testrepo_256/.gitted/refs/remotes/origin/HEAD b/tests/resources/testrepo_256/.gitted/refs/remotes/origin/HEAD
new file mode 100644
index 000000000..6efe28fff
--- /dev/null
+++ b/tests/resources/testrepo_256/.gitted/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests/resources/testrepo_256/README b/tests/resources/testrepo_256/README
new file mode 100644
index 000000000..a8233120f
--- /dev/null
+++ b/tests/resources/testrepo_256/README
@@ -0,0 +1 @@
+hey there
diff --git a/tests/resources/testrepo_256/branch_file.txt b/tests/resources/testrepo_256/branch_file.txt
new file mode 100644
index 000000000..3697d64be
--- /dev/null
+++ b/tests/resources/testrepo_256/branch_file.txt
@@ -0,0 +1,2 @@
+hi
+bye!
diff --git a/tests/resources/testrepo_256/new.txt b/tests/resources/testrepo_256/new.txt
new file mode 100644
index 000000000..a71586c1d
--- /dev/null
+++ b/tests/resources/testrepo_256/new.txt
@@ -0,0 +1 @@
+my new file