google / git-appraise

Distributed code review system for Git repos
Apache License 2.0
5.12k stars 145 forks source link

Cleanup and generalize the API for low-level repository operations. #98

Closed ojarjur closed 4 years ago

ojarjur commented 4 years ago

This change cleans up the API for low-level repository operations in the following ways:

  1. Introduce more generic operations on the underlying repository DAG objects (i.e. blobs, trees, commits, and refs).
  2. Fix a bug in the code for merging archives where we did not check if the local archives ref existed before trying to resolve it.

Previously, the API exposed by the repository interface was very tailored to the tasks that the git-appraise needed to perform for code reviews. That meant that adding new features which used the repository in slightly different ways would require rather large changes to the repository interface.

Under the new API, any feature that simply relies upon the features of git should be able to use the API without changes.

This was originally part of the pull request to add support for forks, but is now being split off into a stand-alone pull request so that it can be reviewed in isolation, and so that it is available for other work like the proposed change to support detached comments (#97).

The bug-fix for the archives issue is being included in here because the refactoring to clean up the repository code is what made us catch the underlying bug. The issue with that bug is that we tried to use a single command ('git show') to both check if the local archives ref (refs/devtools/archives/reviews) exists and to resolve what commit it points to. However, that command returns an error if the ref does not exist.

This change fixes it by including an explicit check to see if the ref exists before trying to resolve it.