git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/3] config: add git_config_from_sha1() to read from a blob
Date: Thu,  9 Dec 2010 22:09:47 +0700	[thread overview]
Message-ID: <1291907388-9068-3-git-send-email-pclouds@gmail.com> (raw)
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

  parent reply	other threads:[~2010-12-09 15:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-09 15:09 [RFC/WIP 0/3] Shared config Nguyễn Thái Ngọc Duy
2010-12-09 15:09 ` [PATCH 1/3] config: read full file content before parsing Nguyễn Thái Ngọc Duy
2010-12-09 15:09 ` Nguyễn Thái Ngọc Duy [this message]
2010-12-09 15:58   ` [PATCH 2/3] config: add git_config_from_sha1() to read from a blob Thiago Farina
2010-12-09 17:02     ` Jonathan Nieder
2010-12-09 15:09 ` [PATCH 3/3] config: add core.sharedconfig Nguyễn Thái Ngọc Duy
2010-12-09 16:00   ` Thiago Farina
2010-12-10  1:53     ` Nguyen Thai Ngoc Duy
2010-12-09 18:13   ` Junio C Hamano
2010-12-09 18:19     ` Jonathan Nieder
2010-12-10  1:29     ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291907388-9068-3-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).