This makes the code a bit easier to understand. Also add a docstring to run().
Note: This means that we read the entire index into memory when calling git update-index, whereas previously we would send the data line-by-line. Git already loads the entire index into memory anyway (to my knowledge) so this should not cause a regression.