MCPcopy Index your code
hub / github.com/google/git-appraise / StoreTree

Method StoreTree

repository/git.go:551–575  ·  view source on GitHub ↗

StoreTree writes the given file tree to the repository and returns its hash.

(contents map[string]TreeChild)

Source from the content-addressed store, hash-verified

549
550// StoreTree writes the given file tree to the repository and returns its hash.
551func (repo *GitRepo) StoreTree(contents map[string]TreeChild) (string, error) {
552 var lines []string
553 for path, obj := range contents {
554 objHash, err := obj.Store(repo)
555 if err != nil {
556 return "", err
557 }
558 mode := "040000"
559 if obj.Type() == "blob" {
560 mode = "100644"
561 }
562 line := fmt.Sprintf("%s %s %s\t%s", mode, obj.Type(), objHash, path)
563 lines = append(lines, line)
564 }
565 stdin := strings.NewReader(strings.Join(lines, "\n"))
566 var stdout bytes.Buffer
567 var stderr bytes.Buffer
568 args := []string{"mktree"}
569 err := repo.runGitCommandWithIO(stdin, &stdout, &stderr, args...)
570 if err != nil {
571 message := strings.TrimSpace(stderr.String())
572 return "", fmt.Errorf("failure storing a git tree, %v: %q", err, message)
573 }
574 return strings.TrimSpace(stdout.String()), nil
575}
576
577func (repo *GitRepo) readBlob(objHash string) (*Blob, error) {
578 out, err := repo.runGitCommand("cat-file", "-p", objHash)

Callers 1

CreateCommitWithTreeMethod · 0.95

Calls 4

runGitCommandWithIOMethod · 0.95
StringMethod · 0.80
StoreMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected