Skip to content

Commit

Permalink
beryllium: update script to handle added and deleted blobs
Browse files Browse the repository at this point in the history
Change-Id: I544a4669d6ba478ea2b7c77084fc5d9ed5d5cee9
Signed-off-by: Chenyang Zhong <[email protected]>
  • Loading branch information
jjpprrrr authored and ibratabian17 committed Apr 11, 2022
1 parent db9fe89 commit aaeda63
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions generate_sha1_from_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# HISTORY
# 2020/06/19 : Script creation
# 2020/09/29 : Updated script to handle added and deleted blobs
#
#==============================================================================
#
Expand Down Expand Up @@ -46,16 +47,36 @@ echo "$(git show -s --format='%h %s' ${COMMIT})"
echo "========================================================"

# iterate through changed files in the commit
for file in $(git diff-tree --no-commit-id --name-only -r "${COMMIT}")
git diff-tree --no-commit-id --name-status -r ${COMMIT} | while read line ;
do
# separate status and file name
read -ra arr_line <<< "${line}"
status=${arr_line[0]}
file=${arr_line[1]}

# remove directory prefix from filename
file_stripped=${file#"${DIR_PREFIX}"}

# blob status is deleted
if [[ "$status" == "D" ]]; then
echo "deleting ${file_stripped}"
sed -i "\%^${file_stripped}%d" "${MY_DIR}/proprietary-files.txt"
continue
fi

# generate sha1
r="$(sha1sum "$file")"
r_arr=($r)
sha1="${r_arr[0]}"

# remove directory prefix from filename
file_stripped=${file#"${DIR_PREFIX}"}
# blob is newly added
if [[ "$status" == "A" ]]; then
echo "adding ${file_stripped}"
echo "${file_stripped}|${sha1}" >> "${MY_DIR}/proprietary-files.txt"
continue
fi

# the rest files already exist in the list and are modified
# iterate through lines in proprietary-files.txt until the first
# non-comment match
for line in $(grep "$file_stripped" "${MY_DIR}/proprietary-files.txt")
Expand Down

0 comments on commit aaeda63

Please sign in to comment.