Skip to content

feat: lookup the .git/lfs/objects before downloading remote parts#21

Merged
rueian merged 1 commit into
mainfrom
local-hit
May 20, 2025
Merged

feat: lookup the .git/lfs/objects before downloading remote parts#21
rueian merged 1 commit into
mainfrom
local-hit

Conversation

@rueian

@rueian rueian commented May 20, 2025

Copy link
Copy Markdown
Member

Local git-lfs files added by the git add will be copied to .git/lfs/objects. We should treat it as a remote as well.

@rueian rueian requested a review from Copilot May 20, 2025 03:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a feature to check the .git/lfs/objects directory for local file objects before downloading remote parts, improving efficiency in retrieving LFS data.

  • In page.go, a new field "po" along with a conditional branch in Fetch checks for local LFS objects.
  • In node_test.go, minor test comment refinements and reordering of git push operations help streamline the test flow.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
page.go Adds a local lookup for LFS objects by introducing a new field and logic in Fetch.
node_test.go Updates comments and adjusts the placement of git push commands to refine testing.
Comments suppressed due to low confidence (1)

page.go:41

  • [nitpick] The variable name 'po' is ambiguous. Consider renaming it to a more descriptive name like 'lfsObjectsPath' to improve code readability.
po        string // .git/lfs/objects

Comment thread page.go
Comment on lines +165 to +172
if f, _ := os.Open(path); f != nil {
defer f.Close()
if _, err := f.Seek(off, io.SeekStart); err == nil {
_, err = io.CopyN(w, f, end-off)
log.Printf("local: oid=(%s) %dMB %d/%d err=%v", ptr.Oid, pagesize/(1024*1024), pageNum+1, (size+pagesize-1)/pagesize, err)
return err
}
}

Copilot AI May 20, 2025

Copy link

Choose a reason for hiding this comment

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

Consider checking and handling the error returned from os.Open instead of ignoring it; this will help diagnose issues reliably during local file access.

Suggested change
if f, _ := os.Open(path); f != nil {
defer f.Close()
if _, err := f.Seek(off, io.SeekStart); err == nil {
_, err = io.CopyN(w, f, end-off)
log.Printf("local: oid=(%s) %dMB %d/%d err=%v", ptr.Oid, pagesize/(1024*1024), pageNum+1, (size+pagesize-1)/pagesize, err)
return err
}
}
f, err := os.Open(path)
if err != nil {
log.Printf("failed to open file: %s, error: %v", path, err)
return err
}
defer f.Close()
if _, err := f.Seek(off, io.SeekStart); err == nil {
_, err = io.CopyN(w, f, end-off)
log.Printf("local: oid=(%s) %dMB %d/%d err=%v", ptr.Oid, pagesize/(1024*1024), pageNum+1, (size+pagesize-1)/pagesize, err)
return err
}

Copilot uses AI. Check for mistakes.
Signed-off-by: Rueian <rueiancsie@gmail.com>
@codecov

codecov Bot commented May 20, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@rueian rueian merged commit 0317ec6 into main May 20, 2025
2 checks passed
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.

2 participants