-
Notifications
You must be signed in to change notification settings - Fork 38
Issue 1089: Move the script generate_patches.sh from lipcap to meta tools #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rshrotey-IBM
wants to merge
2
commits into
main
Choose a base branch
from
rahul/gen_patches
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Script to generate the diff files/patches from source code repo to be committed to the port repo | ||
| # Steps | ||
| # 1. Apply all the patches and generate source code repo using zopen build command | ||
| # 2. Commit the files modified by applying patches. Dev/bug fix changes should be done on top of this commit | ||
| # 3. Once changes are ready, create new commit(s) | ||
| # 4. Use this script to generate patch for files modified in step 3 | ||
|
|
||
| echo_error() | ||
| { | ||
| echo "ERROR: $1" | ||
| } | ||
|
|
||
| get_commit_ids() | ||
| { | ||
| BASE_COMMIT= # source code gets cloned with this latest commit | ||
| PATCHED_COMMIT= # Run zopen build to apply all the patches from port | ||
| CURRENT_COMMIT= # Commit with further dev changes | ||
|
|
||
| #Check here if the branch is in detached state | ||
| if [ $(git branch -a | grep '* ' | grep -c "detached") != 0 ] | ||
| then | ||
| echo_error "This is in detached state, please create a branch and try again!" | ||
| exit 1; | ||
| fi | ||
|
|
||
| #Find the current branch name | ||
| curr_branch=$(git branch -a | grep '* ' | cut -d ' ' -f 2) | ||
|
|
||
| #Find the commit from which curr_branch diverged | ||
| BASE_COMMIT=$(git reflog show ${curr_branch} | grep "branch: Created" | cut -d ' ' -f 1) | ||
|
|
||
| #Find the first commit after curr_branch branch diverged, this is the commit | ||
| #with all previous patches applied | ||
| PATCHED_COMMIT=$(git rev-list --reverse ${curr_branch} | grep -A1 ${BASE_COMMIT} | tail -n 1) | ||
|
|
||
| #Find the latest commit | ||
| CURRENT_COMMIT=$(git rev-list ${curr_branch} | head -n 1) | ||
|
|
||
| if [[ -z ${BASE_COMMIT} || -z ${PATCHED_COMMIT} || -z ${CURRENT_COMMIT} ]] | ||
| then | ||
| echo_error "Something is wrong, BASE_COMMIT, PATCHED_COMMIT and CURRENT_COMMIT needed but are not set" | ||
| exit | ||
| fi | ||
| } | ||
|
|
||
| gen_patches() | ||
| { | ||
| if [ ${PATCHED_COMMIT} == ${CURRENT_COMMIT} ] | ||
| then | ||
| #Generating patch files for the first time | ||
| MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only ${BASE_COMMIT} ${CURRENT_COMMIT} -r) | ||
| else | ||
| MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only ${PATCHED_COMMIT} ${CURRENT_COMMIT} -r) | ||
| fi | ||
|
|
||
| echo -e "\nModified files:\n" | ||
| echo -e "${MODIFIED_FILES}\n" | ||
|
|
||
| for file in ${MODIFIED_FILES} | ||
| do | ||
| echo "Generating diff for ${file}" | ||
|
|
||
| #Save the patch files to port/patches/ | ||
| PATCH_FILE=${PORT_DIR}/patches/${file}.patch | ||
| PATCH_FILE_DIR=$(dirname ${PATCH_FILE}) | ||
|
|
||
| if [ ! -d ${PATCH_FILE_DIR} ] | ||
| then | ||
| echo "${PATCH_FILE_DIR} does not exists, creating one" | ||
| mkdir -p ${PATCH_FILE_DIR} | ||
| fi | ||
|
|
||
| if [ -f ${PATCH_FILE} ] | ||
| then | ||
| echo "WARNING: ${PATCH_FILE} already exists, contents will be overwritten" | ||
| fi | ||
|
|
||
| echo "" | ||
| #Generate patch file | ||
| git diff ${BASE_COMMIT} -- ${file} > ${PATCH_FILE} | ||
|
|
||
| #Add the file to the staging area | ||
| # cd ${PORT_DIR} ; git add ${PATCH_FILE} ; cd - | ||
| done | ||
| } | ||
|
|
||
| ## main() STARTS HERE ## | ||
|
|
||
| if [ $# != "4" ] | ||
| then | ||
| echo_error "Usage: ${0} -p <port-dir absolute path> -s <src-dir absolute path>" | ||
| exit 1; | ||
| fi | ||
|
|
||
| while getopts "p:s:" opt; do | ||
| case $opt in | ||
| p) | ||
| PORT_DIR="$OPTARG" | ||
| ;; | ||
| s) | ||
| SRC_DIR="$OPTARG" | ||
| ;; | ||
| :) | ||
| echo_error "Usage: ${0} -p <port-dir absolute path> -s <src-dir absolute path>" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ ! -d ${SRC_DIR} ] | ||
| then | ||
| echo_error "${SRC_DIR} does not exist" | ||
| exit | ||
| fi | ||
|
|
||
| if [ ! -d ${PORT_DIR} ] | ||
| then | ||
| echo_error "${PORT_DIR} does not exist" | ||
| exit | ||
| fi | ||
|
|
||
| pushd ${SRC_DIR} | ||
|
|
||
| get_commit_ids | ||
|
|
||
| echo "SRC_DIR ${SRC_DIR}" | ||
| echo "PORT_DIR ${PORT_DIR}" | ||
| echo "BASE_COMMIT ${BASE_COMMIT}" | ||
| echo "PATCHED_COMMIT ${PATCHED_COMMIT}" | ||
| echo "CURRENT_COMMIT ${CURRENT_COMMIT}" | ||
|
|
||
| # Generate patches later | ||
| gen_patches | ||
|
|
||
| popd | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.