// CoreBranchHashes returns a map containing all core branches with their hashes,
// i.e. map[branchName]commitHash.
776341
func CoreBranchHashes() (map[string]string, error) {
	coreBranches, err := coreBranchSet()
	if err != nil {
		return nil, err
	}

	// Get all heads known to git.
	//
	// The output consists of lines with the following format:
	//
	// <hash> <ref>
	//
	// e.g.
	//
	// 07f9c47a3005d3545991d4175cd9866c02dbdd85 refs/heads/master
	//
	output, err := Run("show-ref", "--heads")
	if err != nil {
		return nil, err
	}

	// Parse the output.
	var (
		task    = "Parse git show-ref output"
		hashes  = make(map[string]string, len(coreBranches))
		scanner = bufio.NewScanner(output)
	)
	for scanner.Scan() {
		line := scanner.Text()
		parts := strings.Split(line, " ")
		if len(parts) != 2 {
			return nil, errs.NewError(
				task, fmt.Errorf("failed to parse output line: %v", line))
		}
		hash, ref := parts[0], parts[1]
		// Drop the refs/heads/ prefix.
		branch := ref[len("refs/heads/"):]
		// In case this is a core branch, add it to the resulting map.
		if _, ok := coreBranches[branch]; ok {
			hashes[branch] = hash
		}
	}
	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return hashes, nil
}
878483
func (msg *MsgBlock) TxHashes() ([]chainhash.Hash, error) {
	hashList := make([]chainhash.Hash, 0, len(msg.Transactions))
	for _, tx := range msg.Transactions {
		hashList = append(hashList, tx.TxHash())
	}
	return hashList, nil
}
1229110
func getBranch(projects []che.WorkspaceProject, codebaseURL string) string {
	for _, p := range projects {
		if p.Source.Location == codebaseURL {
			return p.Source.Parameters.Branch
		}
	}
	return ""
}
444932
func (d *DotGit) ForEachObjectHash(fun func(plumbing.Hash) error) error {
	if !d.options.ExclusiveAccess {
		return d.forEachObjectHash(fun)
	}

	err := d.genObjectList()
	if err != nil {
		return err
	}

	for _, h := range d.objectList {
		err := fun(h)
		if err != nil {
			return err
		}
	}

	return nil
}
697650
func (h *hasher) hashChildren(original node, db *Database) (node, node, error) {
	var err error

	switch n := original.(type) {
	case *shortNode:
		// Hash the short node's child, caching the newly hashed subtree
		collapsed, cached := n.copy(), n.copy()
		collapsed.Key = hexToCompact(n.Key)
		cached.Key = common.CopyBytes(n.Key)

		if _, ok := n.Val.(valueNode); !ok {
			collapsed.Val, cached.Val, err = h.hash(n.Val, db, false)
			if err != nil {
				return original, original, err
			}
		}
		return collapsed, cached, nil

	case *fullNode:
		// Hash the full node's children, caching the newly hashed subtrees
		collapsed, cached := n.copy(), n.copy()

		for i := 0; i < 16; i++ {
			if n.Children[i] != nil {
				collapsed.Children[i], cached.Children[i], err = h.hash(n.Children[i], db, false)
				if err != nil {
					return original, original, err
				}
			}
		}
		cached.Children[16] = n.Children[16]
		return collapsed, cached, nil

	default:
		// Value and hash nodes don't have children so they're left as were
		return n, original, nil
	}
}
1167413
func (s *Section) KeysHash() map[string]string {
	if s.f.BlockMode {
		s.f.lock.RLock()
		defer s.f.lock.RUnlock()
	}

	hash := map[string]string{}
	for key, value := range s.keysHash {
		hash[key] = value
	}
	return hash
}
319300
func (c *cluster) shardNodes(index string, shard uint64) []*Node {
	return c.partitionNodes(c.partition(index, shard))
}
827542
func (s *MerkleStoreImpl) hash(in keybase1.MerkleStoreKit) keybase1.MerkleStoreKitHash {
	buf := sha512.Sum512([]byte(in))
	out := hex.EncodeToString(buf[:])
	return keybase1.MerkleStoreKitHash(out)
}
239316
func (commit *Commit) Hash() cmn.HexBytes {
	if commit == nil {
		return nil
	}
	if commit.hash == nil {
		bs := make([][]byte, len(commit.Precommits))
		for i, precommit := range commit.Precommits {
			bs[i] = cdcEncode(precommit)
		}
		commit.hash = merkle.SimpleHashFromByteSlices(bs)
	}
	return commit.hash
}
388704
func (c *Client) CommitBranch(branchName string) (int, error) {
	var result params.IntResult
	err := c.facade.FacadeCall("CommitBranch", argForBranch(branchName), &result)
	if err != nil {
		return 0, errors.Trace(err)
	}
	if result.Error != nil {
		return 0, errors.Trace(result.Error)
	}
	return result.Result, nil
}
793081
func iterateCommitTrees(
	seen map[plumbing.Hash]bool,
	tree *object.Tree,
	cb func(h plumbing.Hash),
) error {
	if seen[tree.Hash] {
		return nil
	}

	cb(tree.Hash)

	treeWalker := object.NewTreeWalker(tree, true, seen)

	for {
		_, e, err := treeWalker.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}

		if e.Mode == filemode.Submodule {
			continue
		}

		if seen[e.Hash] {
			continue
		}

		cb(e.Hash)
	}

	return nil
}
1340421
func (client Client) GetBranches(projectKey, repositorySlug string) (map[string]Branch, error) {
	start := 0
	branches := make(map[string]Branch)
	morePages := true
	for morePages {
		var data []byte
		retry := retry.New(3, retry.DefaultBackoffFunc)
		workit := func() error {
			req, err := http.NewRequest("GET", fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s/branches?start=%d&limit=%d", client.baseURL.String(), projectKey, repositorySlug, start, stashPageLimit), nil)
			if err != nil {
				return err
			}
			req.Header.Set("Accept", "application/json")
			req.SetBasicAuth(client.userName, client.password)

			var responseCode int
			responseCode, data, err = client.consumeResponse(req)
			if err != nil {
				return err
			}

			if responseCode != http.StatusOK {
				reason := "unhandled reason"
				switch {
				case responseCode == http.StatusNotFound:
					reason = "Not found"
				case responseCode == http.StatusUnauthorized:
					reason = "Unauthorized"
				}
				return errorResponse{StatusCode: responseCode, Reason: reason}
			}
			return nil
		}
		if err := retry.Try(workit); err != nil {
			return nil, err
		}

		var r Branches
		if err := json.Unmarshal(data, &r); err != nil {
			return nil, err
		}
		for _, branch := range r.Branch {
			branches[branch.DisplayID] = branch
		}
		morePages = !r.IsLastPage
		start = r.NextPageStart
	}
	return branches, nil
}
124482
func (t *ImmutableTree) Hash() []byte {
	if t.root == nil {
		return nil
	}
	hash, _ := t.root.hashWithCount()
	return hash
}
924710
func Compare(local, global HashSet) HashSet {
	missingLocal := make(map[string]bool)
	log.Info("comparing branches: local [", len(local), "] <-> global [", len(global), "]")
	for _, e := range global {
		missingLocal[e.String()] = true
	}
	for _, e := range local {
		if _, ok := missingLocal[e.String()]; ok {
			missingLocal[e.String()] = false
		}
	}
	missingFiles := make(HashSet, 0)
	for _, e := range global {
		if missingLocal[e.String()] {
			missingFiles = append(missingFiles, e)
		}
	}
	log.Notice("missing in local branch:", len(missingFiles))

	return missingFiles
}
468457
func (t *MultiTreeHasher) CreateHash() string {
	if len(t.nodes) == 0 {
		return ""
	}
	rootHash := treeHash(t.nodes)
	return hex.EncodeToString(rootHash[:])
}
658614
func TreeToFiles(r *git.Repository, t *object.Tree,
	repoURL string, repoCache *RepoCache) (map[fileKey]BlobLocation, map[string]plumbing.Hash, error) {
	rw := newRepoWalker(r, repoURL, repoCache)

	if err := rw.parseModuleMap(t); err != nil {
		return nil, nil, err
	}

	tw := object.NewTreeWalker(t, true, make(map[plumbing.Hash]bool))
	defer tw.Close()
	for {
		name, entry, err := tw.Next()
		if err == io.EOF {
			break
		}
		if err := rw.handleEntry(name, &entry); err != nil {
			return nil, nil, err
		}
	}
	return rw.tree, rw.subRepoVersions, nil
}
213623
func (p *PagesSource) GetBranch() string {
	if p == nil || p.Branch == nil {
		return ""
	}
	return *p.Branch
}