Repository navigation
progress: move CopyCallback (& related) to package 'tools' - #2749
Merged
Merged
Conversation
Contributor
Author
|
@git-lfs/core I mistakingly merged this PR thinking that it was approved! Please don't hesitate to let me know if there's anything that looks less than 👍 in this PR, and I'd be more than happy to follow up on it. |
chrisd8088
added a commit
that referenced
this pull request
Aug 5, 2026
We define a "closingByteReader" structure with a no-op Close() method in several of our packages, including the "tools", "lfsapi", and "lfshttp" packages. In each case, the purpose of the structure is to allow us to use the structure returned by the NewReader() function of the Go standard library's "bytes" package in contexts that require a structure that implements the ReadSeekCloser interface from the standard library's "io" package. We introduced the first of these structures to our "lfsapi" package in commit 6659b9d of PR #1839. In a subsequent commit in that PR we then added a NewByteBody() factory function which initializes a "closingByteReader" structure by passing the byte slice provided as a parameter to the "bytes" package's NewReader() function. Next, in the same PR we replicated the structure, its Close() method, and the NewByteBody() function into what was at that time called our "progress" package. In PR #2749 we later moved the "progress" package's contents to our "tools" package, and then in PR #3244 we replicated the structure, its Close() method, and the NewByteBody() function a third time when we refactored portions of the "lfsapi" package into our "lfshttp" package. In our "tools" package we also provide a NewByteBodyWithCallback() factory function which calls the NewByteBody() function and uses the "closingByteReader" structure it returns as the "body" parameter in a call to the NewBodyWithCallback() function. The result is that a new BodyWithCallback structure is initialized with the byte slice passed to the NewByteBodyWithCallback() function as its underlying source of data. This NewByteBodyWithCallback() function is used exclusively in various test functions, both in our "tools" package and our "lfs" package. Ideally, though, we should not define functions or methods in our non-test source files that are intended for use only in test functions. In prior commits in this PR we updated all of the test functions which use the NewByteBodyWithCallback() function, and revised a number of them so that they now perform their checks against the methods of both a BodyWithCallback structure and the methods of a CallbackReader structure. To simplify the initialization of the CallbackReader structures, in another prior commit in this PR we introduced a NewCallbackReader() factory function, which operates in a similar manner to the NewBodyWithCallback() function except that it returns a CallbackReader structure instead of a BodyWithCallback structure. We did not, though, introduce a NewByteCallbackReader() function, as it is relatively straightforward for our tests to simply pass the return value from a call to the "bytes" package's NewReader() function to our NewCallbackReader() function. Given the marginal utility of the NewByteBodyWithCallback() function and the fact that it is only used in our test functions, we remove it now. This also helps align the structure initialization steps performed by our test functions, since they now just call the NewBodyWithCallback() and NewCallbackReader() functions, which initialize their respective structures in an equivalent manner. To bring these initialization steps into even closer alignment, we also rename the "closingByteReader" structure in the "tools" package to ClosingByteReader, and rename its factory function from NewByteBody() to NewClosingByteReader(). These changes will allow us to make use of the structure in our "lfsapi" and "lfshttp" packages, replacing the identical definitions of the "closingByteReader" structure and the related functions and methods in those packages. We defer this refactoring step to a future PR, however, as it is outside of this PR's scope. Finally, we move the definition of the ClosingByteReader structure, its Close() method, and the NewClosingByteReader() function to our "tools/iotools.go" source file, and add a new test function named TestClosingByteReaderNopClose() to the "tools/iotools_test.go" source file. This test function simply verifies that the Close() method of the ClosingByteReader structure performs no action, as we expect that it should not do so.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request moves CopyCallback (and its friends) out of the
progresspackage and into thetoolspackage. Since this is based on #2747, an inter-diff can be summarized as a4ff7b8.EDIT: This is the next step in removing the
progresspackage, as outlined in #2743. Prior to this pull request,progressconsisted of:Progressinterface*progress.Spinnerand*progress.Meter.CopyCallback(and related utilities).As it has grown,
CopyCallback's use has become less related to the rest of theprogresspackage. Since it is used in many locations within Git LFS, this pull request proposes moving it to thetoolspackage. I think that since its surface area is small,CopyCallback-esque functionality does not warrant an entire package of its own, and it would fit well in its current state within thetoolspackage.Following this pull request, the remainder of
progresswill be moved into thetasklogandtqpackages, thus enabling us to remove theprogresspackage entirely./cc @git-lfs/core #2743