-
Notifications
You must be signed in to change notification settings - Fork 0
MinChunkSize: 10MB #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
17fc96a
MinChunkSize: 10MB
bwalsh bfba83c
fix:improve-multipart #18
bwalsh c498c56
improve OptimalChunkSize.scaleLinear
bwalsh 1510a7d
adds optimal-chunk-size
bwalsh a5c310c
table-driven tests GetLfsCustomTransferInt
bwalsh b65c2e7
Initial plan
Copilot 3810eca
Address PR review comments: fix naming, formatting, and test coverage
Copilot 6dfcdcf
Add logging for git config errors and improve documentation structure
Copilot 1dd8ae4
Fix spelling: terrabytes → terabytes
Copilot b9174c3
Merge pull request #21 from calypr/copilot/sub-pr-19
bwalsh 514394f
wip
bwalsh 44cc0c8
adds ProgressEvent
bwalsh 06376c1
Initial plan
Copilot a6a9949
Fix nil pointer dereferences and duplicate progress events
Copilot 1a6ed52
Fix nil pointer dereferences and duplicate progress events in upload …
bwalsh 11f5de5
adds tests
bwalsh 0c83aee
adds tests
bwalsh 3d440e7
add noop ProgressCallback
bwalsh 6bbf0a4
feature/progress-event
bwalsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestGetLfsCustomTransferInt(t *testing.T) { | ||
| configDir := t.TempDir() | ||
| configPath := filepath.Join(configDir, "gitconfig") | ||
|
|
||
| setConfig := func(t *testing.T, key, value string) { | ||
| t.Helper() | ||
| cmd := exec.Command("git", "config", "--file", configPath, key, value) | ||
| if err := cmd.Run(); err != nil { | ||
| t.Fatalf("set git config %s=%s: %v", key, value, err) | ||
| } | ||
| } | ||
|
|
||
| setEnv := func(t *testing.T) { | ||
| t.Helper() | ||
| t.Setenv("GIT_CONFIG_GLOBAL", configPath) | ||
| t.Setenv("GIT_CONFIG_SYSTEM", os.DevNull) | ||
| t.Setenv("GIT_CONFIG_NOSYSTEM", "1") | ||
| } | ||
|
|
||
| const key = "lfs.customtransfer.drs.multipart-min-chunk-size" | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| value string | ||
| defaultVal int64 | ||
| want int64 | ||
| wantErr bool | ||
| setValue bool | ||
| }{ | ||
| { | ||
| name: "missing uses default", | ||
| defaultVal: 10, | ||
| want: 10, | ||
| wantErr: false, | ||
| setValue: false, | ||
| }, | ||
| { | ||
| name: "valid value", | ||
| value: "25", | ||
| defaultVal: 10, | ||
| want: 25, | ||
| wantErr: false, | ||
| setValue: true, | ||
| }, | ||
| { | ||
| name: "negative value", | ||
| value: "-3", | ||
| defaultVal: 10, | ||
| want: 10, | ||
| wantErr: true, | ||
| setValue: true, | ||
| }, | ||
| { | ||
| name: "zero value", | ||
| value: "0", | ||
| defaultVal: 10, | ||
| want: 10, | ||
| wantErr: true, | ||
| setValue: true, | ||
| }, | ||
| { | ||
| name: "over max", | ||
| value: "501", | ||
| defaultVal: 10, | ||
| want: 10, | ||
| wantErr: true, | ||
| setValue: true, | ||
| }, | ||
| { | ||
| name: "non-integer", | ||
| value: "abc", | ||
| defaultVal: 10, | ||
| want: 10, | ||
| wantErr: true, | ||
| setValue: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| if err := os.WriteFile(configPath, nil, 0o600); err != nil { | ||
| t.Fatalf("reset git config: %v", err) | ||
| } | ||
| if tt.setValue { | ||
| setConfig(t, key, tt.value) | ||
| } | ||
| setEnv(t) | ||
|
|
||
| got, err := GetLfsCustomTransferInt(key, tt.defaultVal) | ||
| if tt.wantErr && err == nil { | ||
| t.Fatalf("expected error, got nil") | ||
| } | ||
| if !tt.wantErr && err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if got != tt.want { | ||
| t.Fatalf("value = %d, want %d", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package common | ||
|
|
||
| // ProgressEvent matches the Git LFS custom transfer progress payload. | ||
| type ProgressEvent struct { | ||
| Event string `json:"event"` | ||
| Oid string `json:"oid"` | ||
| BytesSoFar int64 `json:"bytesSoFar"` | ||
| BytesSinceLast int64 `json:"bytesSinceLast"` | ||
| } | ||
|
|
||
| // ProgressCallback emits transfer progress updates. | ||
| type ProgressCallback func(ProgressEvent) error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package download | ||
|
|
||
| import ( | ||
| "io" | ||
|
|
||
| "github.com/calypr/data-client/client/common" | ||
| ) | ||
|
|
||
| type progressWriter struct { | ||
| writer io.Writer | ||
| onProgress common.ProgressCallback | ||
| oid string | ||
| total int64 | ||
| bytesSoFar int64 | ||
| } | ||
|
|
||
| func newProgressWriter(writer io.Writer, onProgress common.ProgressCallback, oid string, total int64) *progressWriter { | ||
| return &progressWriter{ | ||
| writer: writer, | ||
| onProgress: onProgress, | ||
| oid: oid, | ||
| total: total, | ||
| } | ||
| } | ||
|
|
||
| func (pw *progressWriter) Write(p []byte) (int, error) { | ||
| n, err := pw.writer.Write(p) | ||
| if n > 0 && pw.onProgress != nil { | ||
| delta := int64(n) | ||
| pw.bytesSoFar += delta | ||
| if progressErr := pw.onProgress(common.ProgressEvent{ | ||
| Event: "progress", | ||
| Oid: pw.oid, | ||
| BytesSoFar: pw.bytesSoFar, | ||
| BytesSinceLast: delta, | ||
| }); progressErr != nil { | ||
| return n, progressErr | ||
| } | ||
| } | ||
| return n, err | ||
| } | ||
|
|
||
| func (pw *progressWriter) Finalize() error { | ||
| if pw.onProgress == nil { | ||
| return nil | ||
| } | ||
| if pw.total == 0 || pw.bytesSoFar >= pw.total { | ||
| return nil | ||
| } | ||
| delta := pw.total - pw.bytesSoFar | ||
| pw.bytesSoFar = pw.total | ||
| return pw.onProgress(common.ProgressEvent{ | ||
| Event: "progress", | ||
| Oid: pw.oid, | ||
| BytesSoFar: pw.bytesSoFar, | ||
| BytesSinceLast: delta, | ||
| }) | ||
| } | ||
|
|
||
| func resolveDownloadOID(fdr common.FileDownloadResponseObject) string { | ||
| if fdr.OID != "" { | ||
| return fdr.OID | ||
| } | ||
| if fdr.GUID != "" { | ||
| return fdr.GUID | ||
| } | ||
| return fdr.Filename | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.