From patchwork Thu Oct 25 16:18:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 10656153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2241713A4 for ; Thu, 25 Oct 2018 16:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 088092A9EE for ; Thu, 25 Oct 2018 16:18:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 064582BA61; Thu, 25 Oct 2018 16:18:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 415222B99B for ; Thu, 25 Oct 2018 16:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727793AbeJZAv6 (ORCPT ); Thu, 25 Oct 2018 20:51:58 -0400 Received: from mail.ao2.it ([92.243.12.208]:44349 "EHLO ao2.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727455AbeJZAv6 (ORCPT ); Thu, 25 Oct 2018 20:51:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ao2.it; s=20180927; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=fu5L5xMU7n2eQ6/vkhRYQDCY2FvgNNErOBtXtL5N+qc=; b=liUoFTwD4QRjL5UaUnhMnzl+rHs32Po72/ZLt6VAqqGFfFAUioczI3tgwlhbIXLay8Y8sApndG8OoxtS0uv3Oq1FtSMpqFDOJa6PiE5MYfFap7Cihy3570C2DDtJdD3ueyKDzGyGWWBy4b/nHMOrVhIiD5/7VXzhSFtDmFziktH9gx/LJZ9HD1RUU/uor6wnA4GfW2n4Aac+2APSiuL9yqY30cXGKGfEq0IqYUtMaW+bRSmuhEA12GeyyS/h1W/w9LCP47g9J1LygAYTE7MxD+Mhgp1HaDjMJ/oe3wu1vCBYvXNafpWcC1fv7nrQx+v97cK3HwfWO7iGkg4WR8c8VQ==; Received: from localhost ([::1] helo=jcn) by ao2.it with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1gFiKn-0003Kx-Tm; Thu, 25 Oct 2018 18:18:10 +0200 Received: from ao2 by jcn with local (Exim 4.91) (envelope-from ) id 1gFiL5-0004VB-1k; Thu, 25 Oct 2018 18:18:27 +0200 From: Antonio Ospite To: gitster@pobox.com Cc: git@vger.kernel.org, Jonathan Nieder , Stefan Beller , Jeff King , =?utf-8?q?SZ?= =?utf-8?q?EDER_G=C3=A1bor?= , Antonio Ospite Subject: [PATCH v7 01/10] submodule: add a print_config_from_gitmodules() helper Date: Thu, 25 Oct 2018 18:18:04 +0200 Message-Id: <20181025161813.17252-2-ao2@ao2.it> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181025161813.17252-1-ao2@ao2.it> References: <20181025161813.17252-1-ao2@ao2.it> MIME-Version: 1.0 X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM/Vb;]yA5\I~93>J<_`<4)A{':UrE Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new print_config_from_gitmodules() helper function to print values from .gitmodules just like "git config -f .gitmodules" would. This will be used by a new submodule--helper subcommand to be able to access the .gitmodules file in a more controlled way. Signed-off-by: Antonio Ospite --- submodule-config.c | 25 +++++++++++++++++++++++++ submodule-config.h | 1 + 2 files changed, 26 insertions(+) diff --git a/submodule-config.c b/submodule-config.c index b132f7a80b..e36d4e2271 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -692,6 +692,31 @@ void submodule_free(struct repository *r) submodule_cache_clear(r->submodule_cache); } +static int config_print_callback(const char *var, const char *value, void *cb_data) +{ + char *wanted_key = cb_data; + + if (!strcmp(wanted_key, var)) + printf("%s\n", value); + + return 0; +} + +int print_config_from_gitmodules(struct repository *repo, const char *key) +{ + int ret; + char *store_key; + + ret = git_config_parse_key(key, &store_key, NULL); + if (ret < 0) + return CONFIG_INVALID_KEY; + + config_from_gitmodules(config_print_callback, repo, store_key); + + free(store_key); + return 0; +} + struct fetch_config { int *max_children; int *recurse_submodules; diff --git a/submodule-config.h b/submodule-config.h index dc7278eea4..031747ccf8 100644 --- a/submodule-config.h +++ b/submodule-config.h @@ -48,6 +48,7 @@ const struct submodule *submodule_from_path(struct repository *r, const struct object_id *commit_or_tree, const char *path); void submodule_free(struct repository *r); +int print_config_from_gitmodules(struct repository *repo, const char *key); /* * Returns 0 if the name is syntactically acceptable as a submodule "name"