git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/4] make filepairs detachable
@ 2006-06-30  0:27 Alex Riesen
  2006-06-30  1:16 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Riesen @ 2006-06-30  0:27 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Junio C Hamano

Actually, just make sure diff_flush does not crash for diff queue
entries which were cleared.

---
 diff.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/diff.c b/diff.c
index 5a71489..b3480f6 100644
--- a/diff.c
+++ b/diff.c
@@ -2281,6 +2281,8 @@ void diff_flush(struct diff_options *opt
 	}
 	for (i = 0; i < q->nr; i++) {
 		struct diff_filepair *p = q->queue[i];
+		if (!p)
+			continue;
 		flush_one_pair(p, diff_output_format, options, diffstat);
 	}
 
@@ -2290,6 +2292,8 @@ void diff_flush(struct diff_options *opt
 	}
 
 	for (i = 0; i < q->nr; i++) {
+		if (!q->queue[i])
+		    continue;
 		if (diffstat && options->summary)
 			diff_summary(q->queue[i]);
 		diff_free_filepair(q->queue[i]);
-- 
1.4.1.rc1.g17dc

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/4] make filepairs detachable
  2006-06-30  0:27 [PATCH 2/4] make filepairs detachable Alex Riesen
@ 2006-06-30  1:16 ` Junio C Hamano
  2006-06-30  7:42   ` Alex Riesen
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2006-06-30  1:16 UTC (permalink / raw)
  To: Alex Riesen; +Cc: git, Johannes Schindelin

fork0@t-online.de (Alex Riesen) writes:

> Actually, just make sure diff_flush does not crash for diff queue
> entries which were cleared.

Somehow I really feel uneasy about this one.  I think it is the
responsibility of the one who mangles the queue to adjust the
entries and count consistent.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/4] make filepairs detachable
  2006-06-30  1:16 ` Junio C Hamano
@ 2006-06-30  7:42   ` Alex Riesen
  2006-06-30  7:50     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Riesen @ 2006-06-30  7:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Alex Riesen, git, Johannes Schindelin

On 6/30/06, Junio C Hamano <junkio@cox.net> wrote:
>
> > Actually, just make sure diff_flush does not crash for diff queue
> > entries which were cleared.
>
> Somehow I really feel uneasy about this one.  I think it is the
> responsibility of the one who mangles the queue to adjust the
> entries and count consistent.
>

That's what I get after being exposed to double-linked lists for
too long: I begin to think it's fine to take whatever I want.
The pairs are actually exactly what I need, so I take them.
I think I just have to encapsulate it nicely, i.e.:

    struct diff_filepair *diff_queued_detach(int pos)
    {
        struct diff_filepair *pair = NULL;
        if (pos < diff_queued_diff.nr) {
            diff_queued_diff.queue[pos];
            if (diff_queued_diff.nr - pos > 1)
                memmove(pair->queue + pos, pair->queue + pos + 1,
                        diff_queued_diff.nr - pos - 1);
            diff_queued_diff.nr--;
        }
        return pair;
    }

BTW, is there any chance we get the struct diff_filepair's
double-linked? They don't seem to be sorted. Will increase
the memory footprint, though.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/4] make filepairs detachable
  2006-06-30  7:42   ` Alex Riesen
@ 2006-06-30  7:50     ` Junio C Hamano
  2006-06-30  8:21       ` Alex Riesen
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2006-06-30  7:50 UTC (permalink / raw)
  To: Alex Riesen; +Cc: git

"Alex Riesen" <raa.lkml@gmail.com> writes:

> BTW, is there any chance we get the struct diff_filepair's
> double-linked? They don't seem to be sorted. Will increase
> the memory footprint, though.

You do not necessarily have to do things in place.  In fact, all
of the standard diffcore transformers create a new queue, read
from the old queue and place the filtered or munged result in
the new queue, swap the global queued_diff variable to point at
the new one and discard the old queue.

See diff.c::diffcore_apply_filter() for the simplest example.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/4] make filepairs detachable
  2006-06-30  7:50     ` Junio C Hamano
@ 2006-06-30  8:21       ` Alex Riesen
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Riesen @ 2006-06-30  8:21 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On 6/30/06, Junio C Hamano <junkio@cox.net> wrote:
>
> > BTW, is there any chance we get the struct diff_filepair's
> > double-linked? They don't seem to be sorted. Will increase
> > the memory footprint, though.
>
> You do not necessarily have to do things in place.  In fact, all
> of the standard diffcore transformers create a new queue, read
> from the old queue and place the filtered or munged result in
> the new queue, swap the global queued_diff variable to point at
> the new one and discard the old queue.
>
> See diff.c::diffcore_apply_filter() for the simplest example.
>

I see. Looks dangerous outside of diff.c though.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-06-30  8:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-30  0:27 [PATCH 2/4] make filepairs detachable Alex Riesen
2006-06-30  1:16 ` Junio C Hamano
2006-06-30  7:42   ` Alex Riesen
2006-06-30  7:50     ` Junio C Hamano
2006-06-30  8:21       ` Alex Riesen

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).