* [PATCH 1/3] worktree setup: calculate prefix even if no worktree is found
@ 2010-03-08 16:50 Nguyễn Thái Ngọc Duy
2010-03-08 16:50 ` [PATCH 2/3] index-pack: trust the prefix returned by setup_git_directory_gently() Nguyễn Thái Ngọc Duy
2010-03-08 16:50 ` [PATCH 3/3] index-pack: use RUN_SETUP_GENTLY Nguyễn Thái Ngọc Duy
0 siblings, 2 replies; 3+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-03-08 16:50 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy
Commit a672ea6 (rehabilitate 'git index-pack' inside the object
store - 2008-10-20) worked around a fault in
setup_git_directory_gently(). When walking up from inside a git
repository, we will return NULL as prefix. We should have returned a
correct prefix anyway because cwd has been moved.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
I missed index-pack in my RUN_SETUP_GENTLY series. So three more patches
on top.
setup.c | 19 ++++++++-----------
t/t1500-rev-parse.sh | 2 +-
t/t1501-worktree.sh | 5 +++++
3 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/setup.c b/setup.c
index bb3648c..8796c6f 100644
--- a/setup.c
+++ b/setup.c
@@ -392,13 +392,16 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
offset = len = strlen(cwd);
for (;;) {
gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
- if (gitfile_dir) {
- if (set_git_dir(gitfile_dir))
+ if (gitfile_dir || is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT)) {
+ if (gitfile_dir && set_git_dir(gitfile_dir))
die("Repository setup failed");
+ inside_git_dir = 0;
+ if (!work_tree_env)
+ inside_work_tree = 1;
+ root_len = offset_1st_component(cwd);
+ git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
break;
}
- if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
- break;
if (is_git_directory(".")) {
inside_git_dir = 1;
if (!work_tree_env)
@@ -409,8 +412,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
set_git_dir(cwd);
} else
set_git_dir(".");
- check_repository_format_gently(nongit_ok);
- return NULL;
+ break;
}
while (--offset > ceil_offset && cwd[offset] != '/');
if (offset <= ceil_offset) {
@@ -426,11 +428,6 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
die_errno("Cannot change to '%s/..'", cwd);
}
- inside_git_dir = 0;
- if (!work_tree_env)
- inside_work_tree = 1;
- root_len = offset_1st_component(cwd);
- git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
if (check_repository_format_gently(nongit_ok))
return NULL;
if (offset == len)
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 48ee077..4ee92c7 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -42,7 +42,7 @@ test_rev_parse toplevel false false true '' .git
cd .git || exit 1
test_rev_parse .git/ false true false '' .
cd objects || exit 1
-test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
+test_rev_parse .git/objects/ false true false 'objects/' "$ROOT/.git"
cd ../.. || exit 1
mkdir -p sub/dir || exit 1
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 9df3012..c72b578 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -28,6 +28,11 @@ test_rev_parse() {
[ $# -eq 0 ] && return
}
+cd .git/objects || exit 1
+say "subdirectory inside .git"
+test_rev_parse 'inside' false true false objects/
+cd ../.. || exit 1
+
EMPTY_TREE=$(git write-tree)
mkdir -p work/sub/dir || exit 1
mv .git repo.git || exit 1
--
1.7.0.1.384.g6abcaa
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/3] index-pack: trust the prefix returned by setup_git_directory_gently()
2010-03-08 16:50 [PATCH 1/3] worktree setup: calculate prefix even if no worktree is found Nguyễn Thái Ngọc Duy
@ 2010-03-08 16:50 ` Nguyễn Thái Ngọc Duy
2010-03-08 16:50 ` [PATCH 3/3] index-pack: use RUN_SETUP_GENTLY Nguyễn Thái Ngọc Duy
1 sibling, 0 replies; 3+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-03-08 16:50 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/index-pack.c | 21 ++++++---------------
1 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b4cf8c5..2a6359d 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -879,29 +879,20 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
char *index_name_buf = NULL, *keep_name_buf = NULL;
struct pack_idx_entry **idx_objects;
unsigned char pack_sha1[20];
+ int nongit;
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(index_pack_usage);
/*
- * We wish to read the repository's config file if any, and
- * for that it is necessary to call setup_git_directory_gently().
+ * We wish to read the repository's config file if any.
* However if the cwd was inside .git/objects/pack/ then we need
* to go back there or all the pack name arguments will be wrong.
- * And in that case we cannot rely on any prefix returned by
- * setup_git_directory_gently() either.
*/
- {
- char cwd[PATH_MAX+1];
- int nongit;
-
- if (!getcwd(cwd, sizeof(cwd)-1))
- die("Unable to get current working directory");
- setup_git_directory_gently(&nongit);
- git_config(git_index_pack_config, NULL);
- if (chdir(cwd))
- die("Cannot come back to cwd");
- }
+ prefix = setup_git_directory_gently(&nongit);
+ git_config(git_index_pack_config, NULL);
+ if (prefix && chdir(prefix))
+ die("Cannot come back to cwd");
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
--
1.7.0.1.384.g6abcaa
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] index-pack: use RUN_SETUP_GENTLY
2010-03-08 16:50 [PATCH 1/3] worktree setup: calculate prefix even if no worktree is found Nguyễn Thái Ngọc Duy
2010-03-08 16:50 ` [PATCH 2/3] index-pack: trust the prefix returned by setup_git_directory_gently() Nguyễn Thái Ngọc Duy
@ 2010-03-08 16:50 ` Nguyễn Thái Ngọc Duy
1 sibling, 0 replies; 3+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-03-08 16:50 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/index-pack.c | 2 --
git.c | 2 +-
2 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2a6359d..9aa6a13 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -879,7 +879,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
char *index_name_buf = NULL, *keep_name_buf = NULL;
struct pack_idx_entry **idx_objects;
unsigned char pack_sha1[20];
- int nongit;
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(index_pack_usage);
@@ -889,7 +888,6 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
* However if the cwd was inside .git/objects/pack/ then we need
* to go back there or all the pack name arguments will be wrong.
*/
- prefix = setup_git_directory_gently(&nongit);
git_config(git_index_pack_config, NULL);
if (prefix && chdir(prefix))
die("Cannot come back to cwd");
diff --git a/git.c b/git.c
index 88408c8..746470f 100644
--- a/git.c
+++ b/git.c
@@ -332,7 +332,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "grep", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER },
{ "hash-object", cmd_hash_object, RUN_SETUP_GENTLY },
{ "help", cmd_help, RUN_SETUP_GENTLY },
- { "index-pack", cmd_index_pack },
+ { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY },
{ "init", cmd_init_db },
{ "init-db", cmd_init_db },
{ "log", cmd_log, RUN_SETUP | USE_PAGER },
--
1.7.0.1.384.g6abcaa
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-03-08 16:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-08 16:50 [PATCH 1/3] worktree setup: calculate prefix even if no worktree is found Nguyễn Thái Ngọc Duy
2010-03-08 16:50 ` [PATCH 2/3] index-pack: trust the prefix returned by setup_git_directory_gently() Nguyễn Thái Ngọc Duy
2010-03-08 16:50 ` [PATCH 3/3] index-pack: use RUN_SETUP_GENTLY Nguyễn Thái Ngọc Duy
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).