{"thread":{"id":"11507","subject":"Repository specific git commands","startedAt":"2008-01-07T12:15:59Z","lastAt":"2008-05-23T14:20:25Z","messageCount":4,"participants":["Ciprian Dorin Craciun","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64645","messageId":"8e04b5820801070415j5166c2eco53760cffe1ab1efb@mail.gmail.com","threadId":"11507","inReplyTo":null,"subject":"Repository specific git commands","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-01-07T12:15:59Z","receivedAt":"2008-01-07T12:15:59Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    Hello all!\n\n    I have a question / proposal: I see on the mailing list a lot of\nsituations when some commands (or group of commands) are very often\nused and the users demand (or would like to have) a special \"git xxx\"\ncommand for them. But adding such a command -- in almost all cases --\nis not worth the effort or increases the number of available commands\n(thus confusing even more the users).\n\n    Thus the users are left with only two possibilities:\n    -- either define an alias -- but usually it is very restrictive in\nterms of what the alias can do;\n    -- create a custom git command \"git-xxx\" and place it in the\nexecutable path -- but this requires root access.\n    (-- or write a custom script but this can not be invoked as \"git xxx\")\n    => Thus neither option is very useful.\n\n    So my proposal is to let the users create a special folder inside\nthe .git directory, for example \".git/bin\" where they can place custom\nbuilt git files like \"git-xxx\", and when they issue \"git xxx\" this\nfolder is searched first, and if the command is found it will be\nexecuted as any other \"git-xxx\".\n\n    For this I attach a very simple patch that implements it. (It\nmodifies the execv_git_cmd function by adding a new path in the paths\narray.)\n\n    Comments? Opinions? Other solutions that I am not aware of?\n\n    (Please note that I am a git user for only a couple of months, and\nthis is the first time I look over git source code...)\n\n    Thanks,\n    Ciprian Craciun.\n\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex 9b74ed2..9082711 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -30,11 +30,32 @@ const char *git_exec_path(void)\n }\n \n \n+static const char *git_repo_exec_path(void)\n+{\n+\tstatic char path_buffer[PATH_MAX + 1];\n+\tstatic char *path = NULL;\n+\t\n+\tif (!path) {\n+\t\tpath = path_buffer;\n+\t\tpath[0] = '\\0';\n+\t\tif (get_git_dir()) {\n+\t\t\tstrncat(path, get_git_dir(), PATH_MAX);\n+\t\t\tstrncat(path, \"/\", PATH_MAX);\n+\t\t\tstrncat(path, \"bin\", PATH_MAX);\n+\t\t}\n+\t}\n+\t\n+\treturn path;\n+}\n+\n+\n int execv_git_cmd(const char **argv)\n {\n \tchar git_command[PATH_MAX + 1];\n \tint i;\n-\tconst char *paths[] = { current_exec_path,\n+\tconst char *paths[] = {\n+\t\t\t\tgit_repo_exec_path(),\n+\t\t\t\tcurrent_exec_path,\n \t\t\t\tgetenv(EXEC_PATH_ENVIRONMENT),\n \t\t\t\tbuiltin_exec_path };\n \n"},{"id":"64648","messageId":"Pine.LNX.4.64.0801071352470.14355@wbgn129.biozentrum.uni-wuerzburg.de","threadId":"11507","inReplyTo":"8e04b5820801070415j5166c2eco53760cffe1ab1efb@mail.gmail.com","subject":"Re: Repository specific git commands","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-07T12:55:54Z","receivedAt":"2008-01-07T12:55:54Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 7 Jan 2008, Ciprian Dorin Craciun wrote:\n\n>     -- either define an alias -- but usually it is very restrictive in\n> terms of what the alias can do;\n\nYou probably missed the possibility of executing a shell command (or \ncommands) viathe  \"!\" prefix.\n\nSee also\n\n\thttp://git.or.cz/gitwiki/Aliases/\n\nHth,\nDscho\n"},{"id":"64650","messageId":"8e04b5820801070514l7a49b0fewcaa5f4b6d9a6c622@mail.gmail.com","threadId":"11507","inReplyTo":"Pine.LNX.4.64.0801071352470.14355@wbgn129.biozentrum.uni-wuerzburg.de","subject":"Re: Repository specific git commands","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-01-07T13:14:39Z","receivedAt":"2008-01-07T13:14:39Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On 1/7/08, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Hi,\n>\n> On Mon, 7 Jan 2008, Ciprian Dorin Craciun wrote:\n>\n> >     -- either define an alias -- but usually it is very restrictive in\n> > terms of what the alias can do;\n>\n> You probably missed the possibility of executing a shell command (or\n> commands) viathe  \"!\" prefix.\n>\n> See also\n>\n>         http://git.or.cz/gitwiki/Aliases/\n>\n> Hth,\n> Dscho\n\n    I knew about the \"!\" prefix but this allows me to write only a\none-line script... But in the case I want more complex scripts? (Just\nlook at how hard it is to read the \"Getting the diff of only one\nfunction\" example...) (Yes I could create a script, place it in a\nspecial folder and add an alias to it -- remembering to put the right\npath... But it is not as simple as adding it to the bin directory.)\n\n    Ciprian.\n"},{"id":"77553","messageId":"8e04b5820805230720p2117fa9cp5a44c16c99457c69@mail.gmail.com","threadId":"11507","inReplyTo":"8e04b5820801070415j5166c2eco53760cffe1ab1efb@mail.gmail.com","subject":"Re: Repository specific git commands","fromName":"Ciprian Dorin Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2008-05-23T14:20:25Z","receivedAt":"2008-05-23T14:20:25Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    Hello all!\n\n    A few months ago, I've proposed a feature (and accompaning patch)\nthat would enable users to create a \"bin\" folder inside the .git\nfolder, where they were allowed to put special git commands, that\nwould be accessible just like any other git command, but only for that\nspecific repository.\n\n    Now the problem is that in the new Git v1.5.5.1 something has\nchanged, and I can not figure out what I shall do...\n\n    In previous versions it was easy: just add a new path in the array\ninside the execv_git_cmd function.\n\n    But now the paths were moved to the setup_path function, and I'm\nnot able to make it work (see my patch bellow). The problem is that\nall the commands start with the current folder being the top worktree\nfolder...\n\n    Any suggestions, help, documentation?\n\n    Thanks all,\n    Ciprian.\n\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex e189cac..2166ae3 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -41,6 +41,28 @@ static void add_path(struct strbuf *out, const char *path)\n \t}\n }\n\n+static const char *git_repo_exec_path(void)\n+{\n+\tstatic char path_buffer[PATH_MAX + 1];\n+\tstatic char *path = NULL;\n+\tchar *git_dir;\n+\tint nongit_ok = 1; // ????\n+\t\n+\tif (!path) {\n+\t\tpath = path_buffer;\n+\t\tpath[0] = '\\0';\n+\t\tsetup_git_directory_gently(&nongit_ok);\n+\t\tgit_dir = get_git_dir();\n+\t\tif (!nongit_ok && git_dir) {\n+\t\t\tstrncat(path, git_dir, PATH_MAX);\n+\t\t\tstrncat(path, \"/\", PATH_MAX);\n+\t\t\tstrncat(path, \"bin\", PATH_MAX);\n+\t\t}\n+\t}\n+\t\n+\treturn path;\n+}\n+\n void setup_path(const char *cmd_path)\n {\n \tconst char *old_path = getenv(\"PATH\");\n@@ -48,6 +70,7 @@ void setup_path(const char *cmd_path)\n\n \tstrbuf_init(&new_path, 0);\n\n+\tadd_path(&new_path, git_repo_exec_path());\n \tadd_path(&new_path, argv_exec_path);\n \tadd_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));\n \tadd_path(&new_path, builtin_exec_path);\n\n\nOn Mon, Jan 7, 2008 at 3:15 PM, Ciprian Dorin Craciun\n<ciprian.craciun@gmail.com> wrote:\n>    Hello all!\n>\n>    I have a question / proposal: I see on the mailing list a lot of\n> situations when some commands (or group of commands) are very often\n> used and the users demand (or would like to have) a special \"git xxx\"\n> command for them. But adding such a command -- in almost all cases --\n> is not worth the effort or increases the number of available commands\n> (thus confusing even more the users).\n>\n>    Thus the users are left with only two possibilities:\n>    -- either define an alias -- but usually it is very restrictive in\n> terms of what the alias can do;\n>    -- create a custom git command \"git-xxx\" and place it in the\n> executable path -- but this requires root access.\n>    (-- or write a custom script but this can not be invoked as \"git xxx\")\n>    => Thus neither option is very useful.\n>\n>    So my proposal is to let the users create a special folder inside\n> the .git directory, for example \".git/bin\" where they can place custom\n> built git files like \"git-xxx\", and when they issue \"git xxx\" this\n> folder is searched first, and if the command is found it will be\n> executed as any other \"git-xxx\".\n>\n>    For this I attach a very simple patch that implements it. (It\n> modifies the execv_git_cmd function by adding a new path in the paths\n> array.)\n>\n>    Comments? Opinions? Other solutions that I am not aware of?\n>\n>    (Please note that I am a git user for only a couple of months, and\n> this is the first time I look over git source code...)\n>\n>    Thanks,\n>    Ciprian Craciun.\n>\n"}]}