Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Thu, 23 Jul 2009 04:56:46 +0000 (21:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Jul 2009 04:56:46 +0000 (21:56 -0700)
* maint:
Trailing whitespace and no newline fix
diff --cc: a lost line at the beginning of the file is shown incorrectly
combine-diff.c: fix performance problem when folding common deleted lines

1  2 
combine-diff.c
diff --combined combine-diff.c
index bbf74fc42e4e72eb3df99272fb75a03bbeaf726a,1a6f9d1df5b7dcafbdaa2d64c45554e129972be2..5b63af1eeb71907f23117bc552fa7a4019f09722
@@@ -80,6 -80,7 +80,7 @@@ struct lline 
  /* Lines surviving in the merge result */
  struct sline {
        struct lline *lost_head, **lost_tail;
+       struct lline *next_lost;
        char *bol;
        int len;
        /* bit 0 up to (N-1) are on if the parent has this line (i.e.
@@@ -121,18 -122,12 +122,12 @@@ static void append_lost(struct sline *s
  
        /* Check to see if we can squash things */
        if (sline->lost_head) {
-               struct lline *last_one = NULL;
-               /* We cannot squash it with earlier one */
-               for (lline = sline->lost_head;
-                    lline;
-                    lline = lline->next)
-                       if (lline->parent_map & this_mask)
-                               last_one = lline;
-               lline = last_one ? last_one->next : sline->lost_head;
+               lline = sline->next_lost;
                while (lline) {
                        if (lline->len == len &&
                            !memcmp(lline->line, line, len)) {
                                lline->parent_map |= this_mask;
+                               sline->next_lost = lline->next;
                                return;
                        }
                        lline = lline->next;
        lline->line[len] = 0;
        *sline->lost_tail = lline;
        sline->lost_tail = &lline->next;
+       sline->next_lost = NULL;
  }
  
  struct combine_diff_state {
@@@ -168,25 -164,28 +164,28 @@@ static void consume_line(void *state_, 
                                      &state->nb, &state->nn))
                        return;
                state->lno = state->nb;
-               if (!state->nb)
-                       /* @@ -1,2 +0,0 @@ to remove the
-                        * first two lines...
-                        */
-                       state->nb = 1;
-               if (state->nn == 0)
+               if (state->nn == 0) {
                        /* @@ -X,Y +N,0 @@ removed Y lines
                         * that would have come *after* line N
                         * in the result.  Our lost buckets hang
                         * to the line after the removed lines,
+                        *
+                        * Note that this is correct even when N == 0,
+                        * in which case the hunk removes the first
+                        * line in the file.
                         */
                        state->lost_bucket = &state->sline[state->nb];
-               else
+                       if (!state->nb)
+                               state->nb = 1;
+               } else {
                        state->lost_bucket = &state->sline[state->nb-1];
+               }
                if (!state->sline[state->nb-1].p_lno)
                        state->sline[state->nb-1].p_lno =
                                xcalloc(state->num_parent,
                                        sizeof(unsigned long));
                state->sline[state->nb-1].p_lno[state->n] = state->ob;
+               state->lost_bucket->next_lost = state->lost_bucket->lost_head;
                return;
        }
        if (!state->lost_bucket)
@@@ -746,7 -745,7 +745,7 @@@ static void show_patch_diff(struct comb
  
                        done = read_in_full(fd, result, len);
                        if (done < 0)
 -                              die("read error '%s'", elem->path);
 +                              die_errno("read error '%s'", elem->path);
                        else if (done < len)
                                die("early EOF '%s'", elem->path);