test-lib-functions: add parsing helpers for ls-files and ls-tree

Several tests use awk to parse OIDs from the output of 'git ls-files
--stage' and 'git ls-tree'. Introduce helpers to centralize these uses
of awk.

Update t5317-pack-objects-filter-objects.sh to use the new ls-files
helper so that it has some usages to review. Other updates are left for
the future.

Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Neeraj Singh
2022-04-04 22:20:15 -07:00
committed by Junio C Hamano
parent 8a94d83349
commit fb2d0db502
2 changed files with 54 additions and 47 deletions

View File

@ -1706,6 +1706,16 @@ test_oid_to_path () {
echo "${1%$basename}/$basename"
}
# Parse oids from git ls-files --staged output
test_parse_ls_files_stage_oids () {
awk '{print $2}' -
}
# Parse oids from git ls-tree output
test_parse_ls_tree_oids () {
awk '{print $3}' -
}
# Choose a port number based on the test script's number and store it in
# the given variable name, unless that variable already contains a number.
test_set_port () {