From: Imre Deak <imre.deak@gmail.com>
To: git@vger.kernel.org
Cc: imre.deak@gmail.com
Subject: [PATCH] builtin-apply: check for empty files when detecting creation patch
Date: Thu, 8 May 2008 17:39:39 +0300 [thread overview]
Message-ID: <1210257579-30975-1-git-send-email-imre.deak@gmail.com> (raw)
When we can only guess if we have a creation patch, we do
this by treating the patch as such if there weren't any old
lines. Zero length files can be patched without old lines
though, so do an extra check for file size.
Signed-off-by: Imre Deak <imre.deak@gmail.com>
---
builtin-apply.c | 34 +++++++++++++++++++++++++++++++++-
1 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index caa3f2a..80d0779 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1096,6 +1096,33 @@ static int parse_fragment(char *line, unsigned long size,
return offset;
}
+static size_t existing_file_size(const char *file)
+{
+ size_t st_size = -1;
+
+ if (file == NULL)
+ return -1;
+
+ if (cached) {
+ struct cache_entry *ce;
+ int pos;
+
+ pos = cache_name_pos(file, strlen(file));
+ if (pos < 0)
+ return -1;
+ ce = active_cache[pos];
+ st_size = ntohl(ce->ce_size);
+ } else {
+ struct stat st;
+
+ if (lstat(file, &st) < 0)
+ return -1;
+ st_size = st.st_size;
+ }
+
+ return st_size;
+}
+
static int parse_single_patch(char *line, unsigned long size, struct patch *patch)
{
unsigned long offset = 0;
@@ -1143,13 +1170,18 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc
if (patch->is_delete < 0 &&
(newlines || (patch->fragments && patch->fragments->next)))
patch->is_delete = 0;
+ /* FIXME: How can be there context if it's a creation / deletion? */
if (!unidiff_zero || context) {
/* If the user says the patch is not generated with
* --unified=0, or if we have seen context lines,
* then not having oldlines means the patch is creation,
* and not having newlines means the patch is deletion.
+ *
+ * It's also possible that a zero length file is added
+ * to.
*/
- if (patch->is_new < 0 && !oldlines) {
+ if (patch->is_new < 0 && !oldlines &&
+ existing_file_size(patch->old_name) != 0) {
patch->is_new = 1;
patch->old_name = NULL;
}
--
1.5.4.2.dirty
next reply other threads:[~2008-05-08 14:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-08 14:39 Imre Deak [this message]
2008-05-11 2:36 ` [PATCH] builtin-apply: check for empty files when detecting creation patch Junio C Hamano
2008-05-13 20:16 ` Imre Deak
2008-05-13 21:48 ` Junio C Hamano
2008-05-13 22:24 ` Linus Torvalds
2008-05-13 22:34 ` Junio C Hamano
2008-05-13 22:58 ` Linus Torvalds
2008-05-14 0:13 ` Junio C Hamano
2008-05-14 1:14 ` Linus Torvalds
2008-05-17 9:12 ` Junio C Hamano
2008-05-17 9:18 ` [PATCH 1/2] builtin-apply: accept patch to an empty file Junio C Hamano
2008-05-17 9:19 ` [PATCH 2/2] builtin-apply: do not declare patch is creation when we do not know it Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1210257579-30975-1-git-send-email-imre.deak@gmail.com \
--to=imre.deak@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).