-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add basic repository lfs management #7199
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
zeripath
merged 30 commits into
go-gitea:master
from
zeripath:repository-lfs-management
Oct 28, 2019
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
786965e
Add basic repository lfs management
zeripath c3c2ba3
add auto-associate function
zeripath 67c9a0a
Handle git <2.6
zeripath 77bf73c
Adjust presentation of LFS oids
zeripath efd7f4c
Add basic repository lfs management
zeripath fbd8b18
add auto-associate function
zeripath 685b35a
Handle git <2.6
zeripath 1840d23
Adjust presentation of LFS oids
zeripath 4ab690f
Merge branch 'repository-lfs-management' of github.com:zeripath/gitea…
zeripath d8714f6
Merge branch 'master' into repository-lfs-management
zeripath fa5be8c
update to use xorm.io/builder
zeripath 280aa5e
Add functionality to find commits with this lfs file
zeripath 19cc760
Merge branch 'master' into repository-lfs-management
zeripath 8ed7fef
Improve find commits functionality
zeripath 0f13090
take account of foreach error
zeripath ab980f5
remove code duplication and extract to pipeline
zeripath f175676
Merge branch 'master' into repository-lfs-management
zeripath 4c7dac8
Add link to find commits on the lfs file view
zeripath 2f55a5f
Adjust commit view to state the likely branch causing the commit
zeripath adc3c98
Merge branch 'master' into repository-lfs-management
zeripath 5b6e86a
Merge branch 'master' into repository-lfs-management
zeripath 144f435
Merge branch 'master' into repository-lfs-management
zeripath af4a227
cope with moved UTF8 functions
zeripath 4138000
Merge branch 'repository-lfs-management' of github.com:zeripath/gitea…
zeripath 085417a
Merge branch 'master' into repository-lfs-management
zeripath 56d15f2
fix unknwon change
zeripath 5a4161d
Only read Oid from database
zeripath 1856f77
Apply suggestions from code review
zeripath d9bd0d0
Merge branch 'master' into repository-lfs-management
zeripath 134a946
Merge branch 'master' into repository-lfs-management
zeripath 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
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
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,94 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package pipeline | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
|
||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/log" | ||
) | ||
|
||
// CatFileBatchCheck runs cat-file with --batch-check | ||
func CatFileBatchCheck(shasToCheckReader *io.PipeReader, catFileCheckWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) { | ||
defer wg.Done() | ||
defer shasToCheckReader.Close() | ||
defer catFileCheckWriter.Close() | ||
|
||
stderr := new(bytes.Buffer) | ||
var errbuf strings.Builder | ||
cmd := git.NewCommand("cat-file", "--batch-check") | ||
if err := cmd.RunInDirFullPipeline(tmpBasePath, catFileCheckWriter, stderr, shasToCheckReader); err != nil { | ||
_ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %v - %s", tmpBasePath, err, errbuf.String())) | ||
} | ||
} | ||
|
||
// CatFileBatchCheckAllObjects runs cat-file with --batch-check --batch-all | ||
func CatFileBatchCheckAllObjects(catFileCheckWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string, errChan chan<- error) { | ||
defer wg.Done() | ||
defer catFileCheckWriter.Close() | ||
|
||
stderr := new(bytes.Buffer) | ||
var errbuf strings.Builder | ||
cmd := git.NewCommand("cat-file", "--batch-check", "--batch-all-objects") | ||
if err := cmd.RunInDirPipeline(tmpBasePath, catFileCheckWriter, stderr); err != nil { | ||
log.Error("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String()) | ||
err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String()) | ||
_ = catFileCheckWriter.CloseWithError(err) | ||
errChan <- err | ||
} | ||
} | ||
|
||
// CatFileBatch runs cat-file --batch | ||
func CatFileBatch(shasToBatchReader *io.PipeReader, catFileBatchWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) { | ||
defer wg.Done() | ||
defer shasToBatchReader.Close() | ||
defer catFileBatchWriter.Close() | ||
|
||
stderr := new(bytes.Buffer) | ||
var errbuf strings.Builder | ||
if err := git.NewCommand("cat-file", "--batch").RunInDirFullPipeline(tmpBasePath, catFileBatchWriter, stderr, shasToBatchReader); err != nil { | ||
_ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())) | ||
} | ||
} | ||
|
||
// BlobsLessThan1024FromCatFileBatchCheck reads a pipeline from cat-file --batch-check and returns the blobs <1024 in size | ||
func BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader *io.PipeReader, shasToBatchWriter *io.PipeWriter, wg *sync.WaitGroup) { | ||
defer wg.Done() | ||
defer catFileCheckReader.Close() | ||
scanner := bufio.NewScanner(catFileCheckReader) | ||
defer func() { | ||
_ = shasToBatchWriter.CloseWithError(scanner.Err()) | ||
}() | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if len(line) == 0 { | ||
continue | ||
} | ||
fields := strings.Split(line, " ") | ||
if len(fields) < 3 || fields[1] != "blob" { | ||
continue | ||
} | ||
size, _ := strconv.Atoi(fields[2]) | ||
if size > 1024 { | ||
continue | ||
} | ||
toWrite := []byte(fields[0] + "\n") | ||
for len(toWrite) > 0 { | ||
n, err := shasToBatchWriter.Write(toWrite) | ||
if err != nil { | ||
_ = catFileCheckReader.CloseWithError(err) | ||
break | ||
} | ||
toWrite = toWrite[n:] | ||
} | ||
} | ||
} |
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,28 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package pipeline | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"strings" | ||
"sync" | ||
|
||
"code.gitea.io/gitea/modules/git" | ||
) | ||
|
||
// NameRevStdin runs name-rev --stdin | ||
func NameRevStdin(shasToNameReader *io.PipeReader, nameRevStdinWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) { | ||
defer wg.Done() | ||
defer shasToNameReader.Close() | ||
defer nameRevStdinWriter.Close() | ||
|
||
stderr := new(bytes.Buffer) | ||
var errbuf strings.Builder | ||
if err := git.NewCommand("name-rev", "--stdin", "--name-only", "--always").RunInDirFullPipeline(tmpBasePath, nameRevStdinWriter, stderr, shasToNameReader); err != nil { | ||
_ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %v - %s", tmpBasePath, err, errbuf.String())) | ||
} | ||
} |
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,75 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package pipeline | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"strings" | ||
"sync" | ||
|
||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/log" | ||
) | ||
|
||
// RevListAllObjects runs rev-list --objects --all and writes to a pipewriter | ||
func RevListAllObjects(revListWriter *io.PipeWriter, wg *sync.WaitGroup, basePath string, errChan chan<- error) { | ||
defer wg.Done() | ||
defer revListWriter.Close() | ||
|
||
stderr := new(bytes.Buffer) | ||
var errbuf strings.Builder | ||
cmd := git.NewCommand("rev-list", "--objects", "--all") | ||
if err := cmd.RunInDirPipeline(basePath, revListWriter, stderr); err != nil { | ||
log.Error("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String()) | ||
err = fmt.Errorf("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String()) | ||
_ = revListWriter.CloseWithError(err) | ||
errChan <- err | ||
} | ||
} | ||
|
||
// RevListObjects run rev-list --objects from headSHA to baseSHA | ||
func RevListObjects(revListWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath, headSHA, baseSHA string, errChan chan<- error) { | ||
defer wg.Done() | ||
defer revListWriter.Close() | ||
stderr := new(bytes.Buffer) | ||
var errbuf strings.Builder | ||
cmd := git.NewCommand("rev-list", "--objects", headSHA, "--not", baseSHA) | ||
if err := cmd.RunInDirPipeline(tmpBasePath, revListWriter, stderr); err != nil { | ||
log.Error("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String()) | ||
errChan <- fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String()) | ||
} | ||
} | ||
|
||
// BlobsFromRevListObjects reads a RevListAllObjects and only selects blobs | ||
func BlobsFromRevListObjects(revListReader *io.PipeReader, shasToCheckWriter *io.PipeWriter, wg *sync.WaitGroup) { | ||
defer wg.Done() | ||
defer revListReader.Close() | ||
scanner := bufio.NewScanner(revListReader) | ||
defer func() { | ||
_ = shasToCheckWriter.CloseWithError(scanner.Err()) | ||
}() | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if len(line) == 0 { | ||
continue | ||
} | ||
fields := strings.Split(line, " ") | ||
if len(fields) < 2 || len(fields[1]) == 0 { | ||
continue | ||
} | ||
toWrite := []byte(fields[0] + "\n") | ||
for len(toWrite) > 0 { | ||
n, err := shasToCheckWriter.Write(toWrite) | ||
if err != nil { | ||
_ = revListReader.CloseWithError(err) | ||
break | ||
} | ||
toWrite = toWrite[n:] | ||
} | ||
} | ||
} |
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
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.