backporting

I recently sent a pull request for adding sparse matrix boolean comparisons to SciPy. However when comparing a sparse matrix with dense matrix, with the dense matrix on the LHS, the behavior was unpredictable. This is because the __array_priority__ was not being respected. Which was fixed in NumPy by this pull request #3324 (Thanks nouiz!). This will be included in NumPy 1.8, but I would like to have it in the current stable version of NumPy, so that I can use it in my work with SciPy. So I am backporting it.

I thought this backporting process was a insightful demonstration of slightly more advanced git topics. So I'm writing this walkthrough.

Basically we make a branch off of numpy/maintenance/1.7.x, cherry pick a commit from numpy/master then submit a pull request back to numpy/maintenance/1.7.x.

  1. Assuming you already have a fork of Numpy on github. We need to update it from upstream.

    # Add upstream.
    git remote add upstream https://github.com/numpy/numpy.git
    
    # Get the latest updates.
    git fetch upstream
    
    # Make sure you are on master.
    git checkout master
    
    # Apply the updates locally.
    git rebase upstream/master
    
    # Push the updated code to your github repo.
    git push origin
    
  2. Next we need to make the branch we will work on. This needs to be based on the older version of numpy (not master).

    # Make a new branch based of numpy/maintenance/1.7.x, 
    # backport-3324 is our new name for the branch.
    git checkout -b backport-3324 upstream/maintenance/1.7.x
    
  3. Now we need to apply the changes from master to this branch using cherry-pick

    # This pull request included commits aa7a047 to c098283 (inclusive)
    # so use the .. syntax, the ^ makes the range inclusive.
    git cherry-pick aa7a047^..c098283
    
    ...
    
    # Fix any conflicts then if needed.
    git cherry-pick --continue
    
  4. I ran into some conflicts cherry picking here. These are resolved the same as with merge/rebase conflicts. Except here you can use git blame to see the difference between master and the backported branch to make sure nothing gets screwed up.

  5. Push your new branch to your git hub repo.

    git push -u origin backport-3324
    

Finally make your pull request using github.com. My pull request is here.

I wonder how long it will take for Travis ci to update it version of NumPy for testing SciPy?

Comments

Comments powered by Disqus