diff options
author | Junio C Hamano <junkio@cox.net> | 2005-05-27 15:55:28 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-05-29 11:17:43 -0700 |
commit | 367cec1c024c3849cb32eaac15884a4adfefe1de (patch) | |
tree | ff5ff9663406484cfac8d6dee415971e62eba8ef /diffcore-pickaxe.c | |
parent | be020332a152ef95e0e8435fb69d8c02d5da29bb (diff) | |
download | git-367cec1c024c3849cb32eaac15884a4adfefe1de.tar.gz |
[PATCH] Add --pickaxe-all to diff-* brothers.
When --pickaxe-all is given in addition to -S, pickaxe shows the
entire diffs contained in the changeset, not just the diffs for
the filepair that touched the sought-after string. This is
useful to see the changes in context.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'diffcore-pickaxe.c')
-rw-r--r-- | diffcore-pickaxe.c | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index 491900929f..9cf3a50838 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -21,36 +21,73 @@ static int contains(struct diff_filespec *one, return 0; } -void diffcore_pickaxe(const char *needle) +void diffcore_pickaxe(const char *needle, int opts) { struct diff_queue_struct *q = &diff_queued_diff; unsigned long len = strlen(needle); - int i; + int i, has_changes; struct diff_queue_struct outq; outq.queue = NULL; outq.nr = outq.alloc = 0; - for (i = 0; i < q->nr; i++) { - struct diff_filepair *p = q->queue[i]; - int onum = outq.nr; - if (!DIFF_FILE_VALID(p->one)) { - if (!DIFF_FILE_VALID(p->two)) - continue; /* ignore nonsense */ - /* created */ - if (contains(p->two, needle, len)) - diff_q(&outq, p); + if (opts & DIFF_PICKAXE_ALL) { + /* Showing the whole changeset if needle exists */ + for (i = has_changes = 0; !has_changes && i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + if (!DIFF_FILE_VALID(p->one)) { + if (!DIFF_FILE_VALID(p->two)) + continue; /* ignore unmerged */ + /* created */ + if (contains(p->two, needle, len)) + has_changes++; + } + else if (!DIFF_FILE_VALID(p->two)) { + if (contains(p->one, needle, len)) + has_changes++; + } + else if (!diff_unmodified_pair(p) && + contains(p->one, needle, len) != + contains(p->two, needle, len)) + has_changes++; } - else if (!DIFF_FILE_VALID(p->two)) { - if (contains(p->one, needle, len)) + if (has_changes) + return; /* not munge the queue */ + + /* otherwise we will clear the whole queue + * by copying the empty outq at the end of this + * function, but first clear the current entries + * in the queue. + */ + for (i = 0; i < q->nr; i++) + diff_free_filepair(q->queue[i]); + } + else + /* Showing only the filepairs that has the needle */ + for (i = 0; i < q->nr; i++) { + struct diff_filepair *p = q->queue[i]; + has_changes = 0; + if (!DIFF_FILE_VALID(p->one)) { + if (!DIFF_FILE_VALID(p->two)) + ; /* ignore unmerged */ + /* created */ + else if (contains(p->two, needle, len)) + has_changes = 1; + } + else if (!DIFF_FILE_VALID(p->two)) { + if (contains(p->one, needle, len)) + has_changes = 1; + } + else if (!diff_unmodified_pair(p) && + contains(p->one, needle, len) != + contains(p->two, needle, len)) + has_changes = 1; + + if (has_changes) diff_q(&outq, p); + else + diff_free_filepair(p); } - else if (!diff_unmodified_pair(p) && - contains(p->one, needle, len) != - contains(p->two, needle, len)) - diff_q(&outq, p); - if (onum == outq.nr) - diff_free_filepair(p); - } + free(q->queue); *q = outq; return; |