summaryrefslogtreecommitdiff
path: root/add-patch.c
diff options
context:
space:
mode:
Diffstat (limited to 'add-patch.c')
-rw-r--r--add-patch.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/add-patch.c b/add-patch.c
index 1eb0ab97bb..2c46fe5b33 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -44,7 +44,7 @@ struct add_p_state {
struct hunk head;
struct hunk *hunk;
size_t hunk_nr, hunk_alloc;
- unsigned deleted:1, mode_change:1;
+ unsigned deleted:1, mode_change:1,binary:1;
} *file_diff;
size_t file_diff_nr;
};
@@ -294,7 +294,9 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
BUG("'new mode' does not immediately follow "
"'old mode'?\n\n%.*s",
(int)(eol - plain->buf), plain->buf);
- }
+ } else if (hunk == &file_diff->head &&
+ starts_with(p, "Binary files "))
+ file_diff->binary = 1;
if (file_diff->deleted && file_diff->mode_change)
BUG("diff contains delete *and* a mode change?!?\n%.*s",
@@ -1304,7 +1306,7 @@ int run_add_p(struct repository *r, const struct pathspec *ps)
struct add_p_state s = {
{ r }, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT
};
- size_t i;
+ size_t i, binary_count = 0;
init_add_i_state(&s.s, r);
@@ -1318,9 +1320,16 @@ int run_add_p(struct repository *r, const struct pathspec *ps)
}
for (i = 0; i < s.file_diff_nr; i++)
- if (patch_update_file(&s, s.file_diff + i))
+ if (s.file_diff[i].binary && !s.file_diff[i].hunk_nr)
+ binary_count++;
+ else if (patch_update_file(&s, s.file_diff + i))
break;
+ if (s.file_diff_nr == 0)
+ fprintf(stderr, _("No changes.\n"));
+ else if (binary_count == s.file_diff_nr)
+ fprintf(stderr, _("Only binary files changed.\n"));
+
strbuf_release(&s.answer);
strbuf_release(&s.buf);
strbuf_release(&s.plain);