Skip to content

commands/status: add blob info to each entry - #2070

Merged
ttaylorr merged 10 commits into
masterfrom
status-blob-info
Mar 23, 2017
Merged

ttaylorr merged 10 commits into
masterfrom
status-blob-info

Conversation

@ttaylorr

Copy link
Copy Markdown
Contributor

This pull-request makes it easier to diagnose why certain files are modified by LFS by adding blob info to each status line entry in the git lfs status command.

Here's what the output looks like:

On branch master

Git LFS objects to be committed:

    file2.dat (LFS: eeaf82b)
    file3.dat (LFS: a12942e)

Git LFS objects not staged for commit:

    file1.dat (LFS: 1307990 -> Git: 8735179)
    file3.dat (Git: 0dc8537)

The () shows some meta information about each entry's source and destination. For each end, it shows whether the file is tracked by Git or LFS, and the contents SHA of each. The contents SHA is either the shasum -a 256 of the blob's contents (NB: not the blob SHA itself), or the pointer's OID (if the file is tracked by LFS).

The extra info contained between the () comes from the following rules:

  1. If the file is new (marked as A for addition), show a) the source (either Git: or LFS:) & the blob contents SHA.
  2. If the file is not new, is a copy, a modification, or etc., show both the source and destination (either: Git: or LFS:) as well as the blob contents SHA for each.

The blob contents SHA is defined as:

  • If the file is handled by LFS and is currently parse-able as an LFS pointer, mark it as LFS. A file is parse-able as an LFS pointer if it wasn't checked out (using the -I or -X flags), or is staged into the index and tracked with the LFS filter in your repository's .gitattributes.
  • If the file is not tracked by LFS, or is tracked by LFS and is not yet staged into the index (meaning the LFS has not yet clean-ed the file) the file is tracked by Git. If the file is tracked by LFS, but isn't parse-able as an LFS pointer (meaning the clean/smudge filters were skipped, or the file was already committed as a large object into the Git history), show the file as having a Git: source.

A few things that I'd like to address beyond this pull-request:

  1. Since status: use DiffIndexScanner to populate results #2042, we're showing all files (not just those tracked by LFS) in the status output. I think this makes sense since we want to show files that are supposed to be tracked by LFS but aren't. One thing we could do is only show files which match the patterns in .gitattributes, but I like the complete-ness of what we have right now.
  2. Files are shown as coming from Git: if they are tracked by LFS and not yet staged. This is technically correct, but we could show a better prefix, or try and figure out if they would be tracked by LFS. I don't know offhand of a complete way to do this, since we not only have to check the contents of the repository's .gitattributes file(s), but also whether or not the user has a valid LFS clean/smudge/process filter installed.
  3. diff-index doesn't show new, untracked files. This may have always been a problem with the status command, but deserves investigation nonetheless.

/cc @git-lfs/core

@ttaylorr ttaylorr added this to the v2.1.0 milestone Mar 23, 2017
@ttaylorr
ttaylorr requested a review from technoweenie March 23, 2017 16:20

@technoweenie technoweenie left a comment

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.

This is looking really good. Called out a few things though.

Comment thread lfs/gitscanner_catfilebatch.go Outdated
}

func (s *catFileBatchScanner) Scan() bool {
func (s *CatFileBatchScanner) Scan(sha []byte) bool {

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 like this improvement of calling Scan(oid), instead of manually writing to stdin. Why does it take a []byte though? The callers I saw get a sha as a string.

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.

Good call. Since all of the callers have strings when they call Scan() I went ahead and made this change in: b51d649.

Comment thread lfs/gitscanner_catfilebatch.go Outdated
sha := sha256.New()
buf := make([]byte, size)
read, err := io.ReadFull(s.r, buf)
read, err := io.ReadFull(io.TeeReader(s.r, sha), buf)

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.

Using the CatFileBatchScanner in git lfs status will cause it to load potentially huge blobs in memory. This doesn't happen in normal git scanning because the CatFileBatchCheckScanner filters any blobs over lfs.blobSizeCutoff = 1024.

Is it possible to skip the buf init if the the blob size here is also over that threshold?

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.

Great catch -- I made sure that we only read into buf is size <= blobSizeCutoff in 844c0b0.

Comment thread commands/command_status.go Outdated
return "", "", err
}

return fmt.Sprintf("%x", shasum.Sum(nil)), "Git", nil

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.

Since this is reading from the local fs, and not git, what about "New" or even "File" as a better prefix?

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.

I dig it: 3a858da

@ttaylorr
ttaylorr merged commit 3eb6401 into master Mar 23, 2017
@ttaylorr
ttaylorr deleted the status-blob-info branch March 23, 2017 19:06
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Mar 11, 2021
The blobSizeCutoff limit is defined such that "any file
with a size below this cutoff will be scanned" when looking
for LFS pointer blobs.  In general this is true, but there
are few instances where the check is applied such that blobs
matching the cutoff limit are also scanned.

We therefore adjust these to match the same comparison logic
used elsewhere with this limit.

Two of these checks are in the PointerScanner.next() method
used by the runCatFileBatch() function; they were introduced
in commit 844c0b0 in
PR git-lfs#2070 and scan Git objects for eligible LFS pointers
when reading the output of "git cat-file --batch".  Note
that the corresponding runCatFileBatchCheck() function's
catFileBatchCheckScanner.next() method excludes blobs whose
size is above or equal to the limit (with a default limit of
blobSizeCutoff); this aligns with other usage and checks
of the blobSizeCutoff maximum as well.

The other check is in the DecodePointerFromFile()
function where it is used to exclude from consideration as
Git LFS pointers any files larger than blobSizeCutoff.
This function is ultimately called by the "git lfs checkout"
command; the original implementation was added in commit
001ddcd in PR git-lfs#527.
pcal43 pushed a commit to pcal43/git-lfs-hack that referenced this pull request Jul 22, 2021
The blobSizeCutoff limit is defined such that "any file
with a size below this cutoff will be scanned" when looking
for LFS pointer blobs.  In general this is true, but there
are few instances where the check is applied such that blobs
matching the cutoff limit are also scanned.

We therefore adjust these to match the same comparison logic
used elsewhere with this limit.

Two of these checks are in the PointerScanner.next() method
used by the runCatFileBatch() function; they were introduced
in commit 844c0b0 in
PR git-lfs#2070 and scan Git objects for eligible LFS pointers
when reading the output of "git cat-file --batch".  Note
that the corresponding runCatFileBatchCheck() function's
catFileBatchCheckScanner.next() method excludes blobs whose
size is above or equal to the limit (with a default limit of
blobSizeCutoff); this aligns with other usage and checks
of the blobSizeCutoff maximum as well.

The other check is in the DecodePointerFromFile()
function where it is used to exclude from consideration as
Git LFS pointers any files larger than blobSizeCutoff.
This function is ultimately called by the "git lfs checkout"
command; the original implementation was added in commit
001ddcd in PR git-lfs#527.
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.

2 participants