* Repository specific git commands @ 2008-01-07 12:15 Ciprian Dorin Craciun 2008-01-07 12:55 ` Johannes Schindelin 2008-05-23 14:20 ` Ciprian Dorin Craciun 0 siblings, 2 replies; 4+ messages in thread From: Ciprian Dorin Craciun @ 2008-01-07 12:15 UTC (permalink / raw) To: git [-- Attachment #1: Type: text/plain, Size: 1473 bytes --] Hello all! I have a question / proposal: I see on the mailing list a lot of situations when some commands (or group of commands) are very often used and the users demand (or would like to have) a special "git xxx" command for them. But adding such a command -- in almost all cases -- is not worth the effort or increases the number of available commands (thus confusing even more the users). Thus the users are left with only two possibilities: -- either define an alias -- but usually it is very restrictive in terms of what the alias can do; -- create a custom git command "git-xxx" and place it in the executable path -- but this requires root access. (-- or write a custom script but this can not be invoked as "git xxx") => Thus neither option is very useful. So my proposal is to let the users create a special folder inside the .git directory, for example ".git/bin" where they can place custom built git files like "git-xxx", and when they issue "git xxx" this folder is searched first, and if the command is found it will be executed as any other "git-xxx". For this I attach a very simple patch that implements it. (It modifies the execv_git_cmd function by adding a new path in the paths array.) Comments? Opinions? Other solutions that I am not aware of? (Please note that I am a git user for only a couple of months, and this is the first time I look over git source code...) Thanks, Ciprian Craciun. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: patch.diff --] [-- Type: text/x-diff; name=patch.diff, Size: 779 bytes --] diff --git a/exec_cmd.c b/exec_cmd.c index 9b74ed2..9082711 100644 --- a/exec_cmd.c +++ b/exec_cmd.c @@ -30,11 +30,32 @@ const char *git_exec_path(void) } +static const char *git_repo_exec_path(void) +{ + static char path_buffer[PATH_MAX + 1]; + static char *path = NULL; + + if (!path) { + path = path_buffer; + path[0] = '\0'; + if (get_git_dir()) { + strncat(path, get_git_dir(), PATH_MAX); + strncat(path, "/", PATH_MAX); + strncat(path, "bin", PATH_MAX); + } + } + + return path; +} + + int execv_git_cmd(const char **argv) { char git_command[PATH_MAX + 1]; int i; - const char *paths[] = { current_exec_path, + const char *paths[] = { + git_repo_exec_path(), + current_exec_path, getenv(EXEC_PATH_ENVIRONMENT), builtin_exec_path }; ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Repository specific git commands 2008-01-07 12:15 Repository specific git commands Ciprian Dorin Craciun @ 2008-01-07 12:55 ` Johannes Schindelin 2008-01-07 13:14 ` Ciprian Dorin Craciun 2008-05-23 14:20 ` Ciprian Dorin Craciun 1 sibling, 1 reply; 4+ messages in thread From: Johannes Schindelin @ 2008-01-07 12:55 UTC (permalink / raw) To: Ciprian Dorin Craciun; +Cc: git Hi, On Mon, 7 Jan 2008, Ciprian Dorin Craciun wrote: > -- either define an alias -- but usually it is very restrictive in > terms of what the alias can do; You probably missed the possibility of executing a shell command (or commands) viathe "!" prefix. See also http://git.or.cz/gitwiki/Aliases/ Hth, Dscho ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Repository specific git commands 2008-01-07 12:55 ` Johannes Schindelin @ 2008-01-07 13:14 ` Ciprian Dorin Craciun 0 siblings, 0 replies; 4+ messages in thread From: Ciprian Dorin Craciun @ 2008-01-07 13:14 UTC (permalink / raw) To: Johannes Schindelin; +Cc: git On 1/7/08, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote: > Hi, > > On Mon, 7 Jan 2008, Ciprian Dorin Craciun wrote: > > > -- either define an alias -- but usually it is very restrictive in > > terms of what the alias can do; > > You probably missed the possibility of executing a shell command (or > commands) viathe "!" prefix. > > See also > > http://git.or.cz/gitwiki/Aliases/ > > Hth, > Dscho I knew about the "!" prefix but this allows me to write only a one-line script... But in the case I want more complex scripts? (Just look at how hard it is to read the "Getting the diff of only one function" example...) (Yes I could create a script, place it in a special folder and add an alias to it -- remembering to put the right path... But it is not as simple as adding it to the bin directory.) Ciprian. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Repository specific git commands 2008-01-07 12:15 Repository specific git commands Ciprian Dorin Craciun 2008-01-07 12:55 ` Johannes Schindelin @ 2008-05-23 14:20 ` Ciprian Dorin Craciun 1 sibling, 0 replies; 4+ messages in thread From: Ciprian Dorin Craciun @ 2008-05-23 14:20 UTC (permalink / raw) To: git Hello all! A few months ago, I've proposed a feature (and accompaning patch) that would enable users to create a "bin" folder inside the .git folder, where they were allowed to put special git commands, that would be accessible just like any other git command, but only for that specific repository. Now the problem is that in the new Git v1.5.5.1 something has changed, and I can not figure out what I shall do... In previous versions it was easy: just add a new path in the array inside the execv_git_cmd function. But now the paths were moved to the setup_path function, and I'm not able to make it work (see my patch bellow). The problem is that all the commands start with the current folder being the top worktree folder... Any suggestions, help, documentation? Thanks all, Ciprian. diff --git a/exec_cmd.c b/exec_cmd.c index e189cac..2166ae3 100644 --- a/exec_cmd.c +++ b/exec_cmd.c @@ -41,6 +41,28 @@ static void add_path(struct strbuf *out, const char *path) } } +static const char *git_repo_exec_path(void) +{ + static char path_buffer[PATH_MAX + 1]; + static char *path = NULL; + char *git_dir; + int nongit_ok = 1; // ???? + + if (!path) { + path = path_buffer; + path[0] = '\0'; + setup_git_directory_gently(&nongit_ok); + git_dir = get_git_dir(); + if (!nongit_ok && git_dir) { + strncat(path, git_dir, PATH_MAX); + strncat(path, "/", PATH_MAX); + strncat(path, "bin", PATH_MAX); + } + } + + return path; +} + void setup_path(const char *cmd_path) { const char *old_path = getenv("PATH"); @@ -48,6 +70,7 @@ void setup_path(const char *cmd_path) strbuf_init(&new_path, 0); + add_path(&new_path, git_repo_exec_path()); add_path(&new_path, argv_exec_path); add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT)); add_path(&new_path, builtin_exec_path); On Mon, Jan 7, 2008 at 3:15 PM, Ciprian Dorin Craciun <ciprian.craciun@gmail.com> wrote: > Hello all! > > I have a question / proposal: I see on the mailing list a lot of > situations when some commands (or group of commands) are very often > used and the users demand (or would like to have) a special "git xxx" > command for them. But adding such a command -- in almost all cases -- > is not worth the effort or increases the number of available commands > (thus confusing even more the users). > > Thus the users are left with only two possibilities: > -- either define an alias -- but usually it is very restrictive in > terms of what the alias can do; > -- create a custom git command "git-xxx" and place it in the > executable path -- but this requires root access. > (-- or write a custom script but this can not be invoked as "git xxx") > => Thus neither option is very useful. > > So my proposal is to let the users create a special folder inside > the .git directory, for example ".git/bin" where they can place custom > built git files like "git-xxx", and when they issue "git xxx" this > folder is searched first, and if the command is found it will be > executed as any other "git-xxx". > > For this I attach a very simple patch that implements it. (It > modifies the execv_git_cmd function by adding a new path in the paths > array.) > > Comments? Opinions? Other solutions that I am not aware of? > > (Please note that I am a git user for only a couple of months, and > this is the first time I look over git source code...) > > Thanks, > Ciprian Craciun. > ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-05-23 14:21 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-01-07 12:15 Repository specific git commands Ciprian Dorin Craciun 2008-01-07 12:55 ` Johannes Schindelin 2008-01-07 13:14 ` Ciprian Dorin Craciun 2008-05-23 14:20 ` Ciprian Dorin Craciun
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).