diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-02 08:22:36 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-03 07:58:02 +0300 |
commit | de2305e6a106c0025c4fdc691beac9608a93393a (patch) | |
tree | a5454cdcd48bb73ac53228fc01502b5d026c9896 | |
parent | f471288e6b96ea1d3c40316d1afd501a274b3c9e (diff) |
catfile: Detect object hash used by repository
The catfile package needs to parse object hashes in multiple locations
and thus needs to know about the object hash format used by a specific
repository. Detect the object hash at runtime to support both SHA1 and
SHA256 repositories.
-rw-r--r-- | internal/git/catfile/object_info_reader.go | 18 | ||||
-rw-r--r-- | internal/git/catfile/object_reader.go | 6 | ||||
-rw-r--r-- | internal/git/catfile/request_queue.go | 6 |
3 files changed, 24 insertions, 6 deletions
diff --git a/internal/git/catfile/object_info_reader.go b/internal/git/catfile/object_info_reader.go index 62e714e5b..595f6d52e 100644 --- a/internal/git/catfile/object_info_reader.go +++ b/internal/git/catfile/object_info_reader.go @@ -126,7 +126,8 @@ type ObjectInfoQueue interface { // long-lived `git cat-file --batch-check` process such that we do not have to spawn a separate // process per object info we're about to read. type objectInfoReader struct { - cmd *command.Command + cmd *command.Command + objectHash git.ObjectHash counter *prometheus.CounterVec @@ -153,12 +154,19 @@ func newObjectInfoReader( return nil, err } + objectHash, err := repo.ObjectHash(ctx) + if err != nil { + return nil, fmt.Errorf("detecting object hash: %w", err) + } + objectInfoReader := &objectInfoReader{ - cmd: batchCmd, - counter: counter, + cmd: batchCmd, + objectHash: objectHash, + counter: counter, queue: requestQueue{ - stdout: bufio.NewReader(batchCmd), - stdin: bufio.NewWriter(batchCmd), + objectHash: objectHash, + stdout: bufio.NewReader(batchCmd), + stdin: bufio.NewWriter(batchCmd), }, } diff --git a/internal/git/catfile/object_reader.go b/internal/git/catfile/object_reader.go index 516050301..243e70865 100644 --- a/internal/git/catfile/object_reader.go +++ b/internal/git/catfile/object_reader.go @@ -73,10 +73,16 @@ func newObjectReader( return nil, err } + objectHash, err := repo.ObjectHash(ctx) + if err != nil { + return nil, fmt.Errorf("detecting object hash: %w", err) + } + objectReader := &objectReader{ cmd: batchCmd, counter: counter, queue: requestQueue{ + objectHash: objectHash, isObjectQueue: true, stdout: bufio.NewReader(batchCmd), stdin: bufio.NewWriter(batchCmd), diff --git a/internal/git/catfile/request_queue.go b/internal/git/catfile/request_queue.go index 634e30332..232d731b1 100644 --- a/internal/git/catfile/request_queue.go +++ b/internal/git/catfile/request_queue.go @@ -21,6 +21,10 @@ const ( ) type requestQueue struct { + // objectHash is the object hash used by the repository the request queue has been + // spawned for. + objectHash git.ObjectHash + // outstandingRequests is the number of requests which have been queued up. Gets incremented // on request, and decremented when starting to read an object (not when that object has // been fully consumed). @@ -212,5 +216,5 @@ func (q *requestQueue) readInfo() (*ObjectInfo, error) { return nil, fmt.Errorf("concurrent read on request queue") } - return ParseObjectInfo(git.ObjectHashSHA1, q.stdout) + return ParseObjectInfo(q.objectHash, q.stdout) } |