git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Goddard Rosa" <andre.goddard@gmail.com>
To: "Junio C Hamano" <gitster@pobox.com>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: [Resend PATCH] Simplify the code and avoid an assignment
Date: Sun, 25 Nov 2007 19:42:31 -0200	[thread overview]
Message-ID: <b8bf37780711251342j5c733a2du18f5d79a11df4b9f@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2247 bytes --]

Hi, all!

     Simplify the code for easier understanding.

>From cd0cc6995684e2801011910735146052e5b59ccc Mon Sep 17 00:00:00 2001
From: Andre Goddard Rosa <andre.goddard@gmail.com>
Date: Tue, 27 Nov 2007 10:22:46 -0200
Subject: [PATCH] Simplify the code and avoid an assignment.

Signed-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>
---
 config.c          |   19 ++++++++++---------
 mailmap.c         |    2 +-
 xdiff-interface.c |    2 +-
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/config.c b/config.c
index 56e99fc..7c9fcdd 100644
--- a/config.c
+++ b/config.c
@@ -447,15 +447,16 @@ int git_config_from_file(config_fn_t fn, const
char *filename)
        int ret;
        FILE *f = fopen(filename, "r");

-       ret = -1;
-       if (f) {
-               config_file = f;
-               config_file_name = filename;
-               config_linenr = 1;
-               ret = git_parse_file(fn);
-               fclose(f);
-               config_file_name = NULL;
-       }
+       if (!f)
+               return -1;
+
+       config_file = f;
+       config_file_name = filename;
+       config_linenr = 1;
+       ret = git_parse_file(fn);
+       fclose(f);
+       config_file_name = NULL;
+
        return ret;
 }

diff --git a/mailmap.c b/mailmap.c
index 8714167..0c13ecd 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -7,7 +7,7 @@ int read_mailmap(struct path_list *map, const char
*filename, char **repo_abbrev
        char buffer[1024];
        FILE *f = fopen(filename, "r");

-       if (f == NULL)
+       if (!f)
                return 1;
        while (fgets(buffer, sizeof(buffer), f) != NULL) {
                char *end_of_name, *left_bracket, *right_bracket;
diff --git a/xdiff-interface.c b/xdiff-interface.c
index be866d1..9dd1f3b 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -111,7 +111,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename)

        if (stat(filename, &st))
                return error("Could not stat %s", filename);
-       if ((f = fopen(filename, "rb")) == NULL)
+       if (!(f = fopen(filename, "rb")))
                return error("Could not open %s", filename);
        sz = xsize_t(st.st_size);
        ptr->ptr = xmalloc(sz);
--
1.5.3.6.861.gd794-dirty

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-Simplify-the-code-and-avoid-an-assignment.patch --]
[-- Type: text/x-patch; name=0004-Simplify-the-code-and-avoid-an-assignment.patch, Size: 1911 bytes --]

From cd0cc6995684e2801011910735146052e5b59ccc Mon Sep 17 00:00:00 2001
From: Andre Goddard Rosa <andre.goddard@gmail.com>
Date: Tue, 27 Nov 2007 10:22:46 -0200
Subject: [PATCH] Simplify the code and avoid an assignment.

Signed-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>
---
 config.c          |   19 ++++++++++---------
 mailmap.c         |    2 +-
 xdiff-interface.c |    2 +-
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/config.c b/config.c
index 56e99fc..7c9fcdd 100644
--- a/config.c
+++ b/config.c
@@ -447,15 +447,16 @@ int git_config_from_file(config_fn_t fn, const char *filename)
 	int ret;
 	FILE *f = fopen(filename, "r");
 
-	ret = -1;
-	if (f) {
-		config_file = f;
-		config_file_name = filename;
-		config_linenr = 1;
-		ret = git_parse_file(fn);
-		fclose(f);
-		config_file_name = NULL;
-	}
+	if (!f)
+		return -1;
+
+	config_file = f;
+	config_file_name = filename;
+	config_linenr = 1;
+	ret = git_parse_file(fn);
+	fclose(f);
+	config_file_name = NULL;
+
 	return ret;
 }
 
diff --git a/mailmap.c b/mailmap.c
index 8714167..0c13ecd 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -7,7 +7,7 @@ int read_mailmap(struct path_list *map, const char *filename, char **repo_abbrev
 	char buffer[1024];
 	FILE *f = fopen(filename, "r");
 
-	if (f == NULL)
+	if (!f)
 		return 1;
 	while (fgets(buffer, sizeof(buffer), f) != NULL) {
 		char *end_of_name, *left_bracket, *right_bracket;
diff --git a/xdiff-interface.c b/xdiff-interface.c
index be866d1..9dd1f3b 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -111,7 +111,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
 
 	if (stat(filename, &st))
 		return error("Could not stat %s", filename);
-	if ((f = fopen(filename, "rb")) == NULL)
+	if (!(f = fopen(filename, "rb")))
 		return error("Could not open %s", filename);
 	sz = xsize_t(st.st_size);
 	ptr->ptr = xmalloc(sz);
-- 
1.5.3.6.861.gd794-dirty


                 reply	other threads:[~2007-11-25 21:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=b8bf37780711251342j5c733a2du18f5d79a11df4b9f@mail.gmail.com \
    --to=andre.goddard@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).