git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: Greg Brockman <gdb@MIT.EDU>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH/RFC 4/4] Add interactive mode to git-shell for user-friendliness
Date: Wed, 14 Jul 2010 12:27:23 +0200	[thread overview]
Message-ID: <4C3D910B.7080401@viscovery.net> (raw)
In-Reply-To: <1279076475-27730-5-git-send-email-gdb@mit.edu>

I don't have an immediate need for features implemented by this series,
but I think they can be useful occasionally.

Am 7/14/2010 5:01, schrieb Greg Brockman:
> --- a/shell.c
> +++ b/shell.c
> @@ -1,8 +1,11 @@
> +#include <stdio.h>

Is it really needed? Doesn't cache.h pull it in already?

> +
>  #include "cache.h"
...
> +static int run(const char *prog)
> +{
> +	pid_t pid, res;
> +	int w;
> +	pid = fork();
> +	if (pid == -1) {
> +		perror("fork");
> +		exit(-1);
> +	} else if ( pid == 0 ) {
> +		execl(prog, prog, (char *) NULL);
> +		if (prog[0] != '\0')
> +			fprintf(stderr, "unrecognized command '%s'\n", prog);
> +		exit(127);
> +	} else {
> +		do {
> +			res = waitpid (pid, &w, 0);
> +		} while (res == -1 && errno == EINTR);
> +	}
> +}

Is there a reason that you duplicate functionality offered by run_command()?

> @@ -81,8 +105,30 @@ int main(int argc, char **argv)
>  	 * We do not accept anything but "-c" followed by "cmd arg",
>  	 * where "cmd" is a very limited subset of git commands.
>  	 */
> -	else if (argc != 3 || strcmp(argv[1], "-c"))
> -		die("What do you think I am? A shell?");
> +	else if (argc != 3 || strcmp(argv[1], "-c")) {
> +		if (chdir(COMMAND_DIR))
> +			die("Sorry, the interactive git-shell is not enabled");
> +		for (;;) {
> +			printf("git> ");
> +			if (fgets(line, MAX_LINE_LEN, stdin) == NULL) {
> +				printf("\n");
> +				exit(0);
> +			}
> +
> +			if (line[strlen(line) - 1] == '\n')
> +				line[strlen(line) - 1] = '\0';
> +
> +			if (!strcmp(line, "quit") || !strcmp(line, "logout") ||
> +				   !strcmp(line, "exit")) {
> +				exit(0);
> +			} else if (!strcmp(line, "")) {
> +			} else if (is_valid_cmd_name(line)) {
> +				run(line);
> +			} else {
> +				fprintf(stderr, "invalid command format '%s'\n", line);
> +			}
> +		};
> +	}

I can imagine that this loop grows in the future, so I suggest to move it
to a separate function right from the beginning.

I think it would make sense to print a help message before the first prompt.

-- Hannes

  parent reply	other threads:[~2010-07-14 10:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-14  3:01 [PATCH/RFC 0/4] Providing mechanism to list available repositories Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 1/4] Allow creation of arbitrary git-shell commands Greg Brockman
2010-07-14 15:27   ` Junio C Hamano
2010-07-14 17:42     ` Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 2/4] git-shell-commands: Add a command to list bare repos Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 3/4] git-shell-commands: Add a help command Greg Brockman
2010-07-14  3:01 ` [PATCH/RFC 4/4] Add interactive mode to git-shell for user-friendliness Greg Brockman
2010-07-14  9:04   ` Ævar Arnfjörð Bjarmason
2010-07-14 13:59     ` Kevin P. Fleming
2010-07-14 15:24       ` Bernhard R. Link
2010-07-14 15:40         ` Thomas Rast
     [not found]           ` <20100714160730.GA27078@pcpool00.mathematik.uni-freiburg.de>
     [not found]             ` <AANLkTikEjMeKPkyY4RdRq-ESkmmq4PvqCFPgp8yvLVBz@mail.gmail.com>
2010-07-17  4:12               ` Greg Brockman
2010-07-17  5:52                 ` Jonathan Nieder
2010-07-17 14:53                   ` Greg Brockman
2010-07-24 15:20           ` [PATCH] Cast execl*() NULL sentinels to (char *) Thomas Rast
2010-07-24 15:27             ` Ævar Arnfjörð Bjarmason
2010-07-14 10:27   ` Johannes Sixt [this message]
2010-07-14 19:11 ` [PATCH/RFC 0/4] Providing mechanism to list available repositories Junio C Hamano
2010-07-14 19:29   ` Greg Brockman

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=4C3D910B.7080401@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=gdb@MIT.EDU \
    --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).