Skip to content

progress: move CopyCallback (& related) to package 'tools' - #2749

Merged
ttaylorr merged 3 commits into
masterfrom
progress-move-ccb
Nov 22, 2017
Merged

ttaylorr merged 3 commits into
masterfrom
progress-move-ccb

Conversation

@ttaylorr

@ttaylorr ttaylorr commented Nov 22, 2017 •

Copy link
Copy Markdown
Contributor

This pull request moves CopyCallback (and its friends) out of the progress package and into the tools package. Since this is based on #2747, an inter-diff can be summarized as a4ff7b8.

EDIT: This is the next step in removing the progress package, as outlined in #2743. Prior to this pull request, progress consisted of:

  1. The Progress interface
  2. Implementations of the above as *progress.Spinner and *progress.Meter.
  3. CopyCallback (and related utilities).

As it has grown, CopyCallback's use has become less related to the rest of the progress package. Since it is used in many locations within Git LFS, this pull request proposes moving it to the tools package. 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 the tools package.

Following this pull request, the remainder of progress will be moved into the tasklog and tq packages, thus enabling us to remove the progress package entirely.

/cc @git-lfs/core #2743

@ttaylorr ttaylorr added this to the v2.4.0 milestone Nov 22, 2017
@ttaylorr
ttaylorr merged commit 30b8d3b into master Nov 22, 2017
@ttaylorr
ttaylorr deleted the progress-move-ccb branch November 22, 2017 22:25
@ttaylorr

Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant