Blob ID in commit-callback cannot be used to get file contents
I'm using the latest version of git-filter-repo, 2.45.0. My git version is 2.34.1.
I'm trying to write a commit-callback that modifies a single file. I'm basing this callback on this example. However, instead of a object ID, I'm getting an integer that I cannot use with git cat-file --batch. What I really need is the object ID.
I ended up just using the blob-callback and making sure that the blob I'm processing has a very specific prefix that is unique to that file before making changes to it.
I saw this issue, #549 , and if I had that, I'd use it instead.
I have a workaround. I created a blob_callback that creates a dict where the key is the blob ID and the value is the object ID:
import git_filter_repo as fr
BLOB_IDS = {}
def blob_callback(blob: fr.Blob, _metadata):
BLOB_IDS[blob.id] = blob.original_id
I can use that dict to convert the blob ID I get from the commit callback into an object ID that I can pass to git cat-file to get the contents.
While this works, it would be nice if the original_id where part of the blob information passed in files_changed, or if there were a way to access the blob to get its contents. That would remove the need for git cat-file.
I added a --file-info-callback as part of commit 615720731589 (filter-repo: add a --file-info-callback, 2024-10-23). That commit adds a callback which allows you to work with both the filename and file contents (and file mode). It basically just handles the git cat-file --batch-command for you but adds some convenience functions and integrates well with e.g. --replace-text by allowing you to specify which files that should apply to.