Skip to content

Commit 523f893

Browse files
committed
index: add sha256 support
1 parent c616ba2 commit 523f893

File tree

106 files changed

+1704
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1704
-204
lines changed

examples/show-index.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ int lg2_show_index(git_repository *repo, int argc, char **argv)
3030

3131
dirlen = strlen(dir);
3232
if (dirlen > 5 && strcmp(dir + dirlen - 5, "index") == 0) {
33+
#ifdef GIT_EXPERIMENTAL_SHA256
34+
check_lg2(git_index_open(&index, dir, GIT_OID_SHA1), "could not open index", dir);
35+
#else
3336
check_lg2(git_index_open(&index, dir), "could not open index", dir);
37+
#endif
3438
} else {
3539
check_lg2(git_repository_open_ext(&repo, dir, 0, NULL), "could not open repository", dir);
3640
check_lg2(git_repository_index(&index, repo), "could not open repository index", NULL);

include/git2/index.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ typedef enum {
184184
* @param index_path the path to the index file in disk
185185
* @return 0 or an error code
186186
*/
187+
188+
#ifdef GIT_EXPERIMENTAL_SHA256
189+
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path, git_oid_t oid_type);
190+
#else
187191
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
192+
#endif
188193

189194
/**
190195
* Create an in-memory index object.
@@ -197,7 +202,11 @@ GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
197202
* @param out the pointer for the new index
198203
* @return 0 or an error code
199204
*/
205+
#ifdef GIT_EXPERIMENTAL_SHA256
206+
GIT_EXTERN(int) git_index_new(git_index **out, git_oid_t oid_type);
207+
#else
200208
GIT_EXTERN(int) git_index_new(git_index **out);
209+
#endif
201210

202211
/**
203212
* Free an existing index object.

src/libgit2/apply.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "zstream.h"
2020
#include "reader.h"
2121
#include "index.h"
22+
#include "repository.h"
2223
#include "apply.h"
2324

2425
typedef struct {
@@ -644,7 +645,7 @@ int git_apply_to_tree(
644645
* put the current tree into the postimage as-is - the diff will
645646
* replace any entries contained therein
646647
*/
647-
if ((error = git_index_new(&postimage)) < 0 ||
648+
if ((error = git_index__new(&postimage, repo->oid_type)) < 0 ||
648649
(error = git_index_read_tree(postimage, preimage)) < 0 ||
649650
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
650651
goto done;
@@ -851,8 +852,8 @@ int git_apply(
851852
* having the full repo index, so we will limit our checkout
852853
* to only write these files that were affected by the diff.
853854
*/
854-
if ((error = git_index_new(&preimage)) < 0 ||
855-
(error = git_index_new(&postimage)) < 0 ||
855+
if ((error = git_index__new(&preimage, repo->oid_type)) < 0 ||
856+
(error = git_index__new(&postimage, repo->oid_type)) < 0 ||
856857
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
857858
goto done;
858859

0 commit comments

Comments
 (0)