Repository navigation
commands/status: add blob info to each entry - #2070
Conversation
technoweenie
left a comment
There was a problem hiding this comment.
This is looking really good. Called out a few things though.
| } | ||
|
|
||
| func (s *catFileBatchScanner) Scan() bool { | ||
| func (s *CatFileBatchScanner) Scan(sha []byte) bool { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good call. Since all of the callers have strings when they call Scan() I went ahead and made this change in: b51d649.
| sha := sha256.New() | ||
| buf := make([]byte, size) | ||
| read, err := io.ReadFull(s.r, buf) | ||
| read, err := io.ReadFull(io.TeeReader(s.r, sha), buf) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Great catch -- I made sure that we only read into buf is size <= blobSizeCutoff in 844c0b0.
| return "", "", err | ||
| } | ||
|
|
||
| return fmt.Sprintf("%x", shasum.Sum(nil)), "Git", nil |
There was a problem hiding this comment.
Since this is reading from the local fs, and not git, what about "New" or even "File" as a better prefix?
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.
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.
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 statuscommand.Here's what the output looks like:
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 theshasum -a 256of 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:Afor addition), show a) the source (eitherGit:orLFS:) & the blob contents SHA.Git:orLFS:) as well as the blob contents SHA for each.The blob contents SHA is defined as:
-Ior-Xflags), or is staged into the index and tracked with the LFSfilterin your repository's.gitattributes.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 theclean/smudgefilters were skipped, or the file was already committed as a large object into the Git history), show the file as having aGit:source.A few things that I'd like to address beyond this pull-request:
.gitattributes, but I like the complete-ness of what we have right now.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.gitattributesfile(s), but also whether or not the user has a valid LFS clean/smudge/process filter installed.diff-indexdoesn't show new, untracked files. This may have always been a problem with the status command, but deserves investigation nonetheless./cc @git-lfs/core