Merge branch 'jc/strbuf-add-lines-avoid-sp-ht-sequence'
authorJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2015 20:49:19 +0000 (12:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2015 20:49:19 +0000 (12:49 -0800)
The commented output used to blindly add a SP before the payload
line, resulting in "# \t<indented text>\n" when the payload began
with a HT. Instead, produce "#\t<indented text>\n".

* jc/strbuf-add-lines-avoid-sp-ht-sequence:
strbuf_add_commented_lines(): avoid SP-HT sequence in commented lines

1  2 
strbuf.c
diff --combined strbuf.c
index 0346e74a47d14ef13757cadfe2a0de778b5c4cc4,a4486a9e499d74bda3b3db10ef42d4975f7f7cbf..88cafd4a70b8179a4e911c18704fb4ab0f2a21f5
+++ b/strbuf.c
@@@ -204,13 -204,6 +204,13 @@@ void strbuf_adddup(struct strbuf *sb, s
        strbuf_setlen(sb, sb->len + len);
  }
  
 +void strbuf_addchars(struct strbuf *sb, int c, size_t n)
 +{
 +      strbuf_grow(sb, n);
 +      memset(sb->buf + sb->len, c, n);
 +      strbuf_setlen(sb, sb->len + n);
 +}
 +
  void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
  {
        va_list ap;
@@@ -229,7 -222,8 +229,8 @@@ static void add_lines(struct strbuf *ou
                const char *next = memchr(buf, '\n', size);
                next = next ? (next + 1) : (buf + size);
  
-               prefix = (prefix2 && buf[0] == '\n') ? prefix2 : prefix1;
+               prefix = ((prefix2 && (buf[0] == '\n' || buf[0] == '\t'))
+                         ? prefix2 : prefix1);
                strbuf_addstr(out, prefix);
                strbuf_add(out, buf, next - buf);
                size -= next - buf;
@@@ -413,27 -407,6 +414,27 @@@ int strbuf_readlink(struct strbuf *sb, 
        return -1;
  }
  
 +int strbuf_getcwd(struct strbuf *sb)
 +{
 +      size_t oldalloc = sb->alloc;
 +      size_t guessed_len = 128;
 +
 +      for (;; guessed_len *= 2) {
 +              strbuf_grow(sb, guessed_len);
 +              if (getcwd(sb->buf, sb->alloc)) {
 +                      strbuf_setlen(sb, strlen(sb->buf));
 +                      return 0;
 +              }
 +              if (errno != ERANGE)
 +                      break;
 +      }
 +      if (oldalloc == 0)
 +              strbuf_release(sb);
 +      else
 +              strbuf_reset(sb);
 +      return -1;
 +}
 +
  int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
  {
        int ch;
@@@ -583,31 -556,6 +584,31 @@@ void strbuf_humanise_bytes(struct strbu
        }
  }
  
 +void strbuf_add_absolute_path(struct strbuf *sb, const char *path)
 +{
 +      if (!*path)
 +              die("The empty string is not a valid path");
 +      if (!is_absolute_path(path)) {
 +              struct stat cwd_stat, pwd_stat;
 +              size_t orig_len = sb->len;
 +              char *cwd = xgetcwd();
 +              char *pwd = getenv("PWD");
 +              if (pwd && strcmp(pwd, cwd) &&
 +                  !stat(cwd, &cwd_stat) &&
 +                  (cwd_stat.st_dev || cwd_stat.st_ino) &&
 +                  !stat(pwd, &pwd_stat) &&
 +                  pwd_stat.st_dev == cwd_stat.st_dev &&
 +                  pwd_stat.st_ino == cwd_stat.st_ino)
 +                      strbuf_addstr(sb, pwd);
 +              else
 +                      strbuf_addstr(sb, cwd);
 +              if (sb->len > orig_len && !is_dir_sep(sb->buf[sb->len - 1]))
 +                      strbuf_addch(sb, '/');
 +              free(cwd);
 +      }
 +      strbuf_addstr(sb, path);
 +}
 +
  int printf_ln(const char *fmt, ...)
  {
        int ret;