Repository navigation
Progress updates for filters (clean, smudge, push) - #97
Conversation
|
Thinking I might update this format with a 3rd arg:
Do we even need @joshaber: thoughts? |
|
Works for |
|
|
|
Flipped the format so it's easier to handle files with spaces. An application knows that each line will have 2 parts, regardless of how many spaces are in the filename. You could use this Go code to parse those lines, for example: strings.SplitN("0 foo bar/baz", " ", 2)When I add |
easier to parse lines with filenames that include spaces
|
Good call 👍 |
|
We can fake the size if the pointer file doesn't have a size by the Content-Length of the git media HTTP response. Unfortunately, the git media HTTP API adds a small header for security reasons. So, these files will never get to 100. However, these old pointer files will be pretty rare once this is shipped, so I think it's fine. |
|
The Git Media clean has no idea how much content will flow through STDIN. Git Media guesses it by trying to stat the filename passed in the arg. That of course assumes the path is correct. Here are the stats emitted for a ~380k file: |
get stats from the reader input of a PUT request
|
Added an indicator of how many files are part of the current action. Any |
|
Okay, ready for some 👀 |
|
From a consumer point of view, this is ✨ |
There was a problem hiding this comment.
I'm curious under what circumstances os.Stat returns a nil error and a nil stat?
There was a problem hiding this comment.
Not sure, actually.
|
Looks reasonable. We can probably also remove the |
|
The |
|
Ah, good point. |
Progress updates for filters (clean, smudge, push)
Our "tools" package defines two structures which perform similar purposes, the BodyWithCallback and CallbackReader structures, whose Read() methods are identical and invoke a callback function after first calling the Read() method of an underlying resource. The only significant difference between the two structures is that the BodyWithCallback structure's methods implement the ReadSeekCloser interface from the Go standard library's "io" package, while the CallbackReader structure's methods only implement the Reader interface from the "io" package. We introduced the first version of our CallbackReader structure in commit d7a787d of PR #97, along with a Read() method quite similar to the one currently defined for the structure. Later, in commit e04316f of PR #1839, we added the initial version of what is now the BodyWithCallback structure, at which time we simply copied the Read() method of the CallbackReader structure to create an identical method for the BodyWithCallback structure. The implementation of the two Read() methods is identical, so when we fix a bug in one, we have to make the same change in the other also. For instance, in commit a2a7b09 of PR #1955 we revised both methods to address a problem whereby they would fail to invoke their callback functions if the underlying Read() method read a non-zero number of bytes but also encountered an EOF condition. In subsequent commits in this PR we intend to alter the design of the Read() methods of the BodyWithCallback and CallbackReader structures, and then to make further changes to handle instances where the total size of a Git LFS object is initially unknown. As we would prefer to avoid making these revisions in two places, and to avoid future problems where we might accidentally update only one of the two Read() methods, we begin by refactoring both the methods and the BodyWithCallback and CallbackReader structures so they share a common internal implementation. Specifically, we introduce a "callbackState" structure whose fields represent the current state for a given callback function, and then we embed this structure in the BodyWithCallback and CallbackReader structures. These structures now only have one unique field each to store their underlying data source. We also define a read() method for the "callbackState" structure, with an identical design to the existing Read() methods of the BodyWithCallback and CallbackReader structures except that it accepts a parameter of the Reader type from the "io" package. We then revise the Read() methods of the BodyWithCallback and CallbackReader structures to simply invoke this new read() method and pass their respective data sources as its Reader type parameter. Note that in a future PR we may further refactor the implementation of the BodyWithCallback and CallbackReader structures to replace them entirely with a single common structure. However, as this change would affect a number of our packages, it is outside the scope of this PR, so for the time being we just revise the existing structures to share a new, common internal structure and its read() method.
In a previous commit in this PR we refactored the BodyWithCallback and CallbackReader structures in our "tools" package so that they now share a common internal implementation in the form of an internal "callbackState" structure and its read() method. We derived the design of the read() method from that of the Read() methods of the BodyWithCallback and CallbackReader structures as they were previously defined. This design dates back to the original introduction of the CallbackReader structure in commit d7a787d of PR #97. One notable feature of the current implementation of both our new read() method as well as that of its predecessors is that when the registered callback function is invoked, the methods always use the function's "error" return value as their own return value. As a consequence, if the underlying resource's Read() method reads a non-zero number of bytes and also encounters an EOF condition, our read() method will perform a callback and then substitute the callback function's return value for the EOF error. In the normal case where no error occurs during the callback, this will force the caller to make another invocation of our read() method, at which point no bytes will be read and so no callback will be performed, and the EOF condition will be reported to the caller. While this design is acceptable, because the Reader interface of the Go standard library's "io" package allows Read() methods to only return the EOF condition when no bytes are available to be read, it is slightly less efficient than it could be. We can improve this situation by returning an EOF error from the underlying resource's Read() method unless our callback function encountered an error condition. To implement this change, we first revise the doCallbackIfRequired() method of the "callbackState" structure so that the method returns a nil "error" value when no callback should be performed, and otherwise returns the "error" value from the callback function. Next, we update the read() method so that it saves the return value from the doCallbackIfRequired() method into a local "callbackErr" variable, and then returns the "error" value from the Read() method unless the value of the "callbackErr" variable is non-nil, in which case the read() method returns that value instead. Finally, we update two of our existing Go test functions to reflect the new behaviour of the Read() methods of the BodyWithCallback and CallbackReader structures. These tests are sufficient to demonstrate that our changes to the "callbackState" structure's read() and doCallbackIfRequired() methods in this commit mean that the read() method now preserves an EOF error from its underlying resource if the callback function is invoked and does not encounter an error. The TestBothCallbackReadersInvokeCallbackOnEagerEOF() function in our "tools" package and the TestCopyCallbackFileThrottle() function in our "lfs" package both make use of the EagerEOFByteReader structure we added to our "internal/testutil" package in a prior commit in this PR. This structure's Read() method always returns an EOF error when it reads the final bytes from a given byte slice. Previously, these two test functions expected that when an EagerEOFByteReader structure was the underlying resource of a BodyWithCallback or CallbackReader structure, that structure's Read() method would return a nil "error" value when it read the final bytes of a slice.
As described in a previous commit in this PR, several of our Git LFS commands may write progress log messages with a negative value in the denominator of the fraction representing the amount of data downloaded so far for an individual object. Specifically, the "git lfs fetch", "git lfs pull", and "git lfs smudge" commands will write such log messages when a progress log is enabled with the GIT_LFS_PROGRESS environment variable and the response to an HTTP object download request is content-encoded and therefore lacks a Content-Length header. As described in a previous commit in this PR, for historical reasons progress log messages are written either by the anonymous callback function created by the CopyCallbackFile() method of the GitFilter structure in our "lfs" package, or by the logBytes() method of the Meter structure in our "tq" package. However, the format of the messages is identical regardless of which function or method generates them. When the logBytes() method was first introduced in commit 710862b of PR #476, it duplicated the format of the progress log messages generated by the callback function created by the CopyCallbackFile() method. The current progress log message format in that method dates from commit 36fa23d of PR #100, but the original version of the method and its callback function themselves were added in commit fd41906 of PR #97. While we likely should refactor the logBytes() method and the CopyCallbackFile() method's callback function to share a common implementation, that change falls outside of the scope of this PR, so we defer it to a future PR. However, one of the changes we made in a prior commit in this PR now ensures that if an object's total size is initially unknown, when an EOF condition is encountered while reading the object's data, then a final progress log message is guaranteed to be written with the total size of the object represented as equal to the actual number of bytes that were read. Further, this final progress log entry will be output regardless of whether the CopyCallbackFile() method's callback function or the logBytes() method is being used to write messages to the log file. While this change affects the content of the last progress log entry written for a given object, until the EOF condition is reached, intermediate log messages may be generated which still have a negative value in the denominator of the fraction representing the amount of the object's data processed so far. These negative values occur because the length of the data to be read is initially unknown. At present, the only circumstance in which this is possible is when the HTTP response to an object download request lacks a Content-Length header, as will be the case when the response body is gzip-encoded, as we noted in the following comment on PR #6011: #6011 (comment) PR #6011 resolves a bug in our "git lfs filter-progress" and "git lfs clean" commands whereby they can pass an incorrect "totalSize" parameter to the CopyWithCallback() function. The only solution for this problem is for the commands to simply not attempt to determine the total size of an object. As a consequence, we expect that our "git lfs filter-progress" and "git lfs clean" commands will never know in advance the length of the object data they are reading from Git, and it will become a more common occurrence for the CopyCallbackFile() method's callback function and the logBytes() method to receive a "total" parameter with a negative value. We therefore now refine the format of the progress log when the total size of an object is unknown by writing a series of question mark characters ("?") in place of the denominator of the fraction which represents the amount of the object's data processed so far. We adjust the number of these question mark characters to match the length of the numerator, e.g., "123/???" and "12345/?????". To avoid implementing the necessary string formatting logic in both the CopyCallbackFile() method's callback function and the logBytes() method, we introduce a new FormatFraction() function to our "tools" package and then substitute its output in place of the appropriate fraction field in the log messages. We then add a TestFormatFraction() Go test function which verifies that the FormatFraction() function generates the expected output under a range of conditions, including when the number of bytes read so far exceeds the value provided as the total size of an object, and when the total size of an object is unknown and should be represented using various numbers of question mark characters. Finally, we update the comments in several of the tests we added to the "t/t-progress.sh" shell script in a prior commit of this PR, and we revise the "initial total unknown" test case for our TestCopyCallbackFileThrottle() test function. In that test case, we update the expected contents of the progress log because the intermediate entry which precedes the final entry should now have a series of question mark characters rather than a "-1" value in the denominator of the fraction which represents the amount of the object's data processed so far.
Implements #95. If an app sets the
GIT_MEDIA_PROGRESSenv, Git Media commands will write the file status to the file. Git Media will create the directory and file if necessary. But it is up to the calling application to cleanup the file as desired. Git Media will append to the file if it already exists.The file format is just
{filename} {percentComplete}. Git Media should always emit an entry with 0% complete.Some caveats:
%fflag in the clean/smudge filter definitions. Git will pass the filename as an argument togit media [smudge | clean]. Certain older Git versions won't send anything though. In these rare cases, the OID will be used. In the event Git Media can't even find an OID, the string<unknown file>is used. This is likely a bug though.smudgeandcleanevents don't know how many files are part of the current operation, so they always report "1/1".smudgecleanpush