Skip to content

Progress updates for filters (clean, smudge, push) - #97

Merged
technoweenie merged 18 commits into
masterfrom
filter-progress
Aug 7, 2014
Merged

technoweenie merged 18 commits into
masterfrom
filter-progress

Conversation

@technoweenie

Copy link
Copy Markdown
Contributor

Implements #95. If an app sets the GIT_MEDIA_PROGRESS env, 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.

smudge 1/1 0 my-image.jpg
smudge 1/1 50 my-image.jpg
smudge 1/1 100 my-image.jpg
smudge 1/1 0 other-image.jpg
smudge 1/1 25 other-image.jpg
smudge 1/1 100 other-image.jpg

Some caveats:

  • This relies on the %f flag in the clean/smudge filter definitions. Git will pass the filename as an argument to git 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.
  • smudge and clean events don't know how many files are part of the current operation, so they always report "1/1".
  • stream progress updates for smudge
  • stream progress updates for clean
  • stream progress updates for push

@technoweenie

Copy link
Copy Markdown
Contributor Author

Thinking I might update this format with a 3rd arg: event.

  • smudge - Getting file contents (either by downloading from the endpoint or looking in .git/media) for a Git Media pointer
  • clean - Writing a Git Media pointer to the Git odb.
  • push - Uploading a Git Media file to the endpoint.

Do we even need clean events? Git Media basically just copies the file to .git/media and queues it to be uploaded in the next push command.

@joshaber: thoughts?

@technoweenie

Copy link
Copy Markdown
Contributor Author

Works for smudge:

$ GIT_MEDIA_PROGRESS=/Users/rick/github/wat/gitmediatest.log git clone https://github.com/github/gitmediatest
Cloning into 'gitmediatest'...
remote: Counting objects: 61, done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 61 (delta 20), reused 60 (delta 20)
Unpacking objects: 100% (61/61), done.
Checking connectivity... done.
Checking out files: 100% (13/13), done.

$ tail -f wat/gitmediatest.log
waffle-taco.jpg 0
waffle-taco.jpg 51
waffle-taco.jpg 100

@joshaber

joshaber commented Aug 7, 2014

Copy link
Copy Markdown

event would be fine, though I don't think we need it since we'll already know it from the context.

clean is probably good to have. In most cases it'll be fast enough that it doesn't matter but for pathological cases...

@technoweenie

Copy link
Copy Markdown
Contributor Author

Flipped the format so it's easier to handle files with spaces.

0 Arnold_DrosteEffect_DGDO.gif
0 mac-icon.png
0 mac.zip
0 mad-typer.gif
0 nakamayko.gif
0 quake.gif
0 tank.gif
0 video test/video.mp4
0 video/video.mp4
0 waffle-taco.jpg
51 waffle-taco.jpg
100 waffle-taco.jpg

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 event, it'll be in the front of the percentage.

easier to parse lines with filenames that include spaces
@joshaber

joshaber commented Aug 7, 2014

Copy link
Copy Markdown

Good call 👍

@technoweenie

Copy link
Copy Markdown
Contributor Author

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.

smudge 0 Arnold_DrosteEffect_DGDO.gif
smudge 1 Arnold_DrosteEffect_DGDO.gif
smudge 2 Arnold_DrosteEffect_DGDO.gif
smudge 3 Arnold_DrosteEffect_DGDO.gif
smudge 4 Arnold_DrosteEffect_DGDO.gif
smudge 5 Arnold_DrosteEffect_DGDO.gif
smudge 6 Arnold_DrosteEffect_DGDO.gif
smudge 7 Arnold_DrosteEffect_DGDO.gif
smudge 8 Arnold_DrosteEffect_DGDO.gif
smudge 9 Arnold_DrosteEffect_DGDO.gif
smudge 10 Arnold_DrosteEffect_DGDO.gif
smudge 11 Arnold_DrosteEffect_DGDO.gif
smudge 12 Arnold_DrosteEffect_DGDO.gif
smudge 13 Arnold_DrosteEffect_DGDO.gif
smudge 14 Arnold_DrosteEffect_DGDO.gif
smudge 15 Arnold_DrosteEffect_DGDO.gif
smudge 16 Arnold_DrosteEffect_DGDO.gif
smudge 17 Arnold_DrosteEffect_DGDO.gif
smudge 18 Arnold_DrosteEffect_DGDO.gif
smudge 19 Arnold_DrosteEffect_DGDO.gif
smudge 20 Arnold_DrosteEffect_DGDO.gif
smudge 21 Arnold_DrosteEffect_DGDO.gif
smudge 22 Arnold_DrosteEffect_DGDO.gif
smudge 23 Arnold_DrosteEffect_DGDO.gif
smudge 24 Arnold_DrosteEffect_DGDO.gif
smudge 25 Arnold_DrosteEffect_DGDO.gif
smudge 26 Arnold_DrosteEffect_DGDO.gif
smudge 27 Arnold_DrosteEffect_DGDO.gif
smudge 28 Arnold_DrosteEffect_DGDO.gif
smudge 29 Arnold_DrosteEffect_DGDO.gif
smudge 30 Arnold_DrosteEffect_DGDO.gif
smudge 31 Arnold_DrosteEffect_DGDO.gif
smudge 32 Arnold_DrosteEffect_DGDO.gif
smudge 33 Arnold_DrosteEffect_DGDO.gif
smudge 34 Arnold_DrosteEffect_DGDO.gif
smudge 35 Arnold_DrosteEffect_DGDO.gif
smudge 36 Arnold_DrosteEffect_DGDO.gif
smudge 37 Arnold_DrosteEffect_DGDO.gif
smudge 38 Arnold_DrosteEffect_DGDO.gif
smudge 39 Arnold_DrosteEffect_DGDO.gif
smudge 40 Arnold_DrosteEffect_DGDO.gif
smudge 41 Arnold_DrosteEffect_DGDO.gif
smudge 42 Arnold_DrosteEffect_DGDO.gif
smudge 43 Arnold_DrosteEffect_DGDO.gif
smudge 44 Arnold_DrosteEffect_DGDO.gif
smudge 45 Arnold_DrosteEffect_DGDO.gif
smudge 46 Arnold_DrosteEffect_DGDO.gif
smudge 47 Arnold_DrosteEffect_DGDO.gif
smudge 48 Arnold_DrosteEffect_DGDO.gif
smudge 49 Arnold_DrosteEffect_DGDO.gif
smudge 50 Arnold_DrosteEffect_DGDO.gif
smudge 51 Arnold_DrosteEffect_DGDO.gif
smudge 52 Arnold_DrosteEffect_DGDO.gif
smudge 53 Arnold_DrosteEffect_DGDO.gif
smudge 54 Arnold_DrosteEffect_DGDO.gif
smudge 55 Arnold_DrosteEffect_DGDO.gif
smudge 56 Arnold_DrosteEffect_DGDO.gif
smudge 57 Arnold_DrosteEffect_DGDO.gif
smudge 58 Arnold_DrosteEffect_DGDO.gif
smudge 59 Arnold_DrosteEffect_DGDO.gif
smudge 60 Arnold_DrosteEffect_DGDO.gif
smudge 61 Arnold_DrosteEffect_DGDO.gif
smudge 62 Arnold_DrosteEffect_DGDO.gif
smudge 63 Arnold_DrosteEffect_DGDO.gif
smudge 64 Arnold_DrosteEffect_DGDO.gif
smudge 65 Arnold_DrosteEffect_DGDO.gif
smudge 66 Arnold_DrosteEffect_DGDO.gif
smudge 67 Arnold_DrosteEffect_DGDO.gif
smudge 68 Arnold_DrosteEffect_DGDO.gif
smudge 69 Arnold_DrosteEffect_DGDO.gif
smudge 70 Arnold_DrosteEffect_DGDO.gif
smudge 71 Arnold_DrosteEffect_DGDO.gif
smudge 72 Arnold_DrosteEffect_DGDO.gif
smudge 73 Arnold_DrosteEffect_DGDO.gif
smudge 74 Arnold_DrosteEffect_DGDO.gif
smudge 75 Arnold_DrosteEffect_DGDO.gif
smudge 76 Arnold_DrosteEffect_DGDO.gif
smudge 77 Arnold_DrosteEffect_DGDO.gif
smudge 78 Arnold_DrosteEffect_DGDO.gif
smudge 79 Arnold_DrosteEffect_DGDO.gif
smudge 80 Arnold_DrosteEffect_DGDO.gif
smudge 81 Arnold_DrosteEffect_DGDO.gif
smudge 82 Arnold_DrosteEffect_DGDO.gif
smudge 83 Arnold_DrosteEffect_DGDO.gif
smudge 84 Arnold_DrosteEffect_DGDO.gif
smudge 85 Arnold_DrosteEffect_DGDO.gif
smudge 86 Arnold_DrosteEffect_DGDO.gif
smudge 87 Arnold_DrosteEffect_DGDO.gif
smudge 88 Arnold_DrosteEffect_DGDO.gif
smudge 89 Arnold_DrosteEffect_DGDO.gif
smudge 90 Arnold_DrosteEffect_DGDO.gif
smudge 91 Arnold_DrosteEffect_DGDO.gif
smudge 92 Arnold_DrosteEffect_DGDO.gif
smudge 93 Arnold_DrosteEffect_DGDO.gif
smudge 94 Arnold_DrosteEffect_DGDO.gif
smudge 95 Arnold_DrosteEffect_DGDO.gif
smudge 96 Arnold_DrosteEffect_DGDO.gif
smudge 97 Arnold_DrosteEffect_DGDO.gif
smudge 98 Arnold_DrosteEffect_DGDO.gif
smudge 99 Arnold_DrosteEffect_DGDO.gif
smudge 0 mac-icon.png
smudge 98 mac-icon.png

@technoweenie

Copy link
Copy Markdown
Contributor Author

The clean implementation is a little weird. When Git adds a file, it simply pipes the file to git media clean, with the filename:

# dramatization of how git internals work
cat foo.zip | git media clean foo.zip

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:

clean 0 video test/nightly news.jpg
clean 8 video test/nightly news.jpg
clean 17 video test/nightly news.jpg
clean 25 video test/nightly news.jpg
clean 34 video test/nightly news.jpg
clean 43 video test/nightly news.jpg
clean 51 video test/nightly news.jpg
clean 60 video test/nightly news.jpg
clean 68 video test/nightly news.jpg
clean 77 video test/nightly news.jpg
clean 86 video test/nightly news.jpg
clean 94 video test/nightly news.jpg
clean 100 video test/nightly news.jpg

@technoweenie

Copy link
Copy Markdown
Contributor Author

Added an indicator of how many files are part of the current action. Any smudge and clean events still show 1/1. But we can at least get numbers out of git media push:

smudge 1/1 0 waffle-taco.jpg
smudge 1/1 51 waffle-taco.jpg
smudge 1/1 100 waffle-taco.jpg

clean 1/1 0 video test/nightly news.jpg
clean 1/1 94 video test/nightly news.jpg
clean 1/1 100 video test/nightly news.jpg

push 1/2 0 cloak-dagger-and-galactus.png
push 1/2 1 cloak-dagger-and-galactus.png
push 1/2 2 cloak-dagger-and-galactus.png
push 1/2 3 cloak-dagger-and-galactus.png
push 1/2 4 cloak-dagger-and-galactus.png
push 1/2 5 cloak-dagger-and-galactus.png
push 1/2 6 cloak-dagger-and-galactus.png
push 1/2 7 cloak-dagger-and-galactus.png
push 1/2 8 cloak-dagger-and-galactus.png
push 1/2 9 cloak-dagger-and-galactus.png

@technoweenie

Copy link
Copy Markdown
Contributor Author

Okay, ready for some 👀

@joshaber

joshaber commented Aug 7, 2014

Copy link
Copy Markdown

From a consumer point of view, this is ✨

Comment thread commands/command_clean.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious under what circumstances os.Stat returns a nil error and a nil stat?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, actually.

@rubyist

rubyist commented Aug 7, 2014

Copy link
Copy Markdown
Contributor

Looks reasonable. We can probably also remove the cheggaaa/pb dep (and any code that might be using it). That was the old progress bar stuff that we stopped using a while ago.

@technoweenie

Copy link
Copy Markdown
Contributor Author

The pb package is still useful for STDOUT on git media push. Maybe it doesn't matter though since people won't run it directly.

@rubyist

rubyist commented Aug 7, 2014

Copy link
Copy Markdown
Contributor

Ah, good point.

technoweenie added a commit that referenced this pull request Aug 7, 2014
Progress updates for filters (clean, smudge, push)
@technoweenie
technoweenie merged commit 3cf4399 into master Aug 7, 2014
@technoweenie
technoweenie deleted the filter-progress branch August 7, 2014 19:50
chrisd8088 added a commit that referenced this pull request Aug 5, 2026
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.
chrisd8088 added a commit that referenced this pull request Aug 5, 2026
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.
chrisd8088 added a commit that referenced this pull request Aug 5, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants