diff options
author | Karthik Nayak <knayak@gitlab.com> | 2022-11-07 16:48:18 +0300 |
---|---|---|
committer | Karthik Nayak <knayak@gitlab.com> | 2022-11-10 00:27:12 +0300 |
commit | ad423285d60221495daba1eb3357130f0619c6cd (patch) | |
tree | b370f3c719c47632f2f5aa4e95b50be410813fdf | |
parent | 7087c253be455dd2ce4cc4bfcc1d66ea3d557ef4 (diff) |
catfile: Introduce interface `ObjectQueue`
Introduce a new interface `ObjectQueue` which is the summation of the
two interfaces `ObjectInfoQueue` and `ObjectContentQueue`.
We also modify `ObjectContentReader` and `ObjectInfoReader` to return
this new interface and delete both `ObjectContentQueue` and
`ObjectInfoQueue` as they're no longer used. We need this to ensure that
the new object reader we're going to introduce in the following commits
will satisfy a union of the existing interfaces.
-rw-r--r-- | internal/git/catfile/object_content_reader.go | 23 | ||||
-rw-r--r-- | internal/git/catfile/object_info_reader.go | 23 | ||||
-rw-r--r-- | internal/git/catfile/object_reader.go | 46 | ||||
-rw-r--r-- | internal/git/gitpipe/catfile_info.go | 2 | ||||
-rw-r--r-- | internal/git/gitpipe/catfile_object.go | 2 |
5 files changed, 56 insertions, 40 deletions
diff --git a/internal/git/catfile/object_content_reader.go b/internal/git/catfile/object_content_reader.go index 53f9ec6b2..919e3eff0 100644 --- a/internal/git/catfile/object_content_reader.go +++ b/internal/git/catfile/object_content_reader.go @@ -20,26 +20,11 @@ type ObjectContentReader interface { // before another object is requested. Object(context.Context, git.Revision) (*Object, error) - // ObjectContentQueue returns an ObjectContentQueue that can be used to batch multiple object requests. + // ObjectQueue returns an ObjectQueue that can be used to batch multiple object requests. // Using the queue is more efficient than using `Object()` when requesting a bunch of - // objects. The returned function must be executed after use of the ObjectContentQueue has + // objects. The returned function must be executed after use of the ObjectQueue has // finished. - ObjectContentQueue(context.Context) (ObjectContentQueue, func(), error) -} - -// ObjectContentQueue allows for requesting and reading objects independently of each other. The number of -// RequestObject and ReadObject calls must match. ReadObject must be executed after the object has -// been requested already. The order of objects returned by ReadObject is the same as the order in -// which objects have been requested. Users of this interface must call `Flush()` after all requests -// have been queued up such that all requested objects will be readable. -type ObjectContentQueue interface { - // RequestObject requests the given revision from git-cat-file(1). - RequestObject(git.Revision) error - // ReadObject reads an object which has previously been requested. - ReadObject() (*Object, error) - // Flush flushes all queued requests and asks git-cat-file(1) to print all objects which - // have been requested up to this point. - Flush() error + ObjectQueue(context.Context) (ObjectQueue, func(), error) } // objectContentReader is a reader for Git objects. Reading is implemented via a long-lived `git cat-file @@ -142,7 +127,7 @@ func (o *objectContentReader) Object(ctx context.Context, revision git.Revision) return object, nil } -func (o *objectContentReader) ObjectContentQueue(ctx context.Context) (ObjectContentQueue, func(), error) { +func (o *objectContentReader) ObjectQueue(ctx context.Context) (ObjectQueue, func(), error) { queue, finish, err := o.objectQueue(ctx, "catfile.ObjectQueue") if err != nil { return nil, nil, err diff --git a/internal/git/catfile/object_info_reader.go b/internal/git/catfile/object_info_reader.go index 80d7d5683..0904c3ac8 100644 --- a/internal/git/catfile/object_info_reader.go +++ b/internal/git/catfile/object_info_reader.go @@ -100,26 +100,11 @@ type ObjectInfoReader interface { // Info requests information about the revision pointed to by the given revision. Info(context.Context, git.Revision) (*ObjectInfo, error) - // InfoQueue returns an ObjectInfoQueue that can be used to batch multiple object info + // ObjectQueue returns an ObjectQueue that can be used to batch multiple object info // requests. Using the queue is more efficient than using `Info()` when requesting a bunch - // of objects. The returned function must be executed after use of the ObjectInfoQueue has + // of objects. The returned function must be executed after use of the ObjectQueue has // finished. - InfoQueue(context.Context) (ObjectInfoQueue, func(), error) -} - -// ObjectInfoQueue allows for requesting and reading object info independently of each other. The -// number of RequestInfo and ReadInfo calls must match. ReadInfo must be executed after the -// object has been requested already. The order of objects returned by ReadInfo is the same as the -// order in which object info has been requested. Users of this interface must call `Flush()` after -// all requests have been queued up such that all requested objects will be readable. -type ObjectInfoQueue interface { - // RequestInfo requests the given revision from git-cat-file(1). - RequestInfo(git.Revision) error - // ReadInfo reads object info which has previously been requested. - ReadInfo() (*ObjectInfo, error) - // Flush flushes all queued requests and asks git-cat-file(1) to print all objects which - // have been requested up to this point. - Flush() error + ObjectQueue(context.Context) (ObjectQueue, func(), error) } // objectInfoReader is a reader for Git object information. This reader is implemented via a @@ -223,7 +208,7 @@ func (o *objectInfoReader) Info(ctx context.Context, revision git.Revision) (*Ob return objectInfo, nil } -func (o *objectInfoReader) InfoQueue(ctx context.Context) (ObjectInfoQueue, func(), error) { +func (o *objectInfoReader) ObjectQueue(ctx context.Context) (ObjectQueue, func(), error) { queue, cleanup, err := o.infoQueue(ctx, "catfile.InfoQueue") if err != nil { return nil, nil, err diff --git a/internal/git/catfile/object_reader.go b/internal/git/catfile/object_reader.go new file mode 100644 index 000000000..48953ca8b --- /dev/null +++ b/internal/git/catfile/object_reader.go @@ -0,0 +1,46 @@ +package catfile + +import ( + "context" + + "gitlab.com/gitlab-org/gitaly/v15/internal/git" +) + +// ObjectReader returns information about an object referenced by a given revision. +type ObjectReader interface { + cacheable + + // Info requests information about the revision pointed to by the given revision. + Info(context.Context, git.Revision) (*ObjectInfo, error) + + // Reader returns a new Object for the given revision. The Object must be fully consumed + // before another object is requested. + Object(context.Context, git.Revision) (*Object, error) + + // ObjectQueue returns an ObjectQueue that can be used to batch multiple object requests. + // Using the queue is more efficient than using `Object()` when requesting a bunch of + // objects. The returned function must be executed after use of the ObjectQueue has + // finished. Object Content and information can be requested from the queue but their + // respective ordering must be maintained. + ObjectQueue(context.Context) (ObjectQueue, func(), error) +} + +// ObjectQueue allows for requesting and reading objects independently of each other. The number of +// RequestObject+RequestInfo and ReadObject+RequestInfo calls must match and their ordering must be +// maintained. ReadObject/ReadInfo must be executed after the object has been requested already. +// The order of objects returned by ReadObject/ReadInfo is the same as the order in +// which objects have been requested. Users of this interface must call `Flush()` after all requests +// have been queued up such that all requested objects will be readable. +type ObjectQueue interface { + // RequestObject requests the given revision from git-cat-file(1). + RequestObject(git.Revision) error + // ReadObject reads an object which has previously been requested. + ReadObject() (*Object, error) + // RequestInfo requests the given revision from git-cat-file(1). + RequestInfo(git.Revision) error + // ReadInfo reads object info which has previously been requested. + ReadInfo() (*ObjectInfo, error) + // Flush flushes all queued requests and asks git-cat-file(1) to print all objects which + // have been requested up to this point. + Flush() error +} diff --git a/internal/git/gitpipe/catfile_info.go b/internal/git/gitpipe/catfile_info.go index 42ea63b80..55eaf7432 100644 --- a/internal/git/gitpipe/catfile_info.go +++ b/internal/git/gitpipe/catfile_info.go @@ -71,7 +71,7 @@ func CatfileInfo( opt(&cfg) } - queue, queueCleanup, err := objectInfoReader.InfoQueue(ctx) + queue, queueCleanup, err := objectInfoReader.ObjectQueue(ctx) if err != nil { return nil, err } diff --git a/internal/git/gitpipe/catfile_object.go b/internal/git/gitpipe/catfile_object.go index 1590661cd..65c18013a 100644 --- a/internal/git/gitpipe/catfile_object.go +++ b/internal/git/gitpipe/catfile_object.go @@ -39,7 +39,7 @@ func CatfileObject( objectReader catfile.ObjectContentReader, it ObjectIterator, ) (CatfileObjectIterator, error) { - queue, queueCleanup, err := objectReader.ObjectContentQueue(ctx) + queue, queueCleanup, err := objectReader.ObjectQueue(ctx) if err != nil { return nil, err } |