git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/3] C implementation of the 'git' program, take two.

From
Junio C Hamano <junkio@cox.net>
Date
Nov 15, 2005, 23:45 UTC
Message-ID
<7vwtj9eaqm.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20051115233125.3153B5BF76@nox.op5.se>
exon@op5.se (Andreas Ericsson) writes:
> This patch provides a C implementation of the 'git' program and
> introduces support for putting the git-* commands in a directory
> of their own.
Very nice, thanks.  Two questions and a half.
Show 7 quoted lines
> +static void prepend_to_path(const char *dir, int len)
> +{
> +	char *path, *old_path = getenv("PATH");
> +	int path_len = len;
> +
> +	if (!old_path)
> +		old_path = "/bin:/usr/bin:.";

This is to cover strange case and probably would not matter in practice, but perhaps without current directory?

Show 17 quoted lines
> +int main(int argc, char **argv, char **envp)
> +{
> +	char git_command[PATH_MAX + 1];
> +	char wd[PATH_MAX + 1];
> +	int i, len, show_help = 0;
> +	char *exec_path = getenv("GIT_EXEC_PATH");
> +
> +	getcwd(wd, PATH_MAX);
> +...
> +	/* allow relative paths, but run with exact */
> +	if (chdir(exec_path)) {
> +		printf("git: '%s': %s\n", exec_path, strerror(errno));
> +		exit (1);
> +	}
> +
> +	getcwd(git_command, sizeof(git_command));
> +	chdir(wd);
Can we always come back from where we started?
Show 13 quoted lines
> +
> +	len = strlen(git_command);
> +	prepend_to_path(git_command, len);
> +
> +	strncat(&git_command[len], "/git-", sizeof(git_command) - len);
> +	len += 5;
> +	strncat(&git_command[len], argv[i], sizeof(git_command) - len);
> +
> +	if (access(git_command, X_OK))
> +		usage(exec_path, "'%s' is not a git-command", argv[i]);
> +
> +	/* execve() can only ever return if it fails */
> +	execve(git_command, &argv[i], envp);

Shell version for Cygwin seems to do ".exe" at the end --- does it matter?

Previous: Andreas EricssonNext: Andreas Ericsson
Message 2 of 9 in “C implementation of the 'git' program, take two.”
  1. 1/3 C implementation of the 'git' program, take two.Andreas Ericsson, Nov 15, 2005
  2. Junio C HamanoNov 15, 2005
  3. Andreas EricssonNov 16, 2005
  4. Junio C HamanoNov 16, 2005
  5. Linus TorvaldsNov 16, 2005
  6. Andreas EricssonNov 16, 2005
  7. Linus TorvaldsNov 16, 2005
  8. Johannes SchindelinNov 16, 2005
  9. Alex RiesenNov 16, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.