Merge branch 'sp/shortlog-missing-lf'
authorJunio C Hamano <gitster@pobox.com>
Wed, 2 Jan 2013 18:40:34 +0000 (10:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Jan 2013 18:40:34 +0000 (10:40 -0800)
When a line to be wrapped has a solid run of non space characters
whose length exactly is the wrap width, "git shortlog -w" failed to
add a newline after such a line.

* sp/shortlog-missing-lf:
strbuf_add_wrapped*(): Remove unused return value
shortlog: fix wrapping lines of wraplen

1  2 
builtin/shortlog.c
utf8.c
utf8.h
diff --combined builtin/shortlog.c
index b316cf37ca768f1502c5d0cfa64372a9b322a572,52f92842890991f39c9e1ddb097b760cc4ca1c3e..83605143ac0cea68b421dd9a3c056d3a27f66be9
@@@ -10,9 -10,9 +10,9 @@@
  #include "parse-options.h"
  
  static char const * const shortlog_usage[] = {
 -      "git shortlog [-n] [-s] [-e] [-w] [rev-opts] [--] [<commit-id>... ]",
 +      N_("git shortlog [-n] [-s] [-e] [-w] [rev-opts] [--] [<commit-id>... ]"),
        "",
 -      "[rev-opts] are documented in git-rev-list(1)",
 +      N_("[rev-opts] are documented in git-rev-list(1)"),
        NULL
  };
  
@@@ -250,13 -250,13 +250,13 @@@ int cmd_shortlog(int argc, const char *
  
        static const struct option options[] = {
                OPT_BOOLEAN('n', "numbered", &log.sort_by_number,
 -                          "sort output according to the number of commits per author"),
 +                          N_("sort output according to the number of commits per author")),
                OPT_BOOLEAN('s', "summary", &log.summary,
 -                          "Suppress commit descriptions, only provides commit count"),
 +                          N_("Suppress commit descriptions, only provides commit count")),
                OPT_BOOLEAN('e', "email", &log.email,
 -                          "Show the email address of each author"),
 -              { OPTION_CALLBACK, 'w', NULL, &log, "w[,i1[,i2]]",
 -                      "Linewrap output", PARSE_OPT_OPTARG, &parse_wrap_args },
 +                          N_("Show the email address of each author")),
 +              { OPTION_CALLBACK, 'w', NULL, &log, N_("w[,i1[,i2]]"),
 +                      N_("Linewrap output"), PARSE_OPT_OPTARG, &parse_wrap_args },
                OPT_END(),
        };
  
@@@ -306,9 -306,8 +306,8 @@@ parse_done
  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');
+       strbuf_add_wrapped_text(sb, s, log->in1, log->in2, log->wrap);
+       strbuf_addch(sb, '\n');
  }
  
  void shortlog_output(struct shortlog *log)
diff --combined utf8.c
index 5c61bbe1131e7bbdd939c8b815bd5222b872e3fb,613eb94b46c91aaf9cc8d0a885d92377cb1eb8ed..a4ee6650ef6c4c487c083aabf0a950b8ec317b09
--- 1/utf8.c
--- 2/utf8.c
+++ b/utf8.c
@@@ -323,7 -323,7 +323,7 @@@ static size_t display_mode_esc_sequence
   * If indent is negative, assume that already -indent columns have been
   * consumed (and no extra indent is necessary for the first line).
   */
int strbuf_add_wrapped_text(struct strbuf *buf,
void strbuf_add_wrapped_text(struct strbuf *buf,
                const char *text, int indent1, int indent2, int width)
  {
        int indent, w, assume_utf8 = 1;
  
        if (width <= 0) {
                strbuf_add_indented_text(buf, text, indent1, indent2);
-               return 1;
+               return;
        }
  
  retry:
                        if (w <= width || !space) {
                                const char *start = bol;
                                if (!c && text == start)
-                                       return w;
+                                       return;
                                if (space)
                                        start = space;
                                else
                                        strbuf_addchars(buf, ' ', indent);
                                strbuf_add(buf, start, text - start);
                                if (!c)
-                                       return w;
+                                       return;
                                space = text;
                                if (c == '\t')
                                        w |= 0x07;
@@@ -405,13 -405,12 +405,12 @@@ new_line
        }
  }
  
int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
                             int indent, int indent2, int width)
  {
        char *tmp = xstrndup(data, len);
-       int r = strbuf_add_wrapped_text(buf, tmp, indent, indent2, width);
+       strbuf_add_wrapped_text(buf, tmp, indent, indent2, width);
        free(tmp);
-       return r;
  }
  
  int is_encoding_utf8(const char *name)
        return 0;
  }
  
 +int same_encoding(const char *src, const char *dst)
 +{
 +      if (is_encoding_utf8(src) && is_encoding_utf8(dst))
 +              return 1;
 +      return !strcasecmp(src, dst);
 +}
 +
  /*
   * Given a buffer and its encoding, return it re-encoded
   * with iconv.  If the conversion fails, returns NULL.
  #else
        typedef char * iconv_ibp;
  #endif
 -char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding)
 +char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv)
  {
 -      iconv_t conv;
 -      size_t insz, outsz, outalloc;
 +      size_t outsz, outalloc;
        char *out, *outpos;
        iconv_ibp cp;
  
 -      if (!in_encoding)
 -              return NULL;
 -      conv = iconv_open(out_encoding, in_encoding);
 -      if (conv == (iconv_t) -1)
 -              return NULL;
 -      insz = strlen(in);
        outsz = insz;
        outalloc = outsz + 1; /* for terminating NUL */
        out = xmalloc(outalloc);
                        size_t sofar;
                        if (errno != E2BIG) {
                                free(out);
 -                              iconv_close(conv);
                                return NULL;
                        }
                        /* insz has remaining number of bytes.
                        break;
                }
        }
 +      return out;
 +}
 +
 +char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding)
 +{
 +      iconv_t conv;
 +      char *out;
 +
 +      if (!in_encoding)
 +              return NULL;
 +      conv = iconv_open(out_encoding, in_encoding);
 +      if (conv == (iconv_t) -1)
 +              return NULL;
 +      out = reencode_string_iconv(in, strlen(in), conv);
        iconv_close(conv);
        return out;
  }
diff --combined utf8.h
index 93ef60042c2fad93184b573f30e771ecddc842be,f50c567d4202142325ce7a7f991b42775ff0fca5..a214238bdd70c6b4eb41edf6626c5b396489ab50
--- 1/utf8.h
--- 2/utf8.h
+++ b/utf8.h
@@@ -7,15 -7,13 +7,15 @@@ int utf8_width(const char **start, size
  int utf8_strwidth(const char *string);
  int is_utf8(const char *text);
  int is_encoding_utf8(const char *name);
 +int same_encoding(const char *, const char *);
  
int strbuf_add_wrapped_text(struct strbuf *buf,
void strbuf_add_wrapped_text(struct strbuf *buf,
                const char *text, int indent, int indent2, int width);
int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
void strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
                             int indent, int indent2, int width);
  
  #ifndef NO_ICONV
 +char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv);
  char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding);
  #else
  #define reencode_string(a,b,c) NULL