mirror of
https://github.com/git/git
synced 2024-09-12 21:04:12 +00:00
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'
This commit is contained in:
commit
30327a08c8
27
cache-tree.c
27
cache-tree.c
|
@ -101,33 +101,6 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *it, const char *path)
|
|||
return find_subtree(it, path, pathlen, 1);
|
||||
}
|
||||
|
||||
struct cache_tree *cache_tree_find_path(struct cache_tree *it, const char *path)
|
||||
{
|
||||
const char *slash;
|
||||
int namelen;
|
||||
struct cache_tree_sub it_sub = {
|
||||
.cache_tree = it,
|
||||
};
|
||||
struct cache_tree_sub *down = &it_sub;
|
||||
|
||||
while (down) {
|
||||
slash = strchrnul(path, '/');
|
||||
namelen = slash - path;
|
||||
down->cache_tree->entry_count = -1;
|
||||
if (!*slash) {
|
||||
int pos;
|
||||
pos = cache_tree_subtree_pos(down->cache_tree, path, namelen);
|
||||
if (0 <= pos)
|
||||
return down->cache_tree->down[pos]->cache_tree;
|
||||
return NULL;
|
||||
}
|
||||
down = find_subtree(it, path, namelen, 0);
|
||||
path = slash + 1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int do_invalidate_path(struct cache_tree *it, const char *path)
|
||||
{
|
||||
/* a/b/c
|
||||
|
|
|
@ -29,8 +29,6 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
|
|||
|
||||
int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen);
|
||||
|
||||
struct cache_tree *cache_tree_find_path(struct cache_tree *it, const char *path);
|
||||
|
||||
void cache_tree_write(struct strbuf *, struct cache_tree *root);
|
||||
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
|
||||
|
||||
|
|
13
pack-write.c
13
pack-write.c
|
@ -310,26 +310,21 @@ static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash)
|
|||
hashwrite(f, hash, the_hash_algo->rawsz);
|
||||
}
|
||||
|
||||
static const char *write_mtimes_file(const char *mtimes_name,
|
||||
struct packing_data *to_pack,
|
||||
static const char *write_mtimes_file(struct packing_data *to_pack,
|
||||
struct pack_idx_entry **objects,
|
||||
uint32_t nr_objects,
|
||||
const unsigned char *hash)
|
||||
{
|
||||
struct strbuf tmp_file = STRBUF_INIT;
|
||||
const char *mtimes_name;
|
||||
struct hashfile *f;
|
||||
int fd;
|
||||
|
||||
if (!to_pack)
|
||||
BUG("cannot call write_mtimes_file with NULL packing_data");
|
||||
|
||||
if (!mtimes_name) {
|
||||
struct strbuf tmp_file = STRBUF_INIT;
|
||||
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
|
||||
mtimes_name = strbuf_detach(&tmp_file, NULL);
|
||||
} else {
|
||||
unlink(mtimes_name);
|
||||
fd = xopen(mtimes_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
|
||||
}
|
||||
f = hashfd(fd, mtimes_name);
|
||||
|
||||
write_mtimes_header(f);
|
||||
|
@ -561,7 +556,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
|
|||
pack_idx_opts->flags);
|
||||
|
||||
if (pack_idx_opts->flags & WRITE_MTIMES) {
|
||||
mtimes_tmp_name = write_mtimes_file(NULL, to_pack, written_list,
|
||||
mtimes_tmp_name = write_mtimes_file(to_pack, written_list,
|
||||
nr_written,
|
||||
hash);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,14 @@ test_expect_success '--cacheinfo does not accept blob null sha1' '
|
|||
echo content >file &&
|
||||
git add file &&
|
||||
git rev-parse :file >expect &&
|
||||
test_must_fail git update-index --cacheinfo 100644 $ZERO_OID file &&
|
||||
test_must_fail git update-index --verbose --cacheinfo 100644 $ZERO_OID file >out &&
|
||||
git rev-parse :file >actual &&
|
||||
test_cmp expect actual
|
||||
test_cmp expect actual &&
|
||||
|
||||
cat >expect <<-\EOF &&
|
||||
add '\''file'\''
|
||||
EOF
|
||||
test_cmp expect out
|
||||
'
|
||||
|
||||
test_expect_success '--cacheinfo does not accept gitlink null sha1' '
|
||||
|
@ -59,9 +64,14 @@ test_expect_success '--cacheinfo mode,sha1,path (new syntax)' '
|
|||
git rev-parse :file >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git update-index --add --cacheinfo "100644,$(cat expect),elif" &&
|
||||
git update-index --add --verbose --cacheinfo "100644,$(cat expect),elif" >out &&
|
||||
git rev-parse :elif >actual &&
|
||||
test_cmp expect actual
|
||||
test_cmp expect actual &&
|
||||
|
||||
cat >expect <<-\EOF &&
|
||||
add '\''elif'\''
|
||||
EOF
|
||||
test_cmp expect out
|
||||
'
|
||||
|
||||
test_expect_success '.lock files cleaned up' '
|
||||
|
@ -74,7 +84,8 @@ test_expect_success '.lock files cleaned up' '
|
|||
git config core.worktree ../../worktree &&
|
||||
# --refresh triggers late setup_work_tree,
|
||||
# active_cache_changed is zero, rollback_lock_file fails
|
||||
git update-index --refresh &&
|
||||
git update-index --refresh --verbose >out &&
|
||||
test_must_be_empty out &&
|
||||
! test -f .git/index.lock
|
||||
)
|
||||
'
|
||||
|
@ -83,7 +94,15 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
|
|||
>A &&
|
||||
>B &&
|
||||
git add A B &&
|
||||
git update-index --chmod=+x A --chmod=-x B &&
|
||||
git update-index --verbose --chmod=+x A --chmod=-x B >out &&
|
||||
cat >expect <<-\EOF &&
|
||||
add '\''A'\''
|
||||
chmod +x '\''A'\''
|
||||
add '\''B'\''
|
||||
chmod -x '\''B'\''
|
||||
EOF
|
||||
test_cmp expect out &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
100755 $EMPTY_BLOB 0 A
|
||||
100644 $EMPTY_BLOB 0 B
|
||||
|
|
|
@ -451,11 +451,13 @@ test_expect_success 'expiring cruft objects with git gc' '
|
|||
sort <reachable.raw >reachable &&
|
||||
comm -13 reachable objects >unreachable &&
|
||||
|
||||
git repack --cruft -d &&
|
||||
# Write a cruft pack containing all unreachable objects.
|
||||
git gc --cruft --prune="01-01-1980" &&
|
||||
|
||||
mtimes=$(ls .git/objects/pack/pack-*.mtimes) &&
|
||||
test_path_is_file $mtimes &&
|
||||
|
||||
# Prune all unreachable objects from the cruft pack.
|
||||
git gc --cruft --prune=now &&
|
||||
|
||||
git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
|
||||
|
|
Loading…
Reference in a new issue