rehabilitate 'git index-pack' inside the object store
Before commit d0b92a3f6e it was possible to run 'git index-pack' directly in the .git/objects/pack/ directory. Restore that ability. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Oct 20, 2008 at 21:17 UTC
a672ea6ac5a1b876bc7adfe6534b16fa2a32c94b
2 files changed
+29
-3
index-pack.c
+19
-3
@@ -879,10 +879,26 @@ int main(int argc, char **argv)
879
char *index_name_buf = NULL, *keep_name_buf = NULL;
880
struct pack_idx_entry **idx_objects;
881
unsigned char pack_sha1[20];
882
- int nongit = 0;
882
884
- setup_git_directory_gently(&nongit);
885
- git_config(git_index_pack_config, NULL);
883
+ /*
884
+ * We wish to read the repository's config file if any, and
885
+ * for that it is necessary to call setup_git_directory_gently().
886
+ * However if the cwd was inside .git/objects/pack/ then we need
887
+ * to go back there or all the pack name arguments will be wrong.
888
+ * And in that case we cannot rely on any prefix returned by
889
+ * setup_git_directory_gently() either.
890
+ */
891
+ {
892
+ char cwd[PATH_MAX+1];
893
+ int nongit;
894
+
895
+ if (!getcwd(cwd, sizeof(cwd)-1))
896
+ die("Unable to get current working directory");
897
+ setup_git_directory_gently(&nongit);
898
+ git_config(git_index_pack_config, NULL);
899
+ if (chdir(cwd))
900
+ die("Cannot come back to cwd");
901
+ }
902
903
for (i = 1; i < argc; i++) {
904
char *arg = argv[i];
t/t5302-pack-index.sh
+10
@@ -177,4 +177,14 @@ test_expect_success \
177
".git/objects/pack/pack-${pack1}.pack" 2>&1) &&
178
echo "$err" | grep "CRC mismatch"'
179
180
+test_expect_success 'running index-pack in the object store' '
181
+ rm -f .git/objects/pack/* &&
182
+ cp test-1-${pack1}.pack .git/objects/pack/pack-${pack1}.pack &&
183
+ (
184
+ cd .git/objects/pack
185
+ git index-pack pack-${pack1}.pack
186
+ ) &&
187
+ test -f .git/objects/pack/pack-${pack1}.idx
188
+'
189
+
190
test_done