Introducing git-run-with-user-path program.
Subsystems (2)
cover Introducing git-run-with-user-path program.
This is a new series I've mentioned earlier today.
[PATCH 1/2] Introduce git-run-with-user-path helper program. [PATCH 2/2] Add sample ignore logic to git-run-with-user-path command.
The first one adds a path canonicalization helper with path ignore hooks but no ignore logic implementation (it passes everything that passes verify_path()). The second one adds a sample ignore logic implementation using PCRE.
Although the second one is done primarily as an example and to start a mailing list discussion, it should be also safe to merge if you decide to take patch 1, because the logic is used only by git-run-with-user-path which is a new program. no Porcelain uses right now.
cover Introducing git-run-with-user-path program.
I've polished the driver part a bit more, so that it can do something similar to "git-ls-files --others" can do, but with the (to-be-defined) "ignore rules Porcelain layers would agree upon".
[PATCH 1/2] Introduce git-run-with-user-path helper program. [PATCH 2/2] Add sample ignore logic to git-run-with-user-path command.
The first one adds a path canonicalization helper with path ignore hooks but no ignore logic implementation (it passes everything that passes verify_path()). The second one adds a sample ignore logic implementation using PCRE.
Although the second one is done primarily as an example and to start a mailing list discussion, it should be also safe to merge if you decide to take patch 1, because the logic is used only by git-run-with-user-path which is a new program. no Porcelain uses right now.
Re: [PATCH 1/2] Introduce git-run-with-user-path helper program.
A new command git-run-with-user-path takes a command and paths that are filesystem paths (either relative to the cwd or absolute pathname). It canonicalizes these paths to be usable by the core GIT commands, filters using the ignore pattern rule, chdir(2)'s to the top level of the tree and runs the given command with these canonicalizd paths as its arguments.
This version contains necessary hooks to implement the ignore pattern rule, but it does not implement any ignore pattern rules, waiting for more mailing list discussions.
---
Documentation/git-run-with-user-path.txt | 100 +++++++++++++++ Makefile | 7 - paths.c | 199 +++++++++++++++++++++++++++++++ paths.h | 14 ++ run-with-user-path.c | 87 +++++++++++++ t/README | 1 t/t7000-git-run-with-user-path-basic.sh | 87 +++++++++++++ update-cache.c | 29 ---- 8 files changed, 495 insertions(+), 29 deletions(-)
Documentation/git-run-with-user-path.txt (. --> 100644) paths.c (. --> 100644)paths.h (. --> 100644)run-with-user-path.c (. --> 100644) t/t7000-git-run-with-user-path-basic.sh (. --> 100755)
Documentation/git-run-with-user-path.txt new file +100 -0
@@ -0,0 +1,100 @@ +git-run-with-user-path(1) +========================= +v0.1, May 2005 + +NAME +---- +git-run-with-user-path - Run command from the top after canonicalizing paths. + + +SYNOPSIS +-------- +'git-run-with-user-path' [options] <command> <argument>... '--' <path>... +'git-run-with-user-path' [options] ( '--echo-z' | '--echo' ) <path>... + +DESCRIPTION +----------- +In the first form, this command takes a <command>, zero or more +<argument> and zero or more <path> arguments. <path> arguments name +objects on the filesystem, <command> is typically a core GIT command, +and <argument> are the initial arguments to the <command>. + +It first finds the project top directory (the directory that corresponds +to the top of the tree structure GIT_INDEX_FILE describes). When the +environment variable GIT_PROJECT_TOP is set, the value of the variable +is used. Then the <path> parameters are canonicalized to be relative to +the project top. It then chdir(2)'s to the project top directory and +runs the given <command>, with <argument> and these canonicalized <path> +arguments. + +This is useful for the Porcelain layer to run core GIT commands from +subdirectories. For example, if linux-2.6.git tree is checked out in +/usr/src/linux, you can do: + + $ cd /usr/src/linux/fs + $ ... work in fs directory making changes ... + $ git-run-with-user-path git-diff-tree -r HEAD -- ext? ../include/linux + $ find ext? ../include/linux ! -type d -print0 | + xargs -0 git-run-with-user-path git-update-cache --add -- -- + +The above is roughly equivalent to: + + $ cd /usr/src/linux + $ git-diff-tree -r HEAD fs/ext? include/linux + $ find fs/ext? include/linux ! -type d -print0 | + xargs git-update-cache --add -- + +In the second form, this command just canonicalizes and filters paths, +and writes the resulting paths to the standard output. '--echo' +separates each output record with a newline while '--echo-z' uses NUL as +the record separator. + + $ find ext? ../include/linux ! -type d -print0 | + xargs -0 git-run-with-user-path --echo --show-ignore + +This example gives you the list of ignored files, one per line. It is +roughly equivalent to: + + $ find ext? ../include/linux ! -type d -print0 | + xargs -0 -n1 git-run-with-user-path --show-ignore echo -- + + +OPTIONS +------- + +--no-ignore:: + + By default, the path arguments are filtered with the same ignore + rules Porcelain layers use. With --no-ignore flag, there is no + such filtering done. + +--show-ignore:: + + This causes the filter to be applied in reverse. Only the paths + ignored by the ignore rules are passed to the command (or + output). + + +ENVIRONMENT VARIABLES +--------------------- + +'GIT_PROJECT_TOP':: + If the 'GIT_PROJECT_TOP' environment variable is set then it + specifies the directory that corresponds to the top level of the + tree structure GIT_INDEX_FILE describes. When this environment + variable is not defined, the closest parent directory that has + .git/ subdirectory in it is looked for and used. + + +Author +------ +Written by Junio C Hamano <[email protected]> + +Documentation +-------------- +Documentation by Junio C Hamano. + +GIT +--- +Part of the link:git.html[git] suite +
Makefile +6 -1
@@ -28,7 +28,7 @@ git-unpack-file git-export git-diff-cache git-convert-cache \ git-http-pull git-rpush git-rpull git-rev-list git-mktag \ git-diff-helper git-tar-tree git-local-pull git-write-blob \ - git-get-tar-commit-id + git-get-tar-commit-id git-run-with-user-path all: $(PROG)
@@ -46,6 +46,9 @@ LIB_H += diff.h LIB_OBJS += diff.o +LIB_H += paths.h +LIB_OBJS += paths.o + LIB_OBJS += gitenv.o LIBS = $(LIB_FILE)
@@ -100,6 +103,7 @@ git-rpush: rsh.c git-rpull: rsh.c pull.c git-rev-list: rev-list.c +git-run-with-user-path: run-with-user-path.c git-mktag: mktag.c git-diff-helper: diff-helper.c git-tar-tree: tar-tree.c
@@ -117,6 +121,7 @@ sha1_file.o: $(LIB_H) usage.o: $(LIB_H) diff.o: $(LIB_H) +paths.o: $(LIB_H) strbuf.o: $(LIB_H) gitenv.o: $(LIB_H)
paths.c new file +199 -0
199 lines not on this page · raw message
paths.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Copyright (c) 2005 Junio C Hamano +*/ +#ifndef _PATHS_H_ +#define _PATHS_H_ + +int setup_paths (void ); +extern char *git_project_top; + +char *canon_path (const char *); +int path_ignored (const char *); +int verify_path (const char *); + +#endif
run-with-user-path.c new file +87 -0
87 lines not on this page · raw message
t/README +1 -0
@@ -73,6 +73,7 @@ 4 - the diff commands 5 - the pull and exporting commands 6 - the revision tree commands (even e.g. merge-base) + 7 - the non-core commands and helpers Second digit tells the particular command we are testing.
t/t7000-git-run-with-user-path-basic.sh new file +87 -0
87 lines not on this page · raw message
update-cache.c +1 -28
@@ -5,6 +5,7 @@*/ #include <signal.h> #include "cache.h" +#include "paths.h" /* * Default to not allowing changes to the list of files. The
@@ -257,34 +258,6 @@return has_errors; } -/* -* We fundamentally don't like some paths: we don't want -* dot or dot-dot anywhere, and in fact, we don't even want -* any other dot-files (.git or anything else). They -* are hidden, for chist sake. -* -* Also, we don't want double slashes or slashes at the -* end that can make pathnames ambiguous. -*/ -static int verify_path (char *path) -{ -char c; - - goto inside; -for (;;) { -if (!c) -return 1 ; -if (c =='/' ) { -inside: - c = *path++; -if (c !='/' && c !='.' && c !='\0' ) -continue ; -return 0 ; - } - c = *path++; - } -} -static int add_cacheinfo (char *arg1,char *arg2,char *arg3) {int size, len, option;
------------------------------------------------
Re: [PATCH 1/2] Introduce git-run-with-user-path helper program.
*Blush*. I sent out a bad copy for this patch.
In run-with-user-path.c, in main():
+ /* We need to special case -- (end of command) followed
+ * immediately by -- (beginning of paths); otherwise
+ * "git-run-with-user-path git-update-cache --add -- -- foo"
+ * would try canonicalize and filter path arguments starting
+ * from -- (beginning of paths), which is not what we want.
+ */
+ if (!strcmp(av[command_end + 1], "--")) {
+ exec_param[command_end-1] = av[command_end + 1];
+ command_end++;
+ }
The above if() statement should be:
if (command_end + 1 < ac && !strcmp(av[command_end + 1], "--")) {Otherwise "./git-run-with-user-path echo --" would segfault. Sorry about the noise.
PATCH 2/2 Add sample ignore logic to git-run-with-user-path command.
In reply to Junio C HamanoThis adds a sample ignore file logic to git-run-with-user-path command. This is primarily to serve as an example for plugging ignore file logic to the previously introduced framework, and to spur mailing list discussions on what the final ignore file logic should be, and where the information should come from.
---
Documentation/git-run-with-user-path.txt | 32 ++++++++ Makefile | 6 + paths.c | 117 +++++++++++++++++++++++++++++-- t/t7001-git-run-with-user-path-ignore.sh | 67 +++++++++++++++++ 4 files changed, 215 insertions(+), 7 deletions(-)
t/t7001-git-run-with-user-path-ignore.sh (. --> 100755)
Documentation/git-run-with-user-path.txt +32 -0
@@ -75,6 +75,38 @@ output). +IGNORE FILES +------------ + +This command currently uses a pcre based implementation to express +ignore patterns. The purpose of this implementation is to primarily +serve as an example and to start GIT mailing list discussions, and by no +means is cast in stone. This section describes what this sample +implementation does. + +The information used to define which paths to ignore is read from two +files. Both files use the same syntax. + +First, $CIT_DIR/ignore is read. Then, the file whose path (relative to +the project top) recorded in $GIT_DIR/info/ignore-file is read next. +The latter file is expected to be revision controlled with GIT. + +These two files should record one ignore record per line. A line that +is empty, and a line that starts with a '#' are ignored and used as +comments. + +Each ignore record is a pcre regular expression, optionally prefixed +with a '!'. To determine if a path is to be ignored, the path is +matched against each ignore record in the order they appear in the +ignore file. If the ignore record matches the path, and it does not +have the optional '!', then the path is ignored. Otherwise, the path is +not ignored. In either case, the rest of ignore records are not used +after the first match. This means (1) an earlier entry in an ignore +file has precedence over later ones, and (2) the entries in +$GIT_DIR/ignore file have precedence over the ones in the file named +by $GIT_DIR/info/ignore-file. + + ENVIRONMENT VARIABLES ---------------------
Makefile +6 -0
@@ -54,6 +54,12 @@ LIBS = $(LIB_FILE) LIBS += -lz +IGNORE_USING_PCRE=1 + +ifdef IGNORE_USING_PCRE + LIBS += -lpcreposix +endif + ifdef MOZILLA_SHA1 SHA1_HEADER="mozilla-sha1/sha1.h" LIB_OBJS += mozilla-sha1/sha1.o
paths.c +110 -7
139 lines not on this page · raw message
t/t7001-git-run-with-user-path-ignore.sh new file +67 -0
67 lines not on this page · raw message
------------------------------------------------