Advertisement
S-trace

Untitled

Nov 11th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.26 KB | None | 0 0
  1. build_root=$(pwd) # vendorsetup.sh is sourced by build/envsetup.sh in root of android build tree. Hope that nobody can correctly source it not from root of android tree.
  2. echo "Applying patches"
  3. patches_path="$build_root/device/jsr/d10f/patches/"
  4. pushd "$patches_path" > /dev/null
  5. unset repos
  6. find -type f -name '*.patch'|cut -d / -f 2-|sort
  7. for patch in `find -type f -name '*.patch'|cut -d / -f 2-|sort`; do
  8.         # Strip patch title to get git commit title - git ignore [text] prefixes in beginning of patch title during git am
  9.         title=$(sed -rn "s/Subject: (\[[^]]+] *)*//p" "$patch")
  10.         absolute_patch_path="$patches_path/$patch"
  11.         # Supported both path/to/repo_with_underlines/file.patch and path_to_repo+with+underlines/file.patch (both leads to path/to/repo_with_underlines)
  12.         repo_to_patch="$(if dirname $patch|grep -q /; then dirname $patch; else dirname $patch |tr '_' '/'|tr '+' '_'; fi)"
  13.  
  14.         echo -n "Is $repo_to_patch patched for '$title' ?.. "
  15.         pushd "$build_root/$repo_to_patch" > /dev/null
  16.         if (git log |fgrep -q "$title" ); then
  17.                 echo Yes
  18.           commit_hash=$(git log --oneline |grep "$title"|cut -d ' ' -f 1)
  19.           echo -n "Checking if patch $patch matches commit $commit_hash... "
  20.           commit_md5=$(git show --stat $commit_hash -p --pretty=format:%b|md5sum|cut -d ' ' -f 1)
  21.           patch_md5=$(sed '0,/^$/d' $absolute_patch_path|head -n -3 |md5sum|cut -d ' ' -f 1)
  22. #         grep -oPz -- '(?s)-- ?\n[0-9.]+\n' $absolute_patch_path
  23.           if [ $commit_md5 = $patch_md5 ]; then
  24.                   echo 'Yes, it matches'
  25.           else
  26.                   echo 'NO! MISMATCH!'
  27.                   sed '0,/^$/d' $absolute_patch_path|head -n -3  > /tmp/patch
  28.                   git show --stat $commit_hash -p --pretty=format:%b > /tmp/commit
  29.                   diff -u /tmp/patch /tmp/commit
  30.           fi
  31.         else
  32.                 echo No
  33.                 echo "Trying to apply patch $(basename "$patch") to '$repo_to_patch'"
  34.                 if ! git am $absolute_patch_path; then
  35.                         echo "Failed, aborting git am"
  36.                         git am --abort
  37.                 fi
  38.         fi
  39.         popd > /dev/null
  40. done
  41. popd > /dev/null
  42. echo "Applying patches: done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement