git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/9] Add strbuf_read_path().

From
Kristian Høgsberg <krh@redhat.com>
Date
Sep 6, 2007, 00:23 UTC
Message-ID
<11890382262161-git-send-email-krh@redhat.com>
In-Reply-To
<1189038225525-git-send-email-krh@redhat.com>
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
 builtin-tag.c |    7 +------
 strbuf.c      |   15 +++++++++++++++
 strbuf.h      |    1 +
 3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 1aff952..8724d49 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -53,14 +53,9 @@ static void launch_editor(const char *path, struct strbuf *sb)
 	if (run_command(&child))
 		die("There was a problem with the editor %s.", editor);
 
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		die("could not open '%s': %s", path, strerror(errno));
-	if (strbuf_read_fd(sb, fd) < 0) {
+	if (strbuf_read_path(sb, path) < 0)
 		die("could not read message file '%s': %s",
 		    path, strerror(errno));
-	}
-	close(fd);
 }
 
 struct tag_filter {
diff --git a/strbuf.c b/strbuf.c
index ed2afea..1951a5b 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -70,6 +70,21 @@ int strbuf_read_fd(struct strbuf *sb, int fd)
 	return total;
 }
 
+int strbuf_read_path(struct strbuf *sb, const char *path)
+{
+	int fd, len;
+
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		return -1;
+	len = strbuf_read_fd(sb, fd);
+	if (len < 0)
+		return -1;
+	close(fd);
+
+	return len;
+}
+
 void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
 {
 	char buffer[2048];
diff --git a/strbuf.h b/strbuf.h
index a93b9e1..e852070 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -14,6 +14,7 @@ extern void strbuf_add(struct strbuf *sb, const char *data, size_t len);
 extern void strbuf_add_char(struct strbuf *sb, int ch);
 extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
 extern int strbuf_read_fd(struct strbuf *sb, int fd);
+extern int strbuf_read_path(struct strbuf *sb, const char *path);
 extern size_t stripspace(struct strbuf *sb, int skip_comments);
 
 #endif /* STRBUF_H */
-- 
1.5.2.GIT
Previous: Kristian HøgsbergNext: Kristian Høgsberg
Message 7 of 25 in “Enable wt-status output to a given FILE pointer.”
  1. 1/9 Enable wt-status output to a given FILE pointer.Kristian Høgsberg, Sep 6, 2007
  2. 2/9 Enable wt-status to run against non-standard index file.Kristian Høgsberg, Sep 6, 2007
  3. 3/9 Add strbuf_printf() to do formatted printing to a strbuf.Kristian Høgsberg, Sep 6, 2007
  4. 4/9 Introduce entry point for launching add--interactive.Kristian Høgsberg, Sep 6, 2007
  5. 5/9 Introduce strbuf_read_fd().Kristian Høgsberg, Sep 6, 2007
  6. 6/9 Rewrite launch_editor, create_tag and stripspace to use strbufs.Kristian Høgsberg, Sep 6, 2007
  7. 7/9 Add strbuf_read_path().Kristian Høgsberg, Sep 6, 2007
  8. 8/9 Export rerere() and launch_editor().Kristian Høgsberg, Sep 6, 2007
  9. 9/9 Implement git commit as a builtin command.Kristian Høgsberg, Sep 6, 2007
  10. Johannes SchindelinSep 6, 2007
  11. Kristian HøgsbergSep 17, 2007
  12. Johannes SchindelinSep 17, 2007
  13. Jeff KingSep 17, 2007
  14. Kristian HøgsbergSep 18, 2007
  15. Johannes SchindelinSep 6, 2007
  16. Johannes SchindelinSep 6, 2007
  17. Kristian HøgsbergSep 17, 2007
  18. Johannes SchindelinSep 6, 2007
  19. Kristian HøgsbergSep 17, 2007
  20. Johannes SchindelinSep 17, 2007
  21. Junio C HamanoSep 6, 2007
  22. Pierre HabouzitSep 6, 2007
  23. Pierre HabouzitSep 6, 2007
  24. Johannes SchindelinSep 6, 2007
  25. Kristian HøgsbergSep 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.