From: Steven Grimm <koreth@midwinter.com>
To: git@vger.kernel.org
Subject: [PATCH v2] git-diff: Output a warning about stale files in the index
Date: Tue, 7 Aug 2007 00:17:12 -0700 [thread overview]
Message-ID: <20070807071712.GA32751@midwinter.com> (raw)
In-Reply-To: <7vbqdj9709.fsf@assigned-by-dhcp.cox.net>
Signed-off-by: Steven Grimm <koreth@midwinter.com>
---
Modified as suggested by Junio.
diff.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
diffcore.h | 1 +
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/diff.c b/diff.c
index a5fc56b..5f2e1fe 100644
--- a/diff.c
+++ b/diff.c
@@ -2979,7 +2979,7 @@ int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
free(q->queue);
q->queue = NULL;
- q->nr = q->alloc = 0;
+ q->nr = q->alloc = q->removed = 0;
return result;
}
@@ -3074,6 +3074,12 @@ void diff_flush(struct diff_options *options)
if (check_pair_status(p))
diff_flush_patch(p, options);
}
+
+ if (q->removed > 0) {
+ printf("Warning: %d %s touched but not modified. "
+ "Consider running git-status.\n",
+ q->removed, q->removed == 1 ? "path" : "paths");
+ }
}
if (output_format & DIFF_FORMAT_CALLBACK)
@@ -3084,7 +3090,7 @@ void diff_flush(struct diff_options *options)
free_queue:
free(q->queue);
q->queue = NULL;
- q->nr = q->alloc = 0;
+ q->nr = q->alloc = q->removed = 0;
}
static void diffcore_apply_filter(const char *filter)
@@ -3093,7 +3099,7 @@ static void diffcore_apply_filter(const char *filter)
struct diff_queue_struct *q = &diff_queued_diff;
struct diff_queue_struct outq;
outq.queue = NULL;
- outq.nr = outq.alloc = 0;
+ outq.nr = outq.alloc = outq.removed = 0;
if (!filter)
return;
@@ -3143,6 +3149,47 @@ static void diffcore_apply_filter(const char *filter)
*q = outq;
}
+static void diffcore_remove_empty(void)
+{
+ int i;
+ struct diff_queue_struct *q = &diff_queued_diff;
+ struct diff_queue_struct outq;
+ outq.queue = NULL;
+ outq.nr = outq.alloc = outq.removed = 0;
+
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+
+ /*
+ * 1. Keep the ones that cannot be diff-files
+ * "false" match that are only queued due to
+ * cache dirtyness.
+ *
+ * 2. Modified, same size and mode, and the object
+ * name of one side is unknown. If they do not
+ * have identical contents, keep them.
+ * They are different.
+ */
+ if ((p->status != DIFF_STATUS_MODIFIED) || /* (1) */
+ (p->one->sha1_valid && p->two->sha1_valid) ||
+ (p->one->mode != p->two->mode) ||
+
+ diff_populate_filespec(p->one, 1) || /* (2) */
+ diff_populate_filespec(p->two, 1) ||
+ (p->one->size != p->two->size) ||
+ diff_populate_filespec(p->one, 0) ||
+ diff_populate_filespec(p->two, 0) ||
+ memcmp(p->one->data, p->two->data, p->one->size))
+ diff_q(&outq, p);
+ else {
+ diff_free_filepair(p);
+ outq.removed++;
+ }
+ }
+ free(q->queue);
+ *q = outq;
+}
+
void diffcore_std(struct diff_options *options)
{
if (options->quiet)
@@ -3160,6 +3207,8 @@ void diffcore_std(struct diff_options *options)
diffcore_order(options->orderfile);
diff_resolve_rename_copy();
diffcore_apply_filter(options->filter);
+ if (options->output_format & DIFF_FORMAT_PATCH)
+ diffcore_remove_empty();
options->has_changes = !!diff_queued_diff.nr;
}
diff --git a/diffcore.h b/diffcore.h
index eef17c4..e5a9244 100644
--- a/diffcore.h
+++ b/diffcore.h
@@ -81,6 +81,7 @@ struct diff_queue_struct {
struct diff_filepair **queue;
int alloc;
int nr;
+ int removed;
};
extern struct diff_queue_struct diff_queued_diff;
--
1.5.3.rc2.4.g726f9
next prev parent reply other threads:[~2007-08-07 7:17 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-01 16:17 git-diff on touched files: bug or feature? Matthieu Moy
2007-08-01 17:26 ` Junio C Hamano
2007-08-01 19:02 ` Alexandre Julliard
2007-08-01 19:07 ` Junio C Hamano
2007-08-01 19:17 ` Alexandre Julliard
2007-08-02 9:23 ` Matthieu Moy
2007-08-02 9:51 ` Johannes Schindelin
2007-08-02 9:57 ` Matthieu Moy
2007-08-02 10:48 ` Johannes Schindelin
2007-08-02 14:04 ` Jean-François Veillette
2007-08-02 14:43 ` Johannes Schindelin
2007-08-02 15:10 ` Steven Grimm
2007-08-02 15:23 ` Johannes Schindelin
2007-08-02 15:45 ` Matthieu Moy
2007-08-02 17:58 ` J. Bruce Fields
2007-08-03 5:37 ` [PATCH] Add --show-touched option to show "diff --git" line when contents are unchanged Steven Grimm
2007-08-03 6:30 ` Junio C Hamano
2007-08-03 10:23 ` Johannes Schindelin
2007-08-03 20:33 ` Junio C Hamano
2007-08-03 21:32 ` Matthieu Moy
2007-08-03 21:50 ` Junio C Hamano
2007-08-03 23:01 ` Matthieu Moy
2007-08-03 23:36 ` Junio C Hamano
2007-08-05 19:42 ` Matthieu Moy
2007-08-05 19:45 ` Johannes Schindelin
2007-08-05 19:57 ` Matthieu Moy
2007-08-06 15:56 ` Matthias Lederhofer
2007-08-06 16:10 ` David Kastrup
2007-08-06 16:16 ` David Kastrup
2007-08-06 20:05 ` Matthieu Moy
2007-08-06 20:34 ` Junio C Hamano
2007-08-07 6:32 ` David Kastrup
2007-08-07 13:34 ` J. Bruce Fields
2007-08-07 4:22 ` Linus Torvalds
2007-08-07 4:37 ` Junio C Hamano
2007-08-07 6:41 ` David Kastrup
2007-08-08 3:07 ` Linus Torvalds
2007-08-08 3:44 ` Junio C Hamano
2007-08-08 8:26 ` Johannes Schindelin
2007-08-08 8:43 ` Junio C Hamano
2007-08-08 9:13 ` David Kastrup
2007-08-08 9:23 ` Johannes Schindelin
2007-08-08 9:58 ` Jakub Narebski
2007-08-07 5:56 ` Steven Grimm
2007-08-07 5:57 ` [PATCH] Add a note about the index being updated by git-status in some cases Steven Grimm
2007-08-07 6:35 ` [PATCH] git-diff: Output a warning about stale files in the index Steven Grimm
2007-08-07 6:46 ` Junio C Hamano
2007-08-07 7:17 ` Steven Grimm [this message]
2007-08-07 7:46 ` [PATCH v2] " Junio C Hamano
2007-08-07 7:51 ` Steven Grimm
2007-08-07 9:04 ` Jakub Narebski
2007-08-11 20:07 ` Junio C Hamano
2007-08-08 3:42 ` [PATCH] Add --show-touched option to show "diff --git" line when contents are unchanged Linus Torvalds
2007-08-07 6:39 ` Steven Grimm
2007-08-07 6:47 ` Matthieu Moy
2007-08-02 20:50 ` git-diff on touched files: bug or feature? Junio C Hamano
2007-08-02 9:54 ` Junio C Hamano
2007-08-02 10:01 ` Junio C Hamano
2007-08-02 12:08 ` Matthieu Moy
2007-08-02 12:21 ` Johannes Schindelin
2007-08-02 19:56 ` Junio C Hamano
2007-08-03 7:04 ` Jeff King
2007-08-03 7:59 ` Junio C Hamano
2007-08-03 8:24 ` Jeff King
2007-08-03 8:57 ` Junio C Hamano
2007-08-03 8:40 ` Shawn O. Pearce
2007-08-03 9:13 ` Junio C Hamano
2007-08-02 12:05 ` Matthieu Moy
2007-08-02 12:19 ` Johannes Schindelin
2007-08-02 12:26 ` Matthieu Moy
2007-08-02 14:39 ` Johannes Schindelin
2007-08-02 14:49 ` Matthieu Moy
2007-08-02 15:12 ` Johannes Schindelin
2007-08-02 13:25 ` Joel Reed
2007-08-02 15:05 ` Johannes Schindelin
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=20070807071712.GA32751@midwinter.com \
--to=koreth@midwinter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.