Skip to content

Instantly share code, notes, and snippets.

@husio
Created December 1, 2009 20:30
Show Gist options
  • Save husio/246615 to your computer and use it in GitHub Desktop.
Save husio/246615 to your computer and use it in GitHub Desktop.
diff --git a/git.c b/git.c
index 11544cd..88e9ac2 100644
--- a/git.c
+++ b/git.c
@@ -4,6 +4,10 @@
#include "quote.h"
#include "run-command.h"
+#define min_flag_size(ARGC) ((ARGC) * 32)
+#define ENV_CURRENT_CMD "GIT_CURRENT_CMD"
+
+
const char git_usage_string[] =
"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
" [-p|--paginate|--no-pager] [--no-replace-objects]\n"
@@ -461,7 +465,26 @@ static int run_argv(int *argcp, const char ***argv)
int main(int argc, const char **argv)
{
const char *cmd;
-
+ /* full git command handler - yes, I'm C newbie */
+ char *full_cmd = xmalloc(sizeof(char) * min_flag_size(argc));
+ char *p_argv;
+ int i, cmd_iter;
+
+ /* join all arguments into one string */
+ for (cmd_iter=0, i=1; i<argc; ++i) {
+ p_argv = argv[i];
+ while (*p_argv != '\0' && cmd_iter < min_flag_size(argc)) {
+ full_cmd[cmd_iter] = *p_argv;
+ ++p_argv;
+ ++cmd_iter;
+ }
+ full_cmd[cmd_iter] = ' ';
+ ++cmd_iter;
+ }
+ ++cmd_iter;
+ full_cmd[cmd_iter] = '\0';
+ setenv(ENV_CURRENT_CMD, full_cmd,1);
+
cmd = git_extract_argv0_path(argv[0]);
if (!cmd)
cmd = "git-help";
@@ -486,6 +509,7 @@ int main(int argc, const char **argv)
/* Look for flags.. */
argv++;
argc--;
+
handle_options(&argv, &argc, NULL);
commit_pager_choice();
if (argc > 0) {
@@ -530,5 +554,7 @@ int main(int argc, const char **argv)
fprintf(stderr, "Failed to run command '%s': %s\n",
cmd, strerror(errno));
+ /* TODO - check if it's equal to full_cmd and only if true, then unset */
+ unsetenv(ENV_CURRENT_CMD);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment