Advertisement
S-trace

Untitled

Nov 14th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.15 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 -qm1 "$title" ); then
  17.         echo Yes
  18.       commit_hash=$(git log --oneline |fgrep -m1 "$title"|cut -d ' ' -f 1)
  19.       if [ q"$commit_hash" != "q" ]; then
  20.           echo -n "Checking if patch $patch matches commit $commit_hash... "
  21.           commit_id=$(git format-patch -1 --stdout $commit_hash |git patch-id|cut -d ' ' -f 1)
  22.           patch_id=$(git patch-id < $absolute_patch_path|cut -d ' ' -f 1)
  23. #         grep -oPz -- '(?s)-- ?\n[0-9.]+\n' $absolute_patch_path
  24.           if [ $commit_id = $patch_id ]; then
  25.               echo 'Yes, it matches'
  26.           else
  27.               echo 'NO! MISMATCH!'
  28.               sed '0,/^$/d' $absolute_patch_path|head -n -3  > /tmp/patch
  29.               git show --stat $commit_hash -p --pretty=format:%b > /tmp/commit
  30.               diff -u /tmp/patch /tmp/commit
  31.               rm /tmp/patch /tmp/commit
  32.               fi
  33.     else
  34.         echo "Unable to get commit hash for '$title'! Something went wrong!"
  35.         sleep 20
  36.     fi
  37.     else
  38.         echo No
  39.         echo "Trying to apply patch $(basename "$patch") to '$repo_to_patch'"
  40.         if ! git am $absolute_patch_path; then
  41.             echo "Failed, aborting git am"
  42.             git am --abort
  43.         fi
  44.     fi
  45.     popd > /dev/null
  46. done
  47. popd > /dev/null
  48. echo "Applying patches: done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement