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

[PATCH 2/3] config: add git_config_from_sha1() to read from a blob

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 9, 2010, 15:09 UTC
Message-ID
<1291907388-9068-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1291907388-9068-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 config.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/config.c b/config.c
index c8bf46f..e7a9ff4 100644
--- a/config.c
+++ b/config.c
@@ -809,6 +809,40 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 	return ret;
 }
 
+static int git_config_from_sha1(config_fn_t fn, const char *sha1_name, void *data)
+{
+	unsigned char sha1[20];
+	enum object_type type;
+	unsigned long size;
+	int ret;
+
+	if (get_sha1(sha1_name, sha1)) {
+		error("bad shared config reference '%s'", sha1_name);
+		return -1;
+	}
+
+	config_file = read_sha1_file(sha1, &type, &size);
+	if (!config_file) {
+		error("bad shared config '%s'", sha1_name);
+		return -1;
+	}
+	if (type == OBJ_BLOB) {
+		config_file_pos = 0;
+		config_file_size = size;
+		config_file_name = sha1_name;
+		config_linenr = 1;
+		config_file_eof = 0;
+		ret = git_parse_file(fn, data);
+	}
+	else {
+		error("shared config '%s' is not a blob", sha1_name);
+		return -1;
+	}
+	free(config_file);
+	config_file_name = NULL;
+	return ret;
+}
+
 const char *git_etc_gitconfig(void)
 {
 	static const char *system_wide;
-- 
1.7.3.3.476.g893a9
Previous: Nguyễn Thái Ngọc DuyNext: Thiago Farina
Message 3 of 11 in “[RFC/WIP 0/3] Shared config”
  1. Nguyễn Thái Ngọc DuyDec 9, 2010
  2. 1/3 config: read full file content before parsingNguyễn Thái Ngọc Duy, Dec 9, 2010
  3. 2/3 config: add git_config_from_sha1() to read from a blobNguyễn Thái Ngọc Duy, Dec 9, 2010
  4. Thiago FarinaDec 9, 2010
  5. Jonathan NiederDec 9, 2010
  6. 3/3 config: add core.sharedconfigNguyễn Thái Ngọc Duy, Dec 9, 2010
  7. Thiago FarinaDec 9, 2010
  8. Nguyen Thai Ngoc DuyDec 10, 2010
  9. Junio C HamanoDec 9, 2010
  10. Jonathan NiederDec 9, 2010
  11. Nguyen Thai Ngoc DuyDec 10, 2010

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.