git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Kuleshov <kuleshovmail@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git <git@vger.kernel.org>, Alexander Kuleshov <kuleshovmail@gmail.com>
Subject: [PATCH] environment.c: introduce SETUP_GIT_ENV helper macro
Date: Sat, 27 Feb 2016 23:13:35 +0600	[thread overview]
Message-ID: <1456593215-16302-1-git-send-email-kuleshovmail@gmail.com> (raw)

The environment.c contans a couple of functions which are
consist from the following pattern:

        if (!env)
                setup_git_env();
        return env;

Let's move this to the SETUP_GIT_ENV helper macro to prevent
code duplication in these functions.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 environment.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/environment.c b/environment.c
index 6dec9d0..04cb6cd 100644
--- a/environment.c
+++ b/environment.c
@@ -126,6 +126,11 @@ const char * const local_repo_env[] = {
 	NULL
 };
 
+#define SETUP_GIT_ENV(env)              \
+	if (!env)                       \
+		setup_git_env();        \
+	return env;
+
 static char *expand_namespace(const char *raw_namespace)
 {
 	struct strbuf buf = STRBUF_INIT;
@@ -199,9 +204,7 @@ int is_bare_repository(void)
 
 const char *get_git_dir(void)
 {
-	if (!git_dir)
-		setup_git_env();
-	return git_dir;
+	SETUP_GIT_ENV(git_dir);
 }
 
 const char *get_git_common_dir(void)
@@ -211,9 +214,7 @@ const char *get_git_common_dir(void)
 
 const char *get_git_namespace(void)
 {
-	if (!namespace)
-		setup_git_env();
-	return namespace;
+	SETUP_GIT_ENV(namespace);
 }
 
 const char *strip_namespace(const char *namespaced_ref)
@@ -251,9 +252,7 @@ const char *get_git_work_tree(void)
 
 char *get_object_directory(void)
 {
-	if (!git_object_dir)
-		setup_git_env();
-	return git_object_dir;
+	SETUP_GIT_ENV(git_object_dir);
 }
 
 int odb_mkstemp(char *template, size_t limit, const char *pattern)
@@ -295,16 +294,12 @@ int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1)
 
 char *get_index_file(void)
 {
-	if (!git_index_file)
-		setup_git_env();
-	return git_index_file;
+	SETUP_GIT_ENV(git_index_file);
 }
 
 char *get_graft_file(void)
 {
-	if (!git_graft_file)
-		setup_git_env();
-	return git_graft_file;
+	SETUP_GIT_ENV(git_graft_file);
 }
 
 int set_git_dir(const char *path)
-- 
2.5.0

             reply	other threads:[~2016-02-27 17:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-27 17:13 Alexander Kuleshov [this message]
2016-02-27 17:51 ` [PATCH] environment.c: introduce SETUP_GIT_ENV helper macro Junio C Hamano
2016-02-27 18:50   ` Junio C Hamano
2016-02-27 19:10     ` Alexander Kuleshov

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=1456593215-16302-1-git-send-email-kuleshovmail@gmail.com \
    --to=kuleshovmail@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).