public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@grenoble-inp•fr>
To: Tanay Abhra <tanayabh@gmail•com>
Cc: git@vger•kernel.org, Ramkumar Ramachandra <artagnon@gmail•com>,
	Junio C Hamano <gitster@pobox•com>,
	Eric Sunshine <sunshine@sunshineco•com>
Subject: Re: [PATCH v5 2/2] test-config: Add tests for the config_set API
Date: Sun, 06 Jul 2014 21:57:11 +0200	[thread overview]
Message-ID: <vpqk37q2rc8.fsf@anie.imag.fr> (raw)
In-Reply-To: <1404631162-18556-3-git-send-email-tanayabh@gmail.com> (Tanay Abhra's message of "Sun, 6 Jul 2014 00:19:22 -0700")

Tanay Abhra <tanayabh@gmail•com> writes:

> diff --git a/test-config.c b/test-config.c
> new file mode 100644
> index 0000000..45ccd0a
> --- /dev/null
> +++ b/test-config.c
> @@ -0,0 +1,127 @@
> +#include "cache.h"
> +#include "hashmap.h"

Useless include, you're not using the hashmap directly.

> +int main(int argc, char **argv)
> +{
> +	int i, no_of_files;

Unused no_of_files.

With

CFLAGS += -Wdeclaration-after-statement -Wall -Werror

in config.mak, my git.git refuses to compile with your patch. You should
have similar options for hacking on git.git.

> +	if (argc == 3 && !strcmp(argv[1], "get_value")) {

You should do something like

if (argc < 2) {
	fprintf(stderr, "Please, provide a command name on the command-line\n");
	return 1;
}

before this. Otherwise, some argv[1] below are invalid on mis-use. No
need for thorough checks since it's just a test program, but better
avoid undefined behavior and segfaults anyway...

> +		if (!git_config_get_value(argv[2], &v)) {
> +			if (!v)
> +				printf("(NULL)\n");
> +			else
> +				printf("%s\n", v);
> +			return 0;
> +		} else {
> +			printf("Value not found for \"%s\"\n", argv[2]);
> +			return -1;

Avoid returning negative values from main. Your shell's $? won't see -1,
but most likely 255 or so, but I think it even depends on the OS.

You don't seem to use main's return for anything but error, so 0 =
everything OK; 1 = some error is the common convention.

> +		} else {
> +			printf("Value not found for \"%s\"\n", argv[2]);
> +			return -1;
> +		}
> +
> +	} else if (!strcmp(argv[1], "configset_get_value_multi")) {

Why a blank line before this "else if" and not before other "else if"s?

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

  parent reply	other threads:[~2014-07-06 19:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-06  7:19 [PATCH v5 0/3] git config cache & special querying api utilizing the cache Tanay Abhra
2014-07-06  7:19 ` [PATCH v5 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-06 11:15   ` Ramsay Jones
2014-07-06 17:45   ` Matthieu Moy
2014-07-06  7:19 ` [PATCH v5 2/2] test-config: Add tests for the config_set API Tanay Abhra
2014-07-06 18:33   ` Matthieu Moy
2014-07-06 19:57   ` Matthieu Moy [this message]
2014-07-06 23:24   ` Ramkumar Ramachandra
2014-07-07  7:11     ` Matthieu Moy

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=vpqk37q2rc8.fsf@anie.imag.fr \
    --to=matthieu.moy@grenoble-inp$(echo .)fr \
    --cc=artagnon@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=sunshine@sunshineco$(echo .)com \
    --cc=tanayabh@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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