From 4ca0660816671f65546626b6e2c2038b6a347a8b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 25 Nov 2005 23:14:15 -0800 Subject: [PATCH 01/17] working from subdirectory: preparation - prefix_filename() is like prefix_path() but can be used to name any file on the filesystem, not the files that might go into the index file. - setup_git_directory_gently() tries to find the GIT_DIR, but does not die() if called outside a git repository. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ setup.c | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index 634b5aa69c..f9b367f314 100644 --- a/cache.h +++ b/cache.h @@ -147,8 +147,10 @@ extern char *get_graft_file(void); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" extern const char **get_pathspec(const char *prefix, const char **pathspec); +extern const char *setup_git_directory_gently(int *); extern const char *setup_git_directory(void); extern const char *prefix_path(const char *prefix, int len, const char *path); +extern const char *prefix_filename(const char *prefix, int len, const char *path); #define alloc_nr(x) (((x)+16)*3/2) diff --git a/setup.c b/setup.c index cc44a724bf..bde590f7cc 100644 --- a/setup.c +++ b/setup.c @@ -47,6 +47,21 @@ const char *prefix_path(const char *prefix, int len, const char *path) return path; } +/* + * Unlike prefix_path, this should be used if the named file does + * not have to interact with index entry; i.e. name of a random file + * on the filesystem. + */ +const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) +{ + static char path[PATH_MAX]; + if (!pfx || !*pfx || arg[0] == '/') + return arg; + memcpy(path, pfx, pfx_len); + strcpy(path + pfx_len, arg); + return path; +} + const char **get_pathspec(const char *prefix, const char **pathspec) { const char *entry = *pathspec; @@ -92,7 +107,7 @@ static int is_toplevel_directory(void) return 1; } -static const char *setup_git_directory_1(void) +const char *setup_git_directory_gently(int *nongit_ok) { static char cwd[PATH_MAX+1]; int len, offset; @@ -139,8 +154,15 @@ static const char *setup_git_directory_1(void) break; chdir(".."); do { - if (!offset) + if (!offset) { + if (nongit_ok) { + if (chdir(cwd)) + die("Cannot come back to cwd"); + *nongit_ok = 1; + return NULL; + } die("Not a git repository"); + } } while (cwd[--offset] != '/'); } @@ -172,7 +194,7 @@ int check_repository_format(void) const char *setup_git_directory(void) { - const char *retval = setup_git_directory_1(); + const char *retval = setup_git_directory_gently(NULL); check_repository_format(); return retval; } From edf2e37002eeb30a2ccad5db3b3e1fe41cdc7eb0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 25 Nov 2005 23:14:15 -0800 Subject: [PATCH 02/17] git-apply: work from subdirectory. When applying a patch to index file, we need to know where GIT_DIR is; use setup_git_directory() to find it out. This also allows us to work from a subdirectory if we wanted to. When git-apply is run from a subdirectory, it applies the given patch only to the files under the current directory and below. Signed-off-by: Junio C Hamano --- apply.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apply.c b/apply.c index 50be8f3e22..1742ab28e9 100644 --- a/apply.c +++ b/apply.c @@ -16,6 +16,9 @@ // --numstat does numeric diffstat, and doesn't actually apply // --index-info shows the old and new index info for paths if available. // +static const char *prefix; +static int prefix_length = -1; + static int allow_binary_replacement = 0; static int check_index = 0; static int write_index = 0; @@ -1706,6 +1709,12 @@ static int use_patch(struct patch *p) return 0; x = x->next; } + if (0 < prefix_length) { + int pathlen = strlen(pathname); + if (pathlen <= prefix_length || + memcmp(prefix, pathname, prefix_length)) + return 0; + } return 1; } @@ -1845,6 +1854,15 @@ int main(int argc, char **argv) line_termination = 0; continue; } + + if (check_index && prefix_length < 0) { + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; + git_config(git_default_config); + } + if (0 < prefix_length) + arg = prefix_filename(prefix, prefix_length, arg); + fd = open(arg, O_RDONLY); if (fd < 0) usage(apply_usage); From e44eb3e4c74c5f6c1fca1cf92ddb454ad248c24c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 25 Nov 2005 23:50:21 -0800 Subject: [PATCH 03/17] peek-remote: honor proxy config even from subdirectory. Use setup_git_directory_gently() at the beginning of peek-remote so that git:// proxy can be picked up from the configuration file. Signed-off-by: Junio C Hamano --- peek-remote.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/peek-remote.c b/peek-remote.c index ee49bf3b7b..a90cf22069 100644 --- a/peek-remote.c +++ b/peek-remote.c @@ -27,6 +27,9 @@ int main(int argc, char **argv) char *dest = NULL; int fd[2]; pid_t pid; + int nongit = 0; + + setup_git_directory_gently(&nongit); for (i = 1; i < argc; i++) { char *arg = argv[i]; From 61e2b01529d4cb4138c00a653006d16f7a9179ce Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 25 Nov 2005 23:52:04 -0800 Subject: [PATCH 04/17] fsck-objects: work from subdirectory. Not much point making it work from subdirectory, but for a consistency make it so. Signed-off-by: Junio C Hamano --- fsck-objects.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fsck-objects.c b/fsck-objects.c index 0433a1d0da..90e638e573 100644 --- a/fsck-objects.c +++ b/fsck-objects.c @@ -431,6 +431,8 @@ int main(int argc, char **argv) { int i, heads; + setup_git_directory(); + for (i = 1; i < argc; i++) { const char *arg = argv[i]; From c3e9a6534c88767e2ad9126ed45598157c28d1f4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 26 Nov 2005 00:22:48 -0800 Subject: [PATCH 05/17] checkout-index: work from subdirectory. With this, git-checkout-index from a subdirectory works as expected. Note that "git-checkout-index -a" checks out files only in the current directory and under. Signed-off-by: Junio C Hamano --- checkout-index.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/checkout-index.c b/checkout-index.c index dab3778a95..f1e716d412 100644 --- a/checkout-index.c +++ b/checkout-index.c @@ -34,6 +34,9 @@ */ #include "cache.h" +static const char *prefix; +static int prefix_length; + static struct checkout state = { .base_dir = "", .base_dir_len = 0, @@ -69,6 +72,10 @@ static int checkout_all(void) struct cache_entry *ce = active_cache[i]; if (ce_stage(ce)) continue; + if (prefix && *prefix && + ( ce_namelen(ce) <= prefix_length || + memcmp(prefix, ce->name, prefix_length) )) + continue; if (checkout_entry(ce, &state) < 0) errs++; } @@ -91,6 +98,9 @@ int main(int argc, char **argv) int newfd = -1; int all = 0; + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; + if (read_cache() < 0) { die("invalid cache"); } @@ -155,7 +165,7 @@ int main(int argc, char **argv) if (all) die("git-checkout-index: don't mix '--all' and explicit filenames"); - checkout_file(arg); + checkout_file(prefix_path(prefix, prefix_length, arg)); } if (all) From 706fe6ae03e2c1452d59892944701c56237b903f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 26 Nov 2005 00:30:07 -0800 Subject: [PATCH 06/17] hash-object: work within subdirectory. When -w is given, it needs to find out where the .git directory is, so run the setup_git_directory() when we see a -w. Signed-off-by: Junio C Hamano --- hash-object.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/hash-object.c b/hash-object.c index c8c9adb3aa..c3d05a853a 100644 --- a/hash-object.c +++ b/hash-object.c @@ -29,6 +29,8 @@ int main(int argc, char **argv) int i; const char *type = "blob"; int write_object = 0; + const char *prefix; + int prefix_length = -1; for (i = 1 ; i < argc; i++) { if (!strcmp(argv[i], "-t")) { @@ -36,10 +38,20 @@ int main(int argc, char **argv) die(hash_object_usage); type = argv[i]; } - else if (!strcmp(argv[i], "-w")) + else if (!strcmp(argv[i], "-w")) { + if (prefix_length < 0) { + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; + } write_object = 1; - else - hash_object(argv[i], type, write_object); + } + else { + char *arg = argv[i]; + if (0 <= prefix_length) + arg = prefix_filename(prefix, prefix_length, + arg); + hash_object(arg, type, write_object); + } } return 0; } From b191fa72ea501c0789fb1bd7a80fcec9da38804d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 26 Nov 2005 00:40:50 -0800 Subject: [PATCH 07/17] ls-tree: work from subdirectory. This makes ls-tree to work from subdirectory. It defaults to show the paths under the current subdirectory, and interprets user-supplied paths as relative to the current subdirectory. Signed-off-by: Junio C Hamano --- ls-tree.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ls-tree.c b/ls-tree.c index d7c7e750fb..cf4223f4bf 100644 --- a/ls-tree.c +++ b/ls-tree.c @@ -206,7 +206,7 @@ static int list_one(const char *path) return err; } -static int list(char **path) +static int list(const char **path) { int i; int err = 0; @@ -218,11 +218,16 @@ static int list(char **path) static const char ls_tree_usage[] = "git-ls-tree [-d] [-r] [-z] [path...]"; -int main(int argc, char **argv) +int main(int argc, const char **argv) { - static char *path0[] = { "", NULL }; - char **path; + static const char *path0[] = { "", NULL }; + const char **path; unsigned char sha1[20]; + int nongit = 0; + const char *prefix = setup_git_directory_gently(&nongit); + + if (prefix) + path0[0] = prefix; while (1 < argc && argv[1][0] == '-') { switch (argv[1][1]) { @@ -246,7 +251,11 @@ int main(int argc, char **argv) if (get_sha1(argv[1], sha1) < 0) usage(ls_tree_usage); - path = (argc == 2) ? path0 : (argv + 2); + if (argc == 2) + path = path0; + else + path = get_pathspec(prefix, argv + 2); + prepare_root(sha1); if (list(path) < 0) die("list failed"); From 5a3277133d200151fe526e56e036c933d343958a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 26 Nov 2005 00:47:59 -0800 Subject: [PATCH 08/17] Make networking commands to work from a subdirectory. These are whole-tree operations and there is not much point making them operable from within a subdirectory, but it is easy to do so, and using setup_git_directory() upfront helps git:// proxy specification picked up from the correct place. Signed-off-by: Junio C Hamano --- clone-pack.c | 2 ++ fetch-pack.c | 2 ++ http-fetch.c | 2 ++ http-push.c | 1 + local-fetch.c | 2 ++ send-pack.c | 1 + ssh-fetch.c | 2 ++ ssh-upload.c | 3 +++ 8 files changed, 15 insertions(+) diff --git a/clone-pack.c b/clone-pack.c index 960921903e..a99a95c5f2 100644 --- a/clone-pack.c +++ b/clone-pack.c @@ -271,6 +271,8 @@ int main(int argc, char **argv) int fd[2]; pid_t pid; + setup_git_directory(); + nr_heads = 0; heads = NULL; for (i = 1; i < argc; i++) { diff --git a/fetch-pack.c b/fetch-pack.c index 6565982660..58ba2094dc 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -424,6 +424,8 @@ int main(int argc, char **argv) int fd[2]; pid_t pid; + setup_git_directory(); + nr_heads = 0; heads = NULL; for (i = 1; i < argc; i++) { diff --git a/http-fetch.c b/http-fetch.c index 435317342b..ad59f1cce6 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -922,6 +922,8 @@ int main(int argc, char **argv) int arg = 1; int rc = 0; + setup_git_directory(); + while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 't') { get_tree = 1; diff --git a/http-push.c b/http-push.c index ad789829c1..c6e782cbed 100644 --- a/http-push.c +++ b/http-push.c @@ -1239,6 +1239,7 @@ int main(int argc, char **argv) int rc = 0; int i; + setup_git_directory(); setup_ident(); remote = xmalloc(sizeof(*remote)); diff --git a/local-fetch.c b/local-fetch.c index 0931109143..fa9e697fd3 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -207,6 +207,8 @@ int main(int argc, char **argv) char *commit_id; int arg = 1; + setup_git_directory(); + while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 't') get_tree = 1; diff --git a/send-pack.c b/send-pack.c index 3eeb18f7c7..2a14b00845 100644 --- a/send-pack.c +++ b/send-pack.c @@ -273,6 +273,7 @@ int main(int argc, char **argv) int fd[2], ret; pid_t pid; + setup_git_directory(); argv++; for (i = 1; i < argc; i++, argv++) { char *arg = *argv; diff --git a/ssh-fetch.c b/ssh-fetch.c index bf01fbc00d..4eb9e04829 100644 --- a/ssh-fetch.c +++ b/ssh-fetch.c @@ -131,6 +131,8 @@ int main(int argc, char **argv) prog = getenv("GIT_SSH_PUSH"); if (!prog) prog = "git-ssh-upload"; + setup_git_directory(); + while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 't') { get_tree = 1; diff --git a/ssh-upload.c b/ssh-upload.c index 603abcc8c3..b675a0b1f1 100644 --- a/ssh-upload.c +++ b/ssh-upload.c @@ -121,6 +121,9 @@ int main(int argc, char **argv) prog = getenv(COUNTERPART_ENV_NAME); if (!prog) prog = COUNTERPART_PROGRAM_NAME; + + setup_git_directory(); + while (arg < argc && argv[arg][0] == '-') { if (argv[arg][1] == 'w') arg++; From 53228a5fb8e80f87803e4a3ba8ed25b70fb4871d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 26 Nov 2005 00:50:02 -0800 Subject: [PATCH 09/17] Make the rest of commands work from a subdirectory. These commands are converted to run from a subdirectory. commit-tree convert-objects merge-base merge-index mktag pack-objects pack-redundant prune-packed read-tree tar-tree unpack-file unpack-objects update-server-info write-tree Signed-off-by: Junio C Hamano --- commit-tree.c | 2 ++ convert-objects.c | 2 ++ merge-base.c | 2 ++ merge-index.c | 1 + mktag.c | 2 ++ pack-objects.c | 2 ++ pack-redundant.c | 2 ++ prune-packed.c | 2 ++ read-tree.c | 2 ++ tar-tree.c | 2 ++ unpack-file.c | 2 ++ unpack-objects.c | 2 ++ update-server-info.c | 2 ++ write-tree.c | 5 ++++- 14 files changed, 29 insertions(+), 1 deletion(-) diff --git a/commit-tree.c b/commit-tree.c index b60299fed0..4634b50e6a 100644 --- a/commit-tree.c +++ b/commit-tree.c @@ -91,6 +91,8 @@ int main(int argc, char **argv) if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0) usage(commit_tree_usage); + setup_git_directory(); + check_valid(tree_sha1, "tree"); for (i = 2; i < argc; i += 2) { char *a, *b; diff --git a/convert-objects.c b/convert-objects.c index a892013f0f..d78a8b4ae3 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -316,6 +316,8 @@ int main(int argc, char **argv) unsigned char sha1[20]; struct entry *entry; + setup_git_directory(); + if (argc != 2 || get_sha1(argv[1], sha1)) usage("git-convert-objects "); diff --git a/merge-base.c b/merge-base.c index 751c3c281b..e73fca7453 100644 --- a/merge-base.c +++ b/merge-base.c @@ -236,6 +236,8 @@ int main(int argc, char **argv) struct commit *rev1, *rev2; unsigned char rev1key[20], rev2key[20]; + setup_git_directory(); + while (1 < argc && argv[1][0] == '-') { char *arg = argv[1]; if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) diff --git a/merge-index.c b/merge-index.c index 727527fd59..024196e7ac 100644 --- a/merge-index.c +++ b/merge-index.c @@ -102,6 +102,7 @@ int main(int argc, char **argv) if (argc < 3) usage("git-merge-index [-o] [-q] (-a | *)"); + setup_git_directory(); read_cache(); i = 1; diff --git a/mktag.c b/mktag.c index 585677eb83..97e270a576 100644 --- a/mktag.c +++ b/mktag.c @@ -111,6 +111,8 @@ int main(int argc, char **argv) if (argc != 1) usage("cat | git-mktag"); + setup_git_directory(); + // Read the signature size = 0; for (;;) { diff --git a/pack-objects.c b/pack-objects.c index 8864a31cc1..a62c9f8d18 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -473,6 +473,8 @@ int main(int argc, char **argv) struct object_entry **list; int i; + setup_git_directory(); + for (i = 1; i < argc; i++) { const char *arg = argv[i]; diff --git a/pack-redundant.c b/pack-redundant.c index 793fa08096..0a43278924 100644 --- a/pack-redundant.c +++ b/pack-redundant.c @@ -600,6 +600,8 @@ int main(int argc, char **argv) unsigned char *sha1; char buf[42]; /* 40 byte sha1 + \n + \0 */ + setup_git_directory(); + for (i = 1; i < argc; i++) { const char *arg = argv[i]; if(!strcmp(arg, "--")) { diff --git a/prune-packed.c b/prune-packed.c index 26123f7f6b..d24b097114 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -58,6 +58,8 @@ int main(int argc, char **argv) { int i; + setup_git_directory(); + for (i = 1; i < argc; i++) { const char *arg = argv[i]; diff --git a/read-tree.c b/read-tree.c index df156ea0da..e3b9c0d9fa 100644 --- a/read-tree.c +++ b/read-tree.c @@ -629,6 +629,8 @@ int main(int argc, char **argv) unsigned char sha1[20]; merge_fn_t fn = NULL; + setup_git_directory(); + newfd = hold_index_file_for_update(&cache_file, get_index_file()); if (newfd < 0) die("unable to create new cachefile"); diff --git a/tar-tree.c b/tar-tree.c index 970c4bb54e..bacb23ae63 100644 --- a/tar-tree.c +++ b/tar-tree.c @@ -407,6 +407,8 @@ int main(int argc, char **argv) void *buffer; unsigned long size; + setup_git_directory(); + switch (argc) { case 3: basedir = argv[2]; diff --git a/unpack-file.c b/unpack-file.c index d4ac3a5460..07303f8bb3 100644 --- a/unpack-file.c +++ b/unpack-file.c @@ -29,6 +29,8 @@ int main(int argc, char **argv) if (argc != 2 || get_sha1(argv[1], sha1)) usage("git-unpack-file "); + setup_git_directory(); + puts(create_temp_file(sha1)); return 0; } diff --git a/unpack-objects.c b/unpack-objects.c index 8490895cf0..cfd61ae6b0 100644 --- a/unpack-objects.c +++ b/unpack-objects.c @@ -269,6 +269,8 @@ int main(int argc, char **argv) int i; unsigned char sha1[20]; + setup_git_directory(); + for (i = 1 ; i < argc; i++) { const char *arg = argv[i]; diff --git a/update-server-info.c b/update-server-info.c index e824f62eaf..0b6c3835bd 100644 --- a/update-server-info.c +++ b/update-server-info.c @@ -19,5 +19,7 @@ int main(int ac, char **av) if (i != ac) usage(update_server_info_usage); + setup_git_directory(); + return !!update_server_info(force); } diff --git a/write-tree.c b/write-tree.c index 2b2c6b77af..0aac32f227 100644 --- a/write-tree.c +++ b/write-tree.c @@ -86,9 +86,12 @@ static int write_tree(struct cache_entry **cachep, int maxentries, const char *b int main(int argc, char **argv) { int i, funny; - int entries = read_cache(); + int entries; unsigned char sha1[20]; + setup_git_directory(); + + entries = read_cache(); if (argc == 2) { if (!strcmp(argv[1], "--missing-ok")) missing_ok = 1; From 710b7098e28513355cbdbedbb8d9c35ce5b4a488 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 22:53:20 -0800 Subject: [PATCH 10/17] count-objects: make it operable from a subdirectory. Signed-off-by: Junio C Hamano --- git-count-objects.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-count-objects.sh b/git-count-objects.sh index d6e9a3221f..40c58efe08 100755 --- a/git-count-objects.sh +++ b/git-count-objects.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano # -. git-sh-setup +GIT_DIR=`git-rev-parse --git-dir` || exit $? dc /dev/null || { # This is not a real DC at all -- it just knows how From 1abacf3b5b53f6cde7148862234d451cd88d0de3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 23:15:02 -0800 Subject: [PATCH 11/17] ls-remote: define die() now we do not use git-sh-setup Another interesting "property" is that from inside a git managed tree, "git-ls-remote ." names the current repository no matter how deep a subdirectory you are in. Signed-off-by: Junio C Hamano --- git-ls-remote.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-ls-remote.sh b/git-ls-remote.sh index dc6a775a9b..f69926862f 100755 --- a/git-ls-remote.sh +++ b/git-ls-remote.sh @@ -6,6 +6,11 @@ usage () { exit 1; } +die () { + echo >&2 "$*" + exit 1 +} + while case "$#" in 0) break;; esac do case "$1" in From 9cc2527cd2943c82cf448dccec564869b0a762e6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 23:16:15 -0800 Subject: [PATCH 12/17] branch: make it operable from a subdirectory. Signed-off-by: Junio C Hamano --- git-branch.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/git-branch.sh b/git-branch.sh index 4cd5da16f7..b48c32988f 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -1,6 +1,6 @@ #!/bin/sh -. git-sh-setup +GIT_DIR=`git-rev-parse --git-dir` || exit $? usage () { echo >&2 "usage: $(basename $0)"' [-d ] | [[-f] [start-point]] @@ -12,8 +12,7 @@ If two arguments, create a new branch based off of . exit 1 } -headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD | - sed -e 's|^refs/heads/||') +headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||') delete_branch () { option="$1" @@ -114,4 +113,3 @@ then fi fi git update-ref "refs/heads/$branchname" $rev - From eefaa4fca79f5240eaefd0046a338dbdac8b4204 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 23:18:04 -0800 Subject: [PATCH 13/17] lost-found: make it operable from a subdirectory. Signed-off-by: Junio C Hamano --- git-lost-found.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git-lost-found.sh b/git-lost-found.sh index 9dd7430018..2beec2aa63 100755 --- a/git-lost-found.sh +++ b/git-lost-found.sh @@ -1,7 +1,6 @@ #!/bin/sh -. git-sh-setup - +GIT_DIR=`git-rev-parse --git-dir` || exit $? laf="$GIT_DIR/lost-found" rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit From 7ea2fc47d258657d673ce3b9403ed98cc50e2600 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 23:19:06 -0800 Subject: [PATCH 14/17] tag: make it operable from a subdirectory. Signed-off-by: Junio C Hamano --- git-tag.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tag.sh b/git-tag.sh index 16efc5b70a..e71028695c 100755 --- a/git-tag.sh +++ b/git-tag.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright (c) 2005 Linus Torvalds -. git-sh-setup +GIT_DIR=`git-rev-parse --git-dir` || exit $? usage () { echo >&2 "Usage: git-tag [-a | -s | -u ] [-f | -d] [-m ] []" From d6ea70af7708af5f29db09b2d782ab3b9ce50f79 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 23:19:58 -0800 Subject: [PATCH 15/17] verify-tag: make it operable from a subdirectory. Signed-off-by: Junio C Hamano --- git-verify-tag.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/git-verify-tag.sh b/git-verify-tag.sh index 3c65f4a6b5..d6e0eb87c3 100755 --- a/git-verify-tag.sh +++ b/git-verify-tag.sh @@ -1,5 +1,6 @@ #!/bin/sh -. git-sh-setup + +GIT_DIR=`git-rev-parse --git-dir` || exit $? type="$(git-cat-file -t "$1" 2>/dev/null)" || die "$1: no such object." @@ -7,6 +8,9 @@ type="$(git-cat-file -t "$1" 2>/dev/null)" || test "$type" = tag || die "$1: cannot verify a non-tag object of type $type." -git-cat-file tag "$1" > .tmp-vtag || exit 1 -cat .tmp-vtag | sed '/-----BEGIN PGP/Q' | gpg --verify .tmp-vtag - || exit 1 -rm -f .tmp-vtag +git-cat-file tag "$1" >"$GIT_DIR/.tmp-vtag" || exit 1 +cat "$GIT_DIR/.tmp-vtag" | +sed '/-----BEGIN PGP/Q' | +gpg --verify "$GIT_DIR/.tmp-vtag" - || exit 1 +rm -f "$GIT_DIR/.tmp-vtag" + From d165fa14f0a111dfc85d964ecc037d0b280cd54f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 27 Nov 2005 23:33:54 -0800 Subject: [PATCH 16/17] define die() for scripts that use it. As a fallout from not using git-sh-setup in scripts that can operate from a subdirectory, we lost definition of die() from them. It might make sense to do some cleanup to consolidate them back again, but this should suffice for now. Signed-off-by: Junio C Hamano --- git-add.sh | 5 +++++ git-branch.sh | 5 +++++ git-diff.sh | 5 +++++ git-merge-octopus.sh | 5 +++++ git-tag.sh | 5 +++++ git-verify-tag.sh | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/git-add.sh b/git-add.sh index b5fe46aa20..fdec86d1a4 100755 --- a/git-add.sh +++ b/git-add.sh @@ -1,5 +1,10 @@ #!/bin/sh +die () { + echo >&2 "$*" + exit 1 +} + usage() { die "usage: git add [-n] [-v] ..." } diff --git a/git-branch.sh b/git-branch.sh index b48c32988f..5306b2719f 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -2,6 +2,11 @@ GIT_DIR=`git-rev-parse --git-dir` || exit $? +die () { + echo >&2 "$*" + exit 1 +} + usage () { echo >&2 "usage: $(basename $0)"' [-d ] | [[-f] [start-point]] diff --git a/git-diff.sh b/git-diff.sh index b3ec84be69..e45f50ec22 100755 --- a/git-diff.sh +++ b/git-diff.sh @@ -9,6 +9,11 @@ files=$(git-rev-parse --no-revs --no-flags --sq "$@") : ${flags:="'-M' '-p'"} +die () { + echo >&2 "$*" + exit 1 +} + # I often say 'git diff --cached -p' and get scolded by git-diff-files, but # obviously I mean 'git diff --cached -p HEAD' in that case. case "$rev" in diff --git a/git-merge-octopus.sh b/git-merge-octopus.sh index bb58e22a18..7adffdc795 100755 --- a/git-merge-octopus.sh +++ b/git-merge-octopus.sh @@ -8,6 +8,11 @@ LF=' ' +die () { + echo >&2 "$*" + exit 1 +} + # The first parameters up to -- are merge bases; the rest are heads. bases= head= remotes= sep_seen= for arg diff --git a/git-tag.sh b/git-tag.sh index e71028695c..2435a75f7a 100755 --- a/git-tag.sh +++ b/git-tag.sh @@ -8,6 +8,11 @@ usage () { exit 1 } +die () { + echo >&2 "$*" + exit 1 +} + annotate= signed= force= diff --git a/git-verify-tag.sh b/git-verify-tag.sh index d6e0eb87c3..1f44da5349 100755 --- a/git-verify-tag.sh +++ b/git-verify-tag.sh @@ -2,6 +2,11 @@ GIT_DIR=`git-rev-parse --git-dir` || exit $? +die () { + echo >&2 "$*" + exit 1 +} + type="$(git-cat-file -t "$1" 2>/dev/null)" || die "$1: no such object." From 99e01692063cc48adee19e1f738472a579c14ca2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 28 Nov 2005 03:19:03 -0800 Subject: [PATCH 17/17] hash-object.c: type-fix to squelch compiler warnings. Signed-off-by: Junio C Hamano --- hash-object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hash-object.c b/hash-object.c index c3d05a853a..ccba11cb32 100644 --- a/hash-object.c +++ b/hash-object.c @@ -29,7 +29,7 @@ int main(int argc, char **argv) int i; const char *type = "blob"; int write_object = 0; - const char *prefix; + const char *prefix = NULL; int prefix_length = -1; for (i = 1 ; i < argc; i++) { @@ -46,7 +46,7 @@ int main(int argc, char **argv) write_object = 1; } else { - char *arg = argv[i]; + const char *arg = argv[i]; if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg);