Changeset View
Changeset View
Standalone View
Standalone View
src/repository/api/ArcanistGitAPI.php
Context not available. | |||||
} | } | ||||
// NOTE: Windows escaping of "%" symbols apparently is inherently broken; | // NOTE: Windows escaping of "%" symbols apparently is inherently broken; | ||||
// when passed through escapeshellarg() they are replaced with spaces. | // when passed through @escapeshellarg() they are replaced with spaces. | ||||
// TODO: Learn how cmd.exe works and find some clever workaround? | // TODO: Learn how cmd.exe works and find some clever workaround? | ||||
Context not available. | |||||
$commits = array(); | $commits = array(); | ||||
$info = trim($info, " \n\2"); | $info = trim($info, " \n\2"); | ||||
if (!strlen($info)) { | if (!@strlen($info)) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$info = explode("\2", $info); | $info = @explode("\2", $info); | ||||
foreach ($info as $line) { | foreach ($info as $line) { | ||||
list($commit, $tree, $parents, $time, $author, $author_email, | list($commit, $tree, $parents, $time, $author, $author_email, | ||||
$title, $message) = explode("\1", trim($line), 8); | $title, $message) = @explode("\1", trim($line), 8); | ||||
$message = rtrim($message); | $message = rtrim($message); | ||||
$commits[$commit] = array( | $commits[$commit] = array( | ||||
'commit' => $commit, | 'commit' => $commit, | ||||
'tree' => $tree, | 'tree' => $tree, | ||||
'parents' => array_filter(explode(' ', $parents)), | 'parents' => array_filter(@explode(' ', $parents)), | ||||
'time' => $time, | 'time' => $time, | ||||
'author' => $author, | 'author' => $author, | ||||
'summary' => $title, | 'summary' => $title, | ||||
Context not available. | |||||
$prompt = pht('What default do you want to use? [origin/master]'); | $prompt = pht('What default do you want to use? [origin/master]'); | ||||
$default = phutil_console_prompt($prompt); | $default = phutil_console_prompt($prompt); | ||||
if (!strlen(trim($default))) { | if (!@strlen(trim($default))) { | ||||
$default = 'origin/master'; | $default = 'origin/master'; | ||||
} | } | ||||
Context not available. | |||||
return null; | return null; | ||||
} | } | ||||
if (!strlen($branch)) { | if (!@strlen($branch)) { | ||||
return null; | return null; | ||||
} | } | ||||
Context not available. | |||||
public function getCanonicalRevisionName($string) { | public function getCanonicalRevisionName($string) { | ||||
$match = null; | $match = null; | ||||
if (preg_match('/@([0-9]+)$/', $string, $match)) { | if (@preg_match('/@([0-9]+)$/', $string, $match)) { | ||||
$stdout = $this->getHashFromFromSVNRevisionNumber($match[1]); | $stdout = $this->getHashFromFromSVNRevisionNumber($match[1]); | ||||
} else { | } else { | ||||
list($stdout) = $this->execxLocal( | list($stdout) = $this->execxLocal( | ||||
Context not available. | |||||
} | } | ||||
// When git performs a partial-rebuild during svn | // When git performs a partial-rebuild during svn | ||||
// look-up, we need to parse the final line | // look-up, we need to parse the final line | ||||
$lines = explode("\n", $stdout); | $lines = @explode("\n", $stdout); | ||||
$stdout = $lines[count($lines) - 2]; | $stdout = $lines[count($lines) - 2]; | ||||
return rtrim($stdout); | return rtrim($stdout); | ||||
} | } | ||||
Context not available. | |||||
list($stdout) = $status->resolvex(); | list($stdout) = $status->resolvex(); | ||||
$result = new PhutilArrayWithDefaultValue(); | $result = new PhutilArrayWithDefaultValue(); | ||||
$parts = explode("\0", $stdout); | $parts = @explode("\0", $stdout); | ||||
while (count($parts) > 1) { | while (count($parts) > 1) { | ||||
$entry = array_shift($parts); | $entry = array_shift($parts); | ||||
$entry_parts = explode(' ', $entry, 2); | $entry_parts = @explode(' ', $entry, 2); | ||||
if ($entry_parts[0] == '1') { | if ($entry_parts[0] == '1') { | ||||
$entry_parts = explode(' ', $entry, 9); | $entry_parts = @explode(' ', $entry, 9); | ||||
$path = $entry_parts[8]; | $path = $entry_parts[8]; | ||||
} else if ($entry_parts[0] == '2') { | } else if ($entry_parts[0] == '2') { | ||||
$entry_parts = explode(' ', $entry, 10); | $entry_parts = @explode(' ', $entry, 10); | ||||
$path = $entry_parts[9]; | $path = $entry_parts[9]; | ||||
} else if ($entry_parts[0] == 'u') { | } else if ($entry_parts[0] == 'u') { | ||||
$entry_parts = explode(' ', $entry, 11); | $entry_parts = @explode(' ', $entry, 11); | ||||
$path = $entry_parts[10]; | $path = $entry_parts[10]; | ||||
} else if ($entry_parts[0] == '?') { | } else if ($entry_parts[0] == '?') { | ||||
$entry_parts = explode(' ', $entry, 2); | $entry_parts = @explode(' ', $entry, 2); | ||||
$result[$entry_parts[1]] = self::FLAG_UNTRACKED; | $result[$entry_parts[1]] = self::FLAG_UNTRACKED; | ||||
continue; | continue; | ||||
} | } | ||||
$result[$path] |= self::FLAG_UNCOMMITTED; | $result[$path] |= self::FLAG_UNCOMMITTED; | ||||
$index_state = substr($entry_parts[1], 0, 1); | $index_state = @substr($entry_parts[1], 0, 1); | ||||
$working_state = substr($entry_parts[1], 1, 1); | $working_state = @substr($entry_parts[1], 1, 1); | ||||
if ($index_state == 'A') { | if ($index_state == 'A') { | ||||
$result[$path] |= self::FLAG_ADDED; | $result[$path] |= self::FLAG_ADDED; | ||||
} else if ($index_state == 'M') { | } else if ($index_state == 'M') { | ||||
Context not available. | |||||
} | } | ||||
} | } | ||||
} | } | ||||
$submodule_tracked = substr($entry_parts[2], 2, 1); | $submodule_tracked = @substr($entry_parts[2], 2, 1); | ||||
$submodule_untracked = substr($entry_parts[2], 3, 1); | $submodule_untracked = @substr($entry_parts[2], 3, 1); | ||||
if ($submodule_tracked == 'M' || $submodule_untracked == 'U') { | if ($submodule_tracked == 'M' || $submodule_untracked == 'U') { | ||||
$result[$path] |= self::FLAG_EXTERNALS; | $result[$path] |= self::FLAG_EXTERNALS; | ||||
} | } | ||||
Context not available. | |||||
list($stdout) = $untracked_future->resolvex(); | list($stdout) = $untracked_future->resolvex(); | ||||
$stdout = rtrim($stdout, "\n"); | $stdout = rtrim($stdout, "\n"); | ||||
if (strlen($stdout)) { | if (@strlen($stdout)) { | ||||
$stdout = explode("\n", $stdout); | $stdout = @explode("\n", $stdout); | ||||
foreach ($stdout as $path) { | foreach ($stdout as $path) { | ||||
$result[$path] |= self::FLAG_UNTRACKED; | $result[$path] |= self::FLAG_UNTRACKED; | ||||
} | } | ||||
Context not available. | |||||
list($stdout, $stderr) = $unstaged_future->resolvex(); | list($stdout, $stderr) = $unstaged_future->resolvex(); | ||||
$stdout = rtrim($stdout, "\n"); | $stdout = rtrim($stdout, "\n"); | ||||
if (strlen($stdout)) { | if (@strlen($stdout)) { | ||||
$stdout = explode("\n", $stdout); | $stdout = @explode("\n", $stdout); | ||||
foreach ($stdout as $path) { | foreach ($stdout as $path) { | ||||
$result[$path] |= self::FLAG_UNSTAGED; | $result[$path] |= self::FLAG_UNSTAGED; | ||||
} | } | ||||
Context not available. | |||||
$status = trim($status); | $status = trim($status); | ||||
$lines = array(); | $lines = array(); | ||||
foreach (explode("\n", $status) as $line) { | foreach (@explode("\n", $status) as $line) { | ||||
if ($line) { | if ($line) { | ||||
$lines[] = preg_split("/[ \t]/", $line, 6); | $lines[] = preg_split("/[ \t]/", $line, 6); | ||||
} | } | ||||
Context not available. | |||||
} else if (isset($flags[$flag])) { | } else if (isset($flags[$flag])) { | ||||
$mask |= $flags[$flag]; | $mask |= $flags[$flag]; | ||||
} else if ($flag[0] == 'R') { | } else if ($flag[0] == 'R') { | ||||
$both = explode("\t", $file); | $both = @explode("\t", $file); | ||||
if ($full) { | if ($full) { | ||||
$files[$both[0]] = array( | $files[$both[0]] = array( | ||||
'mask' => $mask | self::FLAG_DELETED, | 'mask' => $mask | self::FLAG_DELETED, | ||||
Context not available. | |||||
$file = $both[1]; | $file = $both[1]; | ||||
$mask |= self::FLAG_ADDED; | $mask |= self::FLAG_ADDED; | ||||
} else if ($flag[0] == 'C') { | } else if ($flag[0] == 'C') { | ||||
$both = explode("\t", $file); | $both = @explode("\t", $file); | ||||
$file = $both[1]; | $file = $both[1]; | ||||
$mask |= self::FLAG_ADDED; | $mask |= self::FLAG_ADDED; | ||||
} | } | ||||
Context not available. | |||||
$blame = array(); | $blame = array(); | ||||
foreach ($blame_info as $line_info) { | foreach ($blame_info as $line_info) { | ||||
$revision = substr($line_info, 0, 40); | $revision = @substr($line_info, 0, 40); | ||||
$data = idx($revision_data, $revision, array()); | $data = idx($revision_data, $revision, array()); | ||||
if (empty($data)) { | if (empty($data)) { | ||||
$matches = array(); | $matches = array(); | ||||
if (!preg_match('/^author (.*)$/m', $line_info, $matches)) { | if (!@preg_match('/^author (.*)$/m', $line_info, $matches)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unexpected output from %s: no author for commit %s', | 'Unexpected output from %s: no author for commit %s', | ||||
Context not available. | |||||
$revision)); | $revision)); | ||||
} | } | ||||
$data['author'] = $matches[1]; | $data['author'] = $matches[1]; | ||||
$data['from_first_commit'] = preg_match('/^boundary$/m', $line_info); | $data['from_first_commit'] = @preg_match('/^boundary$/m', $line_info); | ||||
$revision_data[$revision] = $data; | $revision_data[$revision] = $data; | ||||
} | } | ||||
Context not available. | |||||
$result = array(); | $result = array(); | ||||
$stdout = trim($stdout); | $stdout = trim($stdout); | ||||
if (!strlen($stdout)) { | if (!@strlen($stdout)) { | ||||
return $result; | return $result; | ||||
} | } | ||||
$lines = explode("\n", $stdout); | $lines = @explode("\n", $stdout); | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
$matches = array(); | $matches = array(); | ||||
$ok = preg_match( | $ok = @preg_match( | ||||
'/^(\d{6}) (blob|tree|commit) ([a-z0-9]{40})[\t](.*)$/', | '/^(\d{6}) (blob|tree|commit) ([a-z0-9]{40})[\t](.*)$/', | ||||
$line, | $line, | ||||
$matches); | $matches); | ||||
Context not available. | |||||
// and treat it as though it as a file containing a list of other files, | // and treat it as though it as a file containing a list of other files, | ||||
// which is silly. | // which is silly. | ||||
if (!strlen($path)) { | if (!@strlen($path)) { | ||||
// No filename, so there's no content (Probably new/deleted file). | // No filename, so there's no content (Probably new/deleted file). | ||||
return null; | return null; | ||||
} | } | ||||
Context not available. | |||||
$current = $this->getBranchName(); | $current = $this->getBranchName(); | ||||
$result = array(); | $result = array(); | ||||
$lines = explode("\2", $stdout); | $lines = @explode("\2", $stdout); | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
$line = trim($line); | $line = trim($line); | ||||
if (!strlen($line)) { | if (!@strlen($line)) { | ||||
continue; | continue; | ||||
} | } | ||||
$fields = explode("\1", $line, 6); | $fields = @explode("\1", $line, 6); | ||||
list($ref, $hash, $epoch, $tree, $desc, $text) = $fields; | list($ref, $hash, $epoch, $tree, $desc, $text) = $fields; | ||||
$branch = $this->getBranchNameFromRef($ref); | $branch = $this->getBranchNameFromRef($ref); | ||||
Context not available. | |||||
public function getAllLocalChanges() { | public function getAllLocalChanges() { | ||||
$diff = $this->getFullGitDiff($this->getBaseCommit()); | $diff = $this->getFullGitDiff($this->getBaseCommit()); | ||||
if (!strlen(trim($diff))) { | if (!@strlen(trim($diff))) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$parser = new ArcanistDiffParser(); | $parser = new ArcanistDiffParser(); | ||||
Context not available. | |||||
array $query) { | array $query) { | ||||
$messages = $this->getGitCommitLog(); | $messages = $this->getGitCommitLog(); | ||||
if (!strlen($messages)) { | if (!@strlen($messages)) { | ||||
return array(); | return array(); | ||||
} | } | ||||
Context not available. | |||||
)); | )); | ||||
foreach ($results as $key => $result) { | foreach ($results as $key => $result) { | ||||
$hash = substr($reason_map[$result['id']], 0, 16); | $hash = @substr($reason_map[$result['id']], 0, 16); | ||||
$results[$key]['why'] = pht( | $results[$key]['why'] = pht( | ||||
"Commit message for '%s' has explicit 'Differential Revision'.", | "Commit message for '%s' has explicit 'Differential Revision'.", | ||||
$hash); | $hash); | ||||
Context not available. | |||||
} | } | ||||
public function resolveBaseCommitRule($rule, $source) { | public function resolveBaseCommitRule($rule, $source) { | ||||
list($type, $name) = explode(':', $rule, 2); | list($type, $name) = @explode(':', $rule, 2); | ||||
switch ($type) { | switch ($type) { | ||||
case 'git': | case 'git': | ||||
$matches = null; | $matches = null; | ||||
if (preg_match('/^merge-base\((.+)\)$/', $name, $matches)) { | if (@preg_match('/^merge-base\((.+)\)$/', $name, $matches)) { | ||||
list($err, $merge_base) = $this->execManualLocal( | list($err, $merge_base) = $this->execManualLocal( | ||||
'merge-base -- %s HEAD', | 'merge-base -- %s HEAD', | ||||
$matches[1]); | $matches[1]); | ||||
Context not available. | |||||
$source)); | $source)); | ||||
return trim($merge_base); | return trim($merge_base); | ||||
} | } | ||||
} else if (preg_match('/^branch-unique\((.+)\)$/', $name, $matches)) { | } else if (@preg_match('/^branch-unique\((.+)\)$/', $name, $matches)) { | ||||
list($err, $merge_base) = $this->execManualLocal( | list($err, $merge_base) = $this->execManualLocal( | ||||
'merge-base -- %s HEAD', | 'merge-base -- %s HEAD', | ||||
$matches[1]); | $matches[1]); | ||||
Context not available. | |||||
'log --format=%C %s..HEAD --', | 'log --format=%C %s..HEAD --', | ||||
'%H', | '%H', | ||||
$merge_base); | $merge_base); | ||||
$commits = array_filter(explode("\n", $commits)); | $commits = array_filter(@explode("\n", $commits)); | ||||
if (!$commits) { | if (!$commits) { | ||||
return null; | return null; | ||||
Context not available. | |||||
'branch %Ls --contains %s', | 'branch %Ls --contains %s', | ||||
$flags, | $flags, | ||||
$commit); | $commit); | ||||
$branches = array_filter(explode("\n", $branches)); | $branches = array_filter(@explode("\n", $branches)); | ||||
// Filter the list, removing the "current" marker (*) and ignoring | // Filter the list, removing the "current" marker (*) and ignoring | ||||
// anything other than known branch names (mainly, any possible | // anything other than known branch names (mainly, any possible | ||||
Context not available. | |||||
$upstream = trim($upstream); | $upstream = trim($upstream); | ||||
if (preg_match('(^refs/heads/)', $upstream)) { | if (@preg_match('(^refs/heads/)', $upstream)) { | ||||
$upstream = preg_replace('(^refs/heads/)', '', $upstream); | $upstream = preg_replace('(^refs/heads/)', '', $upstream); | ||||
$is_cycle = $path->getUpstream($upstream); | $is_cycle = $path->getUpstream($upstream); | ||||
Context not available. | |||||
continue; | continue; | ||||
} | } | ||||
if (preg_match('(^refs/remotes/)', $upstream)) { | if (@preg_match('(^refs/remotes/)', $upstream)) { | ||||
$upstream = preg_replace('(^refs/remotes/)', '', $upstream); | $upstream = preg_replace('(^refs/remotes/)', '', $upstream); | ||||
list($remote, $branch) = explode('/', $upstream, 2); | list($remote, $branch) = @explode('/', $upstream, 2); | ||||
$path->addUpstream( | $path->addUpstream( | ||||
$cursor, | $cursor, | ||||
Context not available. | |||||
if ($remote_uri !== null) { | if ($remote_uri !== null) { | ||||
$remote_uri = rtrim($remote_uri); | $remote_uri = rtrim($remote_uri); | ||||
if (!strlen($remote_uri)) { | if (!@strlen($remote_uri)) { | ||||
$remote_uri = null; | $remote_uri = null; | ||||
} | } | ||||
} | } | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0