Code

Merge branch 'rs/optim-text-wrap' into maint-1.6.6
authorJunio C Hamano <gitster@pobox.com>
Sun, 7 Mar 2010 22:53:45 +0000 (14:53 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 7 Mar 2010 22:53:45 +0000 (14:53 -0800)
* rs/optim-text-wrap:
  utf8.c: speculatively assume utf-8 in strbuf_add_wrapped_text()
  utf8.c: remove strbuf_write()
  utf8.c: remove print_spaces()
  utf8.c: remove print_wrapped_text()

1  2 
builtin-shortlog.c

diff --combined builtin-shortlog.c
index b3b055f68ce59b6b91ef6949bd8c4bd0bed68b55,d96858f9adcf185e65d6028634bd981430a0f193..ecd2d45a00b1aacf9d3a19e2f934a14ca7e58c35
@@@ -139,12 -139,8 +139,12 @@@ static void read_from_stdin(struct shor
  void shortlog_add_commit(struct shortlog *log, struct commit *commit)
  {
        const char *author = NULL, *buffer;
 +      struct strbuf buf = STRBUF_INIT;
 +      struct strbuf ufbuf = STRBUF_INIT;
 +      struct pretty_print_context ctx = {0};
  
 -      buffer = commit->buffer;
 +      pretty_print_commit(CMIT_FMT_RAW, commit, &buf, &ctx);
 +      buffer = buf.buf;
        while (*buffer && *buffer != '\n') {
                const char *eol = strchr(buffer, '\n');
  
                die("Missing author: %s",
                    sha1_to_hex(commit->object.sha1));
        if (log->user_format) {
 -              struct strbuf buf = STRBUF_INIT;
                struct pretty_print_context ctx = {0};
                ctx.abbrev = DEFAULT_ABBREV;
                ctx.subject = "";
                ctx.after_subject = "";
                ctx.date_mode = DATE_NORMAL;
 -              pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &buf, &ctx);
 -              insert_one_record(log, author, buf.buf);
 -              strbuf_release(&buf);
 -              return;
 -      }
 -      if (*buffer)
 +              pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf, &ctx);
 +              buffer = ufbuf.buf;
 +      } else if (*buffer) {
                buffer++;
 +      }
        insert_one_record(log, author, !*buffer ? "<none>" : buffer);
 +      strbuf_release(&ufbuf);
 +      strbuf_release(&buf);
  }
  
  static void get_from_rev(struct rev_info *rev, struct shortlog *log)
@@@ -304,9 -301,19 +304,19 @@@ parse_done
        return 0;
  }
  
+ static void add_wrapped_shortlog_msg(struct strbuf *sb, const char *s,
+                                    const struct shortlog *log)
+ {
+       int col = strbuf_add_wrapped_text(sb, s, log->in1, log->in2, log->wrap);
+       if (col != log->wrap)
+               strbuf_addch(sb, '\n');
+ }
  void shortlog_output(struct shortlog *log)
  {
        int i, j;
+       struct strbuf sb = STRBUF_INIT;
        if (log->sort_by_number)
                qsort(log->list.items, log->list.nr, sizeof(struct string_list_item),
                        compare_by_number);
                                const char *msg = onelines->items[j].string;
  
                                if (log->wrap_lines) {
-                                       int col = print_wrapped_text(msg, log->in1, log->in2, log->wrap);
-                                       if (col != log->wrap)
-                                               putchar('\n');
+                                       strbuf_reset(&sb);
+                                       add_wrapped_shortlog_msg(&sb, msg, log);
+                                       fwrite(sb.buf, sb.len, 1, stdout);
                                }
                                else
                                        printf("      %s\n", msg);
                log->list.items[i].util = NULL;
        }
  
+       strbuf_release(&sb);
        log->list.strdup_strings = 1;
        string_list_clear(&log->list, 1);
        clear_mailmap(&log->mailmap);