summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/diff_print.c23
-rw-r--r--src/patch_parse.c4
2 files changed, 25 insertions, 2 deletions
diff --git a/src/diff_print.c b/src/diff_print.c
index 29ffcdd51..59f751cc2 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -322,6 +322,26 @@ static int diff_delta_format_with_paths(
return git_buf_printf(out, template, oldpfx, oldpath, newpfx, newpath);
}
+int diff_delta_format_rename_header(
+ git_buf *out,
+ const git_diff_delta *delta)
+{
+ if (delta->similarity > 100) {
+ giterr_set(GITERR_PATCH, "invalid similarity %d", delta->similarity);
+ return -1;
+ }
+
+ git_buf_printf(out,
+ "similarity index %d%%\n"
+ "rename from %s\n"
+ "rename to %s\n",
+ delta->similarity,
+ delta->old_file.path,
+ delta->new_file.path);
+
+ return git_buf_oom(out) ? -1 : 0;
+}
+
int git_diff_delta__format_file_header(
git_buf *out,
const git_diff_delta *delta,
@@ -341,6 +361,9 @@ int git_diff_delta__format_file_header(
git_buf_printf(out, "diff --git %s%s %s%s\n",
oldpfx, delta->old_file.path, newpfx, delta->new_file.path);
+ if (delta->status == GIT_DELTA_RENAMED)
+ GITERR_CHECK_ERROR(diff_delta_format_rename_header(out, delta));
+
GITERR_CHECK_ERROR(diff_print_oid_range(out, delta, oid_strlen));
if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0)
diff --git a/src/patch_parse.c b/src/patch_parse.c
index df2492ee5..aa767f3b9 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -306,7 +306,7 @@ static int parse_header_rename(
static int parse_header_renamefrom(
git_patch_parsed *patch, patch_parse_ctx *ctx)
{
- patch->base.delta->status |= GIT_DELTA_RENAMED;
+ patch->base.delta->status = GIT_DELTA_RENAMED;
return parse_header_rename(
(char **)&patch->base.delta->old_file.path,
@@ -317,7 +317,7 @@ static int parse_header_renamefrom(
static int parse_header_renameto(
git_patch_parsed *patch, patch_parse_ctx *ctx)
{
- patch->base.delta->status |= GIT_DELTA_RENAMED;
+ patch->base.delta->status = GIT_DELTA_RENAMED;
return parse_header_rename(
(char **)&patch->base.delta->new_file.path,