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

[PATCH 03/12] Git.pm: Call external commands using execv_git_cmd()

From
Petr Baudis <pasky@suse.cz>
Date
Jun 24, 2006, 02:34 UTC
Message-ID
<20060624023433.32751.68321.stgit@machine.or.cz>
In-Reply-To
<20060624023429.32751.80619.stgit@machine.or.cz>

Instead of explicitly using the git wrapper to call external commands, use the execv_git_cmd() function which will directly call whatever needs to be called. GitBin option becomes useless so drop it.

This actually means the exec_path() thing I planned to use worthless internally, but Jakub wants it in anyway and I don't mind, so...

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 perl/Git.pm |   12 ++++++------
 perl/Git.xs |   22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 5c5ae12..212337e 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -122,9 +122,6 @@ to the subdirectory and the directory is
 If the directory does not have the subdirectory, C<WorkingCopy> is left
 undefined and C<Repository> is pointed to the directory itself.
 
-B<GitPath> - Path to the C<git> binary executable. By default the C<$PATH>
-is searched for it.
-
 You should not use both C<Directory> and either of C<Repository> and
 C<WorkingCopy> - the results of that are undefined.
 
@@ -363,11 +360,14 @@ sub _cmd_exec {
 		$self->{opts}->{Repository} and $ENV{'GIT_DIR'} = $self->{opts}->{Repository};
 		$self->{opts}->{WorkingCopy} and chdir($self->{opts}->{WorkingCopy});
 	}
-	my $git = $self->{opts}->{GitPath};
-	$git ||= 'git';
-	exec ($git, @args) or croak "exec failed: $!";
+	xs__execv_git_cmd(@args);
+	croak "exec failed: $!";
 }
 
+# Execute the given Git command ($_[0]) with arguments ($_[1..])
+# by searching for it at proper places.
+# _execv_git_cmd(), implemented in Git.xs.
+
 # Close pipe to a subprocess.
 sub _cmd_close {
 	my ($fh) = @_;
diff --git a/perl/Git.xs b/perl/Git.xs
index b6f6d13..c8220e2 100644
--- a/perl/Git.xs
+++ b/perl/Git.xs
@@ -33,6 +33,28 @@ OUTPUT:
 	RETVAL
 
 
+void
+xs__execv_git_cmd(...)
+CODE:
+{
+	const char **argv;
+	int i;
+
+	argv = malloc(sizeof(const char *) * (items + 1));
+	if (!argv)
+		croak("malloc failed");
+	for (i = 0; i < items; i++)
+		argv[i] = strdup(SvPV_nolen(ST(i)));
+	argv[i] = NULL;
+
+	execv_git_cmd(argv);
+
+	for (i = 0; i < items; i++)
+		if (argv[i])
+			free((char *) argv[i]);
+	free((char **) argv);
+}
+
 char *
 xs_hash_object(file, type = "blob")
 	SV *file;
Previous: Petr BaudisNext: Petr Baudis
Message 3 of 25 in “Introduce Git.pm (v4)”
  1. 01/12 Introduce Git.pm (v4)Petr Baudis, Jun 24, 2006
  2. 02/12 Git.pm: Implement Git::exec_path()Petr Baudis, Jun 24, 2006
  3. 03/12 Git.pm: Call external commands using execv_git_cmd()Petr Baudis, Jun 24, 2006
  4. 04/12 Git.pm: Implement Git::version()Petr Baudis, Jun 24, 2006
  5. 05/12 Customizable error handlersPetr Baudis, Jun 24, 2006
  6. 06/12 Add Error.pm to the distributionPetr Baudis, Jun 24, 2006
  7. 07/12 Git.pm: Better error handlingPetr Baudis, Jun 24, 2006
  8. Junio C HamanoJun 24, 2006
  9. Petr BaudisJun 24, 2006
  10. Petr BaudisJun 25, 2006
  11. Junio C HamanoJun 25, 2006
  12. 08/12 Git.pm: Handle failed commands' outputPetr Baudis, Jun 24, 2006
  13. 09/12 Git.pm: Enhance the command_pipe() mechanismPetr Baudis, Jun 24, 2006
  14. 10/12 Git.pm: Implement options for the command interfacePetr Baudis, Jun 24, 2006
  15. 11/12 Git.pm: Add support for subdirectories inside of working copiesPetr Baudis, Jun 24, 2006
  16. 12/12 Convert git-mv to use Git.pmPetr Baudis, Jun 24, 2006
  17. Petr BaudisJun 24, 2006
  18. Junio C HamanoJun 24, 2006
  19. Petr BaudisJun 24, 2006
  20. Junio C HamanoJun 24, 2006
  21. Petr BaudisJun 24, 2006
  22. Petr BaudisJun 24, 2006
  23. Junio C HamanoJun 24, 2006
  24. Petr BaudisJun 24, 2006
  25. Junio C HamanoJun 25, 2006

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.