summaryrefslogtreecommitdiff
path: root/src/diff_print.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-09-22 18:25:03 -0400
committerEdward Thomson <ethomson@github.com>2016-05-26 13:01:05 -0500
commitd68cb736776e0f2f9494b49e2da30a9c4b9fc2c7 (patch)
treed8b8b7bffac2560bae167cb02dd3da8131e40d1e /src/diff_print.c
parente7ec327d4b94d8237f6238fb3d282bd3434b2b56 (diff)
downloadlibgit2-d68cb736776e0f2f9494b49e2da30a9c4b9fc2c7.tar.gz
diff: include oid length in deltas
Now that `git_diff_delta` data can be produced by reading patch file data, which may have an abbreviated oid, allow consumers to know that the id is abbreviated.
Diffstat (limited to 'src/diff_print.c')
-rw-r--r--src/diff_print.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/diff_print.c b/src/diff_print.c
index 09bf77aef..7c9af2449 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -208,6 +208,7 @@ static int diff_print_one_raw(
{
diff_print_info *pi = data;
git_buf *out = pi->buf;
+ int id_abbrev;
char code = git_diff_status_char(delta->status);
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
@@ -218,6 +219,16 @@ static int diff_print_one_raw(
git_buf_clear(out);
+ id_abbrev = delta->old_file.mode ? delta->old_file.id_abbrev :
+ delta->new_file.id_abbrev;
+
+ if (pi->oid_strlen - 1 > id_abbrev) {
+ giterr_set(GITERR_PATCH,
+ "The patch input contains %d id characters (cannot print %d)",
+ id_abbrev, pi->oid_strlen);
+ return -1;
+ }
+
git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.id);
git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.id);
@@ -252,6 +263,22 @@ static int diff_print_oid_range(
{
char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];
+ if (delta->old_file.mode &&
+ oid_strlen - 1 > delta->old_file.id_abbrev) {
+ giterr_set(GITERR_PATCH,
+ "The patch input contains %d id characters (cannot print %d)",
+ delta->old_file.id_abbrev, oid_strlen);
+ return -1;
+ }
+
+ if ((delta->new_file.mode &&
+ oid_strlen - 1 > delta->new_file.id_abbrev)) {
+ giterr_set(GITERR_PATCH,
+ "The patch input contains %d id characters (cannot print %d)",
+ delta->new_file.id_abbrev, oid_strlen);
+ return -1;
+ }
+
git_oid_tostr(start_oid, oid_strlen, &delta->old_file.id);
git_oid_tostr(end_oid, oid_strlen, &delta->new_file.id);