summaryrefslogtreecommitdiff
path: root/src/libgit2/diff_generate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libgit2/diff_generate.c')
-rw-r--r--src/libgit2/diff_generate.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/libgit2/diff_generate.c b/src/libgit2/diff_generate.c
index a88ce8c32..78fe510e7 100644
--- a/src/libgit2/diff_generate.c
+++ b/src/libgit2/diff_generate.c
@@ -61,8 +61,8 @@ static git_diff_delta *diff_delta__alloc(
}
delta->status = status;
- git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
- git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
+ git_oid_clear(&delta->old_file.id, diff->base.opts.oid_type);
+ git_oid_clear(&delta->new_file.id, diff->base.opts.oid_type);
return delta;
}
@@ -149,10 +149,13 @@ static int diff_delta__from_one(
const git_index_entry *entry = nitem;
bool has_old = false;
git_diff_delta *delta;
+ git_oid_t oid_type;
const char *matched_pathspec;
GIT_ASSERT_ARG((oitem != NULL) ^ (nitem != NULL));
+ oid_type = diff->base.opts.oid_type;
+
if (oitem) {
entry = oitem;
has_old = true;
@@ -186,20 +189,23 @@ static int diff_delta__from_one(
GIT_ASSERT(status != GIT_DELTA_MODIFIED);
delta->nfiles = 1;
+ git_oid_clear(&delta->old_file.id, diff->base.opts.oid_type);
+ git_oid_clear(&delta->new_file.id, diff->base.opts.oid_type);
+
if (has_old) {
delta->old_file.mode = entry->mode;
delta->old_file.size = entry->file_size;
delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
git_oid_cpy(&delta->old_file.id, &entry->id);
- git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
- delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
+ git_oid_clear(&delta->new_file.id, oid_type);
+ delta->old_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
} else /* ADDED, IGNORED, UNTRACKED */ {
delta->new_file.mode = entry->mode;
delta->new_file.size = entry->file_size;
delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS;
- git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
+ git_oid_clear(&delta->old_file.id, oid_type);
git_oid_cpy(&delta->new_file.id, &entry->id);
- delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
+ delta->new_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
}
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
@@ -225,6 +231,9 @@ static int diff_delta__from_two(
const git_oid *old_id = &old_entry->id;
git_diff_delta *delta;
const char *canonical_path = old_entry->path;
+ git_oid_t oid_type;
+
+ oid_type = diff->base.opts.oid_type;
if (status == GIT_DELTA_UNMODIFIED &&
DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNMODIFIED))
@@ -254,14 +263,14 @@ static int diff_delta__from_two(
delta->old_file.size = old_entry->file_size;
delta->old_file.mode = old_mode;
git_oid_cpy(&delta->old_file.id, old_id);
- delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
+ delta->old_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID |
GIT_DIFF_FLAG_EXISTS;
}
if (!git_index_entry_is_conflict(new_entry)) {
git_oid_cpy(&delta->new_file.id, new_id);
- delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE;
+ delta->new_file.id_abbrev = (uint16_t)git_oid_hexsize(oid_type);
delta->new_file.size = new_entry->file_size;
delta->new_file.mode = new_mode;
delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS;
@@ -490,6 +499,14 @@ static int diff_generated_apply_options(
return -1;
}
+ if (!diff->base.opts.oid_type) {
+ diff->base.opts.oid_type = repo->oid_type;
+ } else if (diff->base.opts.oid_type != repo->oid_type) {
+ git_error_set(GIT_ERROR_INVALID,
+ "specified object ID type does not match repository object ID type");
+ return -1;
+ }
+
/* flag INCLUDE_TYPECHANGE_TREES implies INCLUDE_TYPECHANGE */
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES))
diff->base.opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE;
@@ -603,7 +620,7 @@ int git_diff__oid_for_file(
entry.mode = mode;
entry.file_size = (uint32_t)size;
entry.path = (char *)path;
- git_oid_clear(&entry.id, GIT_OID_SHA1);
+ git_oid_clear(&entry.id, diff->opts.oid_type);
return git_diff__oid_for_entry(out, diff, &entry, mode, NULL);
}
@@ -624,7 +641,7 @@ int git_diff__oid_for_entry(
GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED);
diff = (git_diff_generated *)d;
- git_oid_clear(out, GIT_OID_SHA1);
+ git_oid_clear(out, diff->base.opts.oid_type);
if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0)
return -1;
@@ -660,7 +677,8 @@ int git_diff__oid_for_entry(
git_error_clear();
}
} else if (S_ISLNK(mode)) {
- error = git_odb__hashlink(out, full_path.ptr, GIT_OID_SHA1);
+ error = git_odb__hashlink(out, full_path.ptr,
+ diff->base.opts.oid_type);
diff->base.perf.oid_calculations++;
} else if (!git__is_sizet(entry.file_size)) {
git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'",
@@ -676,7 +694,8 @@ int git_diff__oid_for_entry(
else {
error = git_odb__hashfd_filtered(
out, fd, (size_t)entry.file_size,
- GIT_OBJECT_BLOB, GIT_OID_SHA1, fl);
+ GIT_OBJECT_BLOB, diff->base.opts.oid_type,
+ fl);
p_close(fd);
diff->base.perf.oid_calculations++;
}
@@ -785,7 +804,7 @@ static int maybe_modified(
git_diff_generated *diff,
diff_in_progress *info)
{
- git_oid noid = GIT_OID_SHA1_ZERO;
+ git_oid noid;
git_delta_t status = GIT_DELTA_MODIFIED;
const git_index_entry *oitem = info->oitem;
const git_index_entry *nitem = info->nitem;
@@ -796,6 +815,8 @@ static int maybe_modified(
const char *matched_pathspec;
int error = 0;
+ git_oid_clear(&noid, diff->base.opts.oid_type);
+
if (!diff_pathspec_match(&matched_pathspec, diff, oitem))
return 0;
@@ -1700,11 +1721,11 @@ int git_diff__commit(
*out = NULL;
if ((parents = git_commit_parentcount(commit)) > 1) {
- char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1];
+ char commit_oidstr[GIT_OID_MAX_HEXSIZE + 1];
error = -1;
git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit",
- git_oid_tostr(commit_oidstr, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(commit)));
+ git_oid_tostr(commit_oidstr, GIT_OID_MAX_HEXSIZE + 1, git_commit_id(commit)));
goto on_error;
}