Skip to content

Commit a672ea6

Browse files
Nicolas Pitregitster
authored andcommitted
rehabilitate 'git index-pack' inside the object store
Before commit d0b92a3 it was possible to run 'git index-pack' directly in the .git/objects/pack/ directory. Restore that ability. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5610e3b commit a672ea6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

index-pack.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,10 +879,26 @@ int main(int argc, char **argv)
879879
char *index_name_buf = NULL, *keep_name_buf = NULL;
880880
struct pack_idx_entry **idx_objects;
881881
unsigned char pack_sha1[20];
882-
int nongit = 0;
883882

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+
}
886902

887903
for (i = 1; i < argc; i++) {
888904
char *arg = argv[i];

t/t5302-pack-index.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,14 @@ test_expect_success \
177177
".git/objects/pack/pack-${pack1}.pack" 2>&1) &&
178178
echo "$err" | grep "CRC mismatch"'
179179

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+
180190
test_done

0 commit comments

Comments
 (0)