Code

IO API: use in add_describe_ref
authorJonas Fonseca <fonseca@diku.dk>
Wed, 31 Dec 2008 06:56:55 +0000 (01:56 -0500)
committerJonas Fonseca <fonseca@diku.dk>
Tue, 13 Jan 2009 21:55:18 +0000 (22:55 +0100)
tig.c

diff --git a/tig.c b/tig.c
index cb2c09fd10ab416bccecff5cd50a188540867d48..7275a993591e8e3cf241bab26ae4014a34f234fe 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -504,6 +504,23 @@ io_gets(struct io *io)
        return io->buf;
 }
 
+static bool
+run_io_buf(const char **argv, char buf[], size_t bufsize)
+{
+       struct io io = {};
+       bool error;
+
+       if (!run_io_rd(&io, argv, FORMAT_NONE))
+               return FALSE;
+
+       io.buf = buf;
+       io.bufalloc = bufsize;
+       error = !io_gets(&io) && io_error(&io);
+       io.buf = NULL;
+
+       return done_io(&io) || error;
+}
+
 
 /*
  * User requests
@@ -3135,20 +3152,12 @@ pager_draw(struct view *view, struct line *line, unsigned int lineno)
 static bool
 add_describe_ref(char *buf, size_t *bufpos, const char *commit_id, const char *sep)
 {
+       const char *describe_argv[] = { "git", "describe", commit_id, NULL };
        char refbuf[SIZEOF_STR];
        char *ref = NULL;
-       FILE *pipe;
-
-       if (!string_format(refbuf, "git describe %s 2>/dev/null", commit_id))
-               return TRUE;
 
-       pipe = popen(refbuf, "r");
-       if (!pipe)
-               return TRUE;
-
-       if ((ref = fgets(refbuf, sizeof(refbuf), pipe)))
-               ref = chomp_string(ref);
-       pclose(pipe);
+       if (run_io_buf(describe_argv, refbuf, sizeof(refbuf)))
+               ref = chomp_string(refbuf);
 
        if (!ref || !*ref)
                return TRUE;