Skip to content

Commit 30327a0

Browse files
committed
Merge branch 'ds/more-test-coverage'
Improve test coverage with a handful of tests. * ds/more-test-coverage: cache-tree: remove cache_tree_find_path() pack-write: drop always-NULL parameter t5329: test 'git gc --cruft' without '--prune=now' t2107: test 'git update-index --verbose'
2 parents 2fec2d2 + 86aa250 commit 30327a0

File tree

5 files changed

+34
-47
lines changed

5 files changed

+34
-47
lines changed

cache-tree.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,6 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *it, const char *path)
101101
return find_subtree(it, path, pathlen, 1);
102102
}
103103

104-
struct cache_tree *cache_tree_find_path(struct cache_tree *it, const char *path)
105-
{
106-
const char *slash;
107-
int namelen;
108-
struct cache_tree_sub it_sub = {
109-
.cache_tree = it,
110-
};
111-
struct cache_tree_sub *down = &it_sub;
112-
113-
while (down) {
114-
slash = strchrnul(path, '/');
115-
namelen = slash - path;
116-
down->cache_tree->entry_count = -1;
117-
if (!*slash) {
118-
int pos;
119-
pos = cache_tree_subtree_pos(down->cache_tree, path, namelen);
120-
if (0 <= pos)
121-
return down->cache_tree->down[pos]->cache_tree;
122-
return NULL;
123-
}
124-
down = find_subtree(it, path, namelen, 0);
125-
path = slash + 1;
126-
}
127-
128-
return NULL;
129-
}
130-
131104
static int do_invalidate_path(struct cache_tree *it, const char *path)
132105
{
133106
/* a/b/c

cache-tree.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
2929

3030
int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen);
3131

32-
struct cache_tree *cache_tree_find_path(struct cache_tree *it, const char *path);
33-
3432
void cache_tree_write(struct strbuf *, struct cache_tree *root);
3533
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
3634

pack-write.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,21 @@ static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash)
310310
hashwrite(f, hash, the_hash_algo->rawsz);
311311
}
312312

313-
static const char *write_mtimes_file(const char *mtimes_name,
314-
struct packing_data *to_pack,
313+
static const char *write_mtimes_file(struct packing_data *to_pack,
315314
struct pack_idx_entry **objects,
316315
uint32_t nr_objects,
317316
const unsigned char *hash)
318317
{
318+
struct strbuf tmp_file = STRBUF_INIT;
319+
const char *mtimes_name;
319320
struct hashfile *f;
320321
int fd;
321322

322323
if (!to_pack)
323324
BUG("cannot call write_mtimes_file with NULL packing_data");
324325

325-
if (!mtimes_name) {
326-
struct strbuf tmp_file = STRBUF_INIT;
327-
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
328-
mtimes_name = strbuf_detach(&tmp_file, NULL);
329-
} else {
330-
unlink(mtimes_name);
331-
fd = xopen(mtimes_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
332-
}
326+
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
327+
mtimes_name = strbuf_detach(&tmp_file, NULL);
333328
f = hashfd(fd, mtimes_name);
334329

335330
write_mtimes_header(f);
@@ -561,7 +556,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
561556
pack_idx_opts->flags);
562557

563558
if (pack_idx_opts->flags & WRITE_MTIMES) {
564-
mtimes_tmp_name = write_mtimes_file(NULL, to_pack, written_list,
559+
mtimes_tmp_name = write_mtimes_file(to_pack, written_list,
565560
nr_written,
566561
hash);
567562
}

t/t2107-update-index-basic.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ test_expect_success '--cacheinfo does not accept blob null sha1' '
3636
echo content >file &&
3737
git add file &&
3838
git rev-parse :file >expect &&
39-
test_must_fail git update-index --cacheinfo 100644 $ZERO_OID file &&
39+
test_must_fail git update-index --verbose --cacheinfo 100644 $ZERO_OID file >out &&
4040
git rev-parse :file >actual &&
41-
test_cmp expect actual
41+
test_cmp expect actual &&
42+
43+
cat >expect <<-\EOF &&
44+
add '\''file'\''
45+
EOF
46+
test_cmp expect out
4247
'
4348

4449
test_expect_success '--cacheinfo does not accept gitlink null sha1' '
@@ -59,9 +64,14 @@ test_expect_success '--cacheinfo mode,sha1,path (new syntax)' '
5964
git rev-parse :file >actual &&
6065
test_cmp expect actual &&
6166
62-
git update-index --add --cacheinfo "100644,$(cat expect),elif" &&
67+
git update-index --add --verbose --cacheinfo "100644,$(cat expect),elif" >out &&
6368
git rev-parse :elif >actual &&
64-
test_cmp expect actual
69+
test_cmp expect actual &&
70+
71+
cat >expect <<-\EOF &&
72+
add '\''elif'\''
73+
EOF
74+
test_cmp expect out
6575
'
6676

6777
test_expect_success '.lock files cleaned up' '
@@ -74,7 +84,8 @@ test_expect_success '.lock files cleaned up' '
7484
git config core.worktree ../../worktree &&
7585
# --refresh triggers late setup_work_tree,
7686
# active_cache_changed is zero, rollback_lock_file fails
77-
git update-index --refresh &&
87+
git update-index --refresh --verbose >out &&
88+
test_must_be_empty out &&
7889
! test -f .git/index.lock
7990
)
8091
'
@@ -83,7 +94,15 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
8394
>A &&
8495
>B &&
8596
git add A B &&
86-
git update-index --chmod=+x A --chmod=-x B &&
97+
git update-index --verbose --chmod=+x A --chmod=-x B >out &&
98+
cat >expect <<-\EOF &&
99+
add '\''A'\''
100+
chmod +x '\''A'\''
101+
add '\''B'\''
102+
chmod -x '\''B'\''
103+
EOF
104+
test_cmp expect out &&
105+
87106
cat >expect <<-EOF &&
88107
100755 $EMPTY_BLOB 0 A
89108
100644 $EMPTY_BLOB 0 B

t/t5329-pack-objects-cruft.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,13 @@ test_expect_success 'expiring cruft objects with git gc' '
451451
sort <reachable.raw >reachable &&
452452
comm -13 reachable objects >unreachable &&
453453
454-
git repack --cruft -d &&
454+
# Write a cruft pack containing all unreachable objects.
455+
git gc --cruft --prune="01-01-1980" &&
455456
456457
mtimes=$(ls .git/objects/pack/pack-*.mtimes) &&
457458
test_path_is_file $mtimes &&
458459
460+
# Prune all unreachable objects from the cruft pack.
459461
git gc --cruft --prune=now &&
460462
461463
git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&

0 commit comments

Comments
 (0)