Extract the tree hash for a given branch or tree reference.

@param  string $branch

@return string
506804
public function getBranchTree($branch)
    {
        $hash = $this->getClient()->run($this, "log --pretty=\"%T\" --max-count=1 $branch");
        $hash = trim($hash, "\r\n ");

        return $hash ?: false;
    }
110836
def to_hash(node)
      node_type = get_node_type node

      case node_type
      when :blank
        {}
      when :branch
        hash = {}

        16.times do |i|
          sub_hash = to_hash decode_to_node(node[i])
          sub_hash.each {|k, v| hash[NibbleKey.new([i]) + k] = v }
        end

        hash[NibbleKey.terminator] = node.last if node.last.true?
        hash
      when *NODE_KV_TYPE
        nibbles = NibbleKey.decode(node[0]).terminate(false)

        sub_hash = node_type == :extension ?
          to_hash(decode_to_node(node[1])) : {NibbleKey.terminator => node[1]}

        {}.tap do |hash|
          sub_hash.each {|k, v| hash[nibbles + k] = v }
        end
      else
        # do nothing
      end
    end
945166
protected function processBranch(DOMNode $branch)
	{
		$list = $this->childrenAsArray($branch->childNodes);

		for ($i = 0; $i < count($list); $i++)
		{
			$node = $list[$i];
			if ($node->namespaceURI == self::NS)
			{
				$node = $this->processExtendedNode($node);
			}

			if ($node && in_array($node->nodeName, $this->inputs))
			{
				$node = $this->processInput($node);
			}

			if ($node)
			{
				$this->processBranch($node);
			}
			//$this->processExtendedAttributes($node);
		}

	}
422529
protected function optimizeBranchesHead(array &$branches)
	{
		// Capture common output
		$before = $this->optimizeBranchesOutput($branches, 'head');

		// Move the branch output to the tail for branches that have no body
		foreach ($branches as &$branch)
		{
			if ($branch['body'] !== '' || !empty($branch['tail']))
			{
				continue;
			}

			$branch['tail'] = array_reverse($branch['head']);
			$branch['head'] = [];
		}
		unset($branch);

		return $before;
	}
1114260
protected function calculateRoot(): string
    {
        $size = \count($this->nodes);
        if ($size < 1) {
            return '';
        }
        $order = self::getSizeRoundedUp($size);
        /** @var array<int, string> $hash */
        $hash = [];
        // Population (Use self::MERKLE_LEAF as a prefix)
        for ($i = 0; $i < $order; ++$i) {
            if ($i >= $size) {
                $hash[$i] = self::MERKLE_LEAF .
                    $this->personalization .
                    $this->nodes[$size - 1]->getHash(
                        true,
                        $this->outputSize,
                        $this->personalization
                    );
            } else {
                $hash[$i] = self::MERKLE_LEAF .
                    $this->personalization .
                    $this->nodes[$i]->getHash(
                        true,
                        $this->outputSize,
                        $this->personalization
                    );
            }
        }

        // Calculation (Use self::MERKLE_BRANCH as a prefix)
        do {
            /** @var array<int, string> $tmp */
            $tmp = [];
            $j = 0;
            for ($i = 0; $i < $order; $i += 2) {
                /** @var string $prev */
                $curr = (string) ($hash[$i] ?? '');
                if (empty($hash[$i + 1])) {
                    // @codeCoverageIgnoreStart
                    $tmp[$j] = Util::raw_hash(
                        self::MERKLE_BRANCH .
                            $this->personalization .
                            $curr .
                            $curr,
                        $this->outputSize
                    );
                    // @codeCoverageIgnoreEnd
                } else {
                    /** @var string $curr */
                    $curr = (string) ($hash[$i] ?? '');
                    /** @var string $next */
                    $next = (string) ($hash[$i + 1] ?? '');
                    $tmp[$j] = Util::raw_hash(
                        self::MERKLE_BRANCH .
                            $this->personalization .
                            $curr . $next,
                        $this->outputSize
                    );
                }
                ++$j;
            }
            $hash = $tmp;
            $order >>= 1;
        } while ($order > 1);
        // We should only have one value left:t
        $this->rootCalculated = true;
        /** @var string $first */
        $first = \array_shift($hash);
        return $first;
    }
63605
protected function collectJohns( $branches, $prefix, array $johns=array(), array &$paths=array() ) {
		$paths[$prefix] = $johns;
		foreach( $branches as $k=>$johnTreeNode ) {
			$johns2 = $johns;
			$johns2[] = $johnTreeNode->getJohn();
			$this->collectJohns( $johnTreeNode->getBranches(), $prefix.'.'.$k, $johns2, $paths );
		}
		return $paths;
	}
485749
protected function collectBranch() : string
    {
        $branchesResult = $this->executor->execute('git branch');

        foreach ($branchesResult as $result) {
            if (strpos($result, '* ') === 0) {
                $exploded = explode('* ', $result, 2);

                return $exploded[1];
            }
        }

        throw new \RuntimeException();
    }
1210518
public function getNodeName($tree)
    {
        if ($models = ArrayHelper::getValue($this->treeWidgetOptions, 'models')) {
            $model = $models[0];
            $rootLevel = $model->level;

            /**
             * @var \skeeks\cms\models\CmsTree $tree
             */
            $name = $tree->name;
            if ($tree->parents) {
                $parents = $tree->getParents()->andWhere(['>=', 'level', $rootLevel])->all();
                if ($parents) {
                    $name = implode(" / ", \yii\helpers\ArrayHelper::map($parents, 'id', 'name'));
                    $name .= " / " . $tree->name;
                }
            }

            return $name;
        } else {
            $rootLevel = 0;

            /**
             * @var \skeeks\cms\models\CmsTree $tree
             */
            $name = $tree->name;
            if ($tree->parents) {
                $parents = $tree->getParents()->andWhere(['>=', 'level', $rootLevel])->all();
                if ($parents) {
                    $name = implode(" / ", \yii\helpers\ArrayHelper::map($parents, 'id', 'name'));
                    $name .= " / " . $tree->name;
                }
            }

            return $name;
        }

        return $tree->name;
    }
360905
public function extract($hash) {
		if ($this->commandDisabled('extract')) {
			return $this->setError(elFinder::ERROR_PERM_DENIED);
		}
		
		if (($file = $this->file($hash)) == false) {
			return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
		}
		
		$archiver = isset($this->archivers['extract'][$file['mime']])
			? $this->archivers['extract'][$file['mime']]
			: false;
			
		if (!$archiver) {
			return $this->setError(elFinder::ERROR_NOT_ARCHIVE);
		}
		
		$path   = $this->decode($hash);
		$parent = $this->stat($this->_dirname($path));

		if (!$file['read'] || !$parent['write']) {
			return $this->setError(elFinder::ERROR_PERM_DENIED);
		}
		$this->clearcache();
		return ($path = $this->_extract($path, $archiver)) ? $this->stat($path) : false;
	}
420527
public function stashBranch(string $branch, string $stash)
    {
        $stashCommand = StashCommand::getInstance($this);
        $command = $stashCommand->branch($branch, $stash);
        $this->caller->execute($command);
    }
602228
public function gitBranch($branch)
    {
        $options = ['options' => ['regexp' => '/^[a-zA-Z0-9\/\+\._-]+$/']];
        if (filter_var($branch, FILTER_VALIDATE_REGEXP, $options) === false) {
            throw new \InvalidArgumentException(sprintf("Invalid characters found in git branch name '%s'. Use only letters, numbers, underscore, hyphen and forward slashes.", $branch));
        }

        return $branch;
    }
578395
public function getLastChild(Branch $branch = null)
    {
        if (null === $branch) {
            return null;
        }

        //end return last child or false if is not found
        $children = $branch->getChildren();
        $last = end($children);

        return $last ? $last : null;
    }
784508
def commit_hash(self):
        
        commit_hash = None
        branch = None
        branch_file = '.git/HEAD'  # ref: refs/heads/develop

        # get current branch
        if os.path.isfile(branch_file):
            with open(branch_file, 'r') as f:
                try:
                    branch = f.read().strip().split('/')[2]
                except IndexError:
                    pass

            # get commit hash
            if branch:
                hash_file = '.git/refs/heads/{}'.format(branch)
                if os.path.isfile(hash_file):
                    with open(hash_file, 'r') as f:
                        commit_hash = f.read().strip()
        return commit_hash
547940
protected function validateBranch($branch)
    {
        try {
            if (!strpos($branch, '/')) {
                return false;
            }
            return $this->versionParser->normalizeBranch(
                $this->_getBranchWithoutNamespace($branch)
            );
        } catch (\Exception $e) {
            return false;
        }
    }
1113044
private function branch($owner = 0, $level = 0)
    {
        $result = '';

        $flags = SECTIONS_ACTIVE;
        if (!$this->settings['showHidden'])
        {
            $flags += SECTIONS_VISIBLE;
        }

        $access = $this->settings['showPriveleged'] ? ROOT :
            Eresus_CMS::getLegacyKernel()->user['access'];

        $items = Eresus_CMS::getLegacyKernel()->sections->children($owner, $access, $flags);

        if (count($items))
        {
            foreach ($items as $item)
            {
                $item = Eresus_CMS::getLegacyKernel()->sections->get($item['id']);
                if ($item['type'] == 'url')
                {
                    $item['url'] = $item['content'];
                }
                else
                {
                    $item['url'] = Eresus_Kernel::app()->getPage()->clientURL($item['id']);
                }
                $item['level'] = $level + 1;
                $item['subitems'] = $this->branch($item['id'], $level + 1);
                $result .= $this->replaceMacros($this->settings['tmplItem'], $item);
            }
            $result = array('level' => ($level + 1), 'items' => $result);
            $result = $this->replaceMacros($this->settings['tmplList'], $result);
        }
        return $result;
    }
1014635
function getBranchLinkDomains(branchXml, key) {
    const output = [];
    if (branchXml.hasOwnProperty(key)) {
      for (let i = 0; i < branchXml[key].length; i++) {
        const item = branchXml[key][i];
        output.push(item.$.value);
      }
    }
    return output;
  }
1205423
public function getBranch(string $name)
    {
        /** @var Branch $branch */
        foreach ($this->getBranches() as $branch) {
            if ($branch->getName() === $name) {
                return $branch;
            }
        }

        return null;
    }