Skip to content
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

Produce a squashed version of SYCL history to make the life of the SYCL SC committee simpler #617

Open
keryell opened this issue Sep 10, 2024 · 3 comments
Assignees
Labels
editorial Some purely editorial problem

Comments

@keryell
Copy link
Member

keryell commented Sep 10, 2024

@VerenaBeckham @etomzak @AByzhynar I put an example of what a simplified history is: https://github.com/KhronosGroup/SYCL-Docs/tree/squashed-main
Interestingly, the link on the PR in the commit title correctly send to the original PR and its commits.
Note that it will be misleading when clicked from the SYCL-SC repository, but we could add a more precise link.

Here is the current recipe using https://github.com/newren/git-filter-repo quite faster than the old git filter-branch:

sudo apt install git-filter-repo
git clone [email protected]:KhronosGroup/SYCL-Doc
cd SYCL-Doc
# Just keep the first parent from each commit to give a squashed view
git filter-repo --refs main --commit-callback 'if len(commit.parents) > 1 : commit.parents = [commit.parents[0]]'
# Create a new squashed-main branch upstream.
git push origin main:squashed-main
@keryell keryell added the editorial Some purely editorial problem label Sep 10, 2024
@rolandschulz
Copy link

You were quicker. Alternative solution created by GPT:

#!/bin/bash

# Set the current branch and main branch names
main_branch="main"

# Find the most recent commit on the current branch with "cherry picked from commit" in the last line of the message
recent_commit=$(git log --format=%H -n 1 --grep="cherry picked from commit")

if [ -z "$recent_commit" ]; then
  echo "No recent commit with 'cherry picked from commit' found. Using HEAD as the original commit."
  original_commit=$(git rev-parse HEAD)
else
  echo "Most recent commit with cherry-pick found: $recent_commit"
  
  # Extract the original commit hash from the cherry-pick message (it's the last word of the commit message)
  original_commit=$(git log -1 --format=%B $recent_commit | grep "cherry picked from commit" | awk '{print $NF}' | tr -d ')')
  
  # Check if the original commit hash was extracted
  if [ -z "$original_commit" ]; then
    echo "Failed to extract the original commit hash."
    exit 1
  fi
fi

echo "Original commit hash: $original_commit"

# Get all commits after the original commit on the main branch (first-parent only)
commits_to_cherry_pick=$(git log --first-parent --format=%H --reverse $original_commit..$main_branch)

# Check if there are any commits to cherry-pick
if [ -z "$commits_to_cherry_pick" ]; then
  echo "No commits to cherry-pick from $main_branch after $original_commit."
  exit 0
fi

# Cherry-pick all commits (merge or non-merge) with -m 1 and -x to include the cherry-pick message
echo "Cherry-picking all commits from $main_branch after $original_commit..."
git cherry-pick -m 1 -x $commits_to_cherry_pick

# Check if the cherry-pick succeeded
if [ $? -ne 0 ]; then
  echo "Cherry-pick failed. Resolve conflicts, then run 'git cherry-pick --continue' to finish."
  exit 1
fi

echo "Successfully cherry-picked all relevant commits from $main_branch."

Advantage of this solution is that it automatically only adds the new commits added since it was called last time. So it can be run in post-commit without having to recreate the branch every time and it refers to the original commit. Disadvantage creating many commits is much slower than with Ronan's solution. But given that this only done once it shouldn't matter.

@keryell
Copy link
Member Author

keryell commented Sep 10, 2024

Whatever solution we pick, regenerating the branch from scratch seems idempotent (generating new hash values every time the script is done would be a nightmare) and is surprisingly done in only a fraction of second.

@keryell
Copy link
Member Author

keryell commented Sep 16, 2024

This is to be used as described in SYCL SC internal https://gitlab.khronos.org/syclsc/Specification/-/issues/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial Some purely editorial problem
Projects
None yet
Development

No branches or pull requests

3 participants