Skip to content

Update code.gitea.io/git #3482

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 1 commit into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions models/git_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"strconv"
"strings"

"code.gitea.io/git"
Expand Down Expand Up @@ -368,8 +369,15 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
a := line[beg+2 : middle]
b := line[middle+3:]
if hasQuote {
a = string(git.UnescapeChars([]byte(a[1 : len(a)-1])))
b = string(git.UnescapeChars([]byte(b[1 : len(b)-1])))
var err error
a, err = strconv.Unquote(a)
if err != nil {
return nil, fmt.Errorf("Unquote: %v", err)
}
b, err = strconv.Unquote(b)
if err != nil {
return nil, fmt.Errorf("Unquote: %v", err)
}
}

curFile = &DiffFile{
Expand Down
52 changes: 13 additions & 39 deletions models/repo_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,43 +231,17 @@ func addDelete(filename string, repo *Repository, batch rupture.FlushingBatch) e
}

// parseGitLsTreeOutput parses the output of a `git ls-tree -r --full-name` command
func parseGitLsTreeOutput(stdout string) ([]fileUpdate, error) {
lines := strings.Split(stdout, "\n")
updates := make([]fileUpdate, 0, len(lines))
for _, line := range lines {
// expect line to be "<mode> <object-type> <object-sha>\t<filename>"
line = strings.TrimSpace(line)
if len(line) == 0 {
continue
}
firstSpaceIndex := strings.IndexByte(line, ' ')
if firstSpaceIndex < 0 {
log.Error(4, "Misformatted git ls-tree output: %s", line)
continue
}
tabIndex := strings.IndexByte(line, '\t')
if tabIndex < 42+firstSpaceIndex || tabIndex == len(line)-1 {
log.Error(4, "Misformatted git ls-tree output: %s", line)
continue
}
if objectType := line[firstSpaceIndex+1 : tabIndex-41]; objectType != "blob" {
// submodules appear as commit objects, we do not index submodules
continue
}

blobSha := line[tabIndex-40 : tabIndex]
filename := line[tabIndex+1:]
if filename[0] == '"' {
var err error
filename, err = strconv.Unquote(filename)
if err != nil {
return nil, err
}
func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) {
entries, err := git.ParseTreeEntries(stdout)
if err != nil {
return nil, err
}
updates := make([]fileUpdate, len(entries))
for i, entry := range entries {
updates[i] = fileUpdate{
Filename: entry.Name(),
BlobSha: entry.ID.String(),
}
updates = append(updates, fileUpdate{
Filename: filename,
BlobSha: blobSha,
})
}
return updates, nil
}
Expand All @@ -276,7 +250,7 @@ func parseGitLsTreeOutput(stdout string) ([]fileUpdate, error) {
func genesisChanges(repo *Repository, revision string) (*repoChanges, error) {
var changes repoChanges
stdout, err := git.NewCommand("ls-tree", "--full-tree", "-r", revision).
RunInDir(repo.RepoPath())
RunInDirBytes(repo.RepoPath())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -327,11 +301,11 @@ func nonGenesisChanges(repo *Repository, revision string) (*repoChanges, error)

cmd := git.NewCommand("ls-tree", "--full-tree", revision, "--")
cmd.AddArguments(updatedFilenames...)
stdout, err = cmd.RunInDir(repo.RepoPath())
lsTreeStdout, err := cmd.RunInDirBytes(repo.RepoPath())
if err != nil {
return nil, err
}
changes.Updates, err = parseGitLsTreeOutput(stdout)
changes.Updates, err = parseGitLsTreeOutput(lsTreeStdout)
return &changes, err
}

Expand Down
81 changes: 81 additions & 0 deletions vendor/code.gitea.io/git/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 1 addition & 82 deletions vendor/code.gitea.io/git/tree.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"ignore": "test appengine",
"package": [
{
"checksumSHA1": "Gz+a5Qo4PCiB/Gf2f02v8HEAxDM=",
"checksumSHA1": "j6YyQxuOYRs94MVEamvnbE6ZtD0=",
"path": "code.gitea.io/git",
"revision": "6798d0f202cdc7187c00a467b586a4bdee27e8c9",
"revisionTime": "2018-01-14T14:37:32Z"
"revision": "827f97aaaa6a4ab5c31b1b799c56687a8cf6aade",
"revisionTime": "2018-02-10T03:05:43Z"
},
{
"checksumSHA1": "Qtq0kW+BnpYMOriaoCjMa86WGG8=",
Expand Down