1#!/usr/bin/env bash 2 3# Copyright (C) 2017 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# This script is called by git diff with GIT_EXTERNAL_DIFF 18 19# git calls this script with 7 parameters: 20# path old-file old-hex old-mode new-file new-hex new-mode 21# if 8th parameter is specified, the change is written incrementally 22 23source $(dirname ${BASH_SOURCE})/common.sh 24 25OLD_FILE=${2} 26NEW_FILE=${5} 27INCREMENTAL=${8} 28echo "diffing ${NEW_FILE}" 29# Compute the patch file path 30TARGET_FILE=$PWD/${NEW_FILE} 31PATCH_FILE=${PATCHES_DIR}/$(relpath ${TARGET_FILE} ${ICU4J_DIR})".patch" 32 33# Create the dst directory 34mkdir -p $(dirname ${PATCH_FILE}) 35 36# Write the diff into the patch file 37# Replace the tmp file path in the first line with the real source path 38if [ -z ${INCREMENTAL} ]; then 39 diff -u "${NEW_FILE}" "${OLD_FILE}" | sed "2s#${OLD_FILE}#${NEW_FILE}#" > ${PATCH_FILE} 40else 41 diff -u "${OLD_FILE}" "${NEW_FILE}" | sed "1s#${OLD_FILE}#${NEW_FILE}#" >> ${PATCH_FILE} 42fi 43 44