t/t5522-pull-symlink.sh: use the $( ... ) construct for command substitution
[gitweb.git] / strbuf.c
index 958387562184fe27c7e476ebb24d5547a55ae4ad..d76f0aed85c4ec6eafdcfd1a8ee2b22d3d20df96 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -245,8 +245,8 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size
        static char prefix2[2];
 
        if (prefix1[0] != comment_line_char) {
-               sprintf(prefix1, "%c ", comment_line_char);
-               sprintf(prefix2, "%c", comment_line_char);
+               xsnprintf(prefix1, sizeof(prefix1), "%c ", comment_line_char);
+               xsnprintf(prefix2, sizeof(prefix2), "%c", comment_line_char);
        }
        add_lines(out, prefix1, prefix2, buf, size);
 }
@@ -744,6 +744,15 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm)
        strbuf_setlen(sb, sb->len + len);
 }
 
+void strbuf_add_unique_abbrev(struct strbuf *sb, const unsigned char *sha1,
+                             int abbrev_len)
+{
+       int r;
+       strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
+       r = find_unique_abbrev_r(sb->buf + sb->len, sha1, abbrev_len);
+       strbuf_setlen(sb, sb->len + r);
+}
+
 /*
  * Returns the length of a line, without trailing spaces.
  *