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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
| David Miller | Slow DOWN, please!!! |
| KAMEZAWA Hiroyuki | Re: 2.6.22-rc1-mm1 |
| Steven Rostedt | [RFC PATCH 1/3] Unified trace buffer |
| Steven Rostedt | [RFC PATCH 0/6] Convert all tasklets to workqueues |
git: | |
| Peter Klavins | Re: CRLF problems with Git on Win32 |
| J. Bruce Fields | Re: Git User's Survey 2007 unfinished summary continued |
| Linus Torvalds | Re: VCS comparison table |
| Junichi Uekawa | Re: [ANNOUNCE] GIT 1.5.4 |
| Arjan van de Ven | Re: [GIT]: Networking |
| Rémi | [PATCH 0/6] [RFC] Phonet pipes protocol (v2) |
| Jarek Poplawski | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| Jozsef Kadlecsik | Re: TCP connection stalls under 2.6.24.7 |
| Richard Stallman | Real men don't attack straw men |
| Rogier Krieger | Re: bcw(4) is gone |
| Leon Dippenaar | New tcp stack attack |
| Brandon Lee | DELL PERC 5iR slow performance |
| high memory | 6 hours ago | Linux kernel |
| semaphore access speed | 9 hours ago | Applications and Utilities |
| the kernel how to power off the machine | 10 hours ago | Linux kernel |
| Easter Eggs in windows XP | 12 hours ago | Windows |
| Shared swap partition | 13 hours ago | Linux general |
| Root password | 14 hours ago | Linux general |
| Where/when DNOTIFY is used? | 15 hours ago | Linux kernel |
| How to convert Linux Kernel built-in module into a loadable module | 18 hours ago | Linux kernel |
| Linux 2.6.24 and I/O schedulers | 18 hours ago | Linux kernel |
| USB Driver -- Interrupt Polling -- A Little Help Please | 1 day ago | Linux general |
