Merge pull request #2510 from git-lfs/size-conv-warn-on-clean
commands,lfs: warn on 4gb size conversion during clean
This commit is contained in:
commit
2ae1594579
@ -22,7 +22,7 @@ import (
|
|||||||
//
|
//
|
||||||
// If the object read from "from" is _already_ a clean pointer, then it will be
|
// If the object read from "from" is _already_ a clean pointer, then it will be
|
||||||
// written out verbatim to "to", without trying to make it a pointer again.
|
// written out verbatim to "to", without trying to make it a pointer again.
|
||||||
func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) error {
|
func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) (*lfs.Pointer, error) {
|
||||||
var cb progress.CopyCallback
|
var cb progress.CopyCallback
|
||||||
var file *os.File
|
var file *os.File
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) error
|
|||||||
// containing the bytes that we should write back out to Git.
|
// containing the bytes that we should write back out to Git.
|
||||||
|
|
||||||
_, err = to.Write(errors.GetContext(err, "bytes").([]byte))
|
_, err = to.Write(errors.GetContext(err, "bytes").([]byte))
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,7 +85,7 @@ func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = lfs.EncodePointer(to, cleaned.Pointer)
|
_, err = lfs.EncodePointer(to, cleaned.Pointer)
|
||||||
return err
|
return cleaned.Pointer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanCommand(cmd *cobra.Command, args []string) {
|
func cleanCommand(cmd *cobra.Command, args []string) {
|
||||||
@ -97,9 +97,14 @@ func cleanCommand(cmd *cobra.Command, args []string) {
|
|||||||
fileName = args[0]
|
fileName = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := clean(os.Stdout, os.Stdin, fileName, -1); err != nil {
|
ptr, err := clean(os.Stdout, os.Stdin, fileName, -1)
|
||||||
|
if err != nil {
|
||||||
Error(err.Error())
|
Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ptr != nil && possiblyMalformedObjectSize(ptr.Size) {
|
||||||
|
Error("Possibly malformed conversion on Windows, see `git lfs help smudge` for more details.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -63,7 +63,13 @@ func filterCommand(cmd *cobra.Command, args []string) {
|
|||||||
switch req.Header["command"] {
|
switch req.Header["command"] {
|
||||||
case "clean":
|
case "clean":
|
||||||
w = git.NewPktlineWriter(os.Stdout, cleanFilterBufferCapacity)
|
w = git.NewPktlineWriter(os.Stdout, cleanFilterBufferCapacity)
|
||||||
err = clean(w, req.Payload, req.Header["pathname"], -1)
|
|
||||||
|
var ptr *lfs.Pointer
|
||||||
|
ptr, err = clean(w, req.Payload, req.Header["pathname"], -1)
|
||||||
|
|
||||||
|
if ptr != nil {
|
||||||
|
n = ptr.Size
|
||||||
|
}
|
||||||
case "smudge":
|
case "smudge":
|
||||||
w = git.NewPktlineWriter(os.Stdout, smudgeFilterBufferCapacity)
|
w = git.NewPktlineWriter(os.Stdout, smudgeFilterBufferCapacity)
|
||||||
n, err = smudge(w, req.Payload, req.Header["pathname"], skip, filter)
|
n, err = smudge(w, req.Payload, req.Header["pathname"], skip, filter)
|
||||||
@ -74,7 +80,7 @@ func filterCommand(cmd *cobra.Command, args []string) {
|
|||||||
if errors.IsNotAPointerError(err) {
|
if errors.IsNotAPointerError(err) {
|
||||||
malformed = append(malformed, req.Header["pathname"])
|
malformed = append(malformed, req.Header["pathname"])
|
||||||
err = nil
|
err = nil
|
||||||
} else if possiblyMalformedSmudge(n) {
|
} else if possiblyMalformedObjectSize(n) {
|
||||||
malformedOnWindows = append(malformedOnWindows, req.Header["pathname"])
|
malformedOnWindows = append(malformedOnWindows, req.Header["pathname"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func migrateImportCommand(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
if err := clean(&buf, b.Contents, path, b.Size); err != nil {
|
if _, err := clean(&buf, b.Contents, path, b.Size); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ func smudgeCommand(cmd *cobra.Command, args []string) {
|
|||||||
} else {
|
} else {
|
||||||
Error(err.Error())
|
Error(err.Error())
|
||||||
}
|
}
|
||||||
} else if possiblyMalformedSmudge(n) {
|
} else if possiblyMalformedObjectSize(n) {
|
||||||
fmt.Fprintln(os.Stderr, "Possibly malformed smudge on Windows: see `git lfs help smudge` for more info.")
|
fmt.Fprintln(os.Stderr, "Possibly malformed smudge on Windows: see `git lfs help smudge` for more info.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ func smudgeFilename(args []string) string {
|
|||||||
return "<unknown file>"
|
return "<unknown file>"
|
||||||
}
|
}
|
||||||
|
|
||||||
func possiblyMalformedSmudge(n int64) bool {
|
func possiblyMalformedObjectSize(n int64) bool {
|
||||||
return n > 4*humanize.Gigabyte
|
return n > 4*humanize.Gigabyte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user