public function testPhutilArrayWithDefaultValue() { $a = new PhutilArrayWithDefaultValue(); $this->assertEqual(0, $a[99]); $a[99] = 1; $this->assertEqual(1, $a[99]); $a->setDefaultValue('default'); $this->assertEqual('default', $a['key']); $this->assertEqual(array(99 => 1, 'key' => 'default'), $a->toArray()); $init = array('apple' => 'red'); $b = new PhutilArrayWithDefaultValue($init); $this->assertEqual($init, $b->toArray()); $fruits = array('apple', 'cherry', 'banana', 'cherry', 'cherry', 'apple', 'banana', 'plum', 'cherry', 'cherry'); $counts = new PhutilArrayWithDefaultValue(); foreach ($fruits as $fruit) { $counts[$fruit] += 1; } $this->assertEqual(array('apple' => 2, 'cherry' => 5, 'banana' => 2, 'plum' => 1), $counts->toArray()); $masks = array(1, 2, 4); $bitmask = new PhutilArrayWithDefaultValue(); foreach ($masks as $mask) { $bitmask['value'] |= $mask; } $this->assertEqual(7, $bitmask['value']); }
protected function buildUncommittedStatus() { $diff_options = $this->getDiffBaseOptions(); if ($this->repositoryHasNoCommits) { $diff_base = self::GIT_MAGIC_ROOT_COMMIT; } else { $diff_base = 'HEAD'; } // Find uncommitted changes. $uncommitted_future = $this->buildLocalFuture(array('diff %C --raw %s --', $diff_options, $diff_base)); $untracked_future = $this->buildLocalFuture(array('ls-files --others --exclude-standard')); // Unstaged changes $unstaged_future = $this->buildLocalFuture(array('diff-files --name-only')); $futures = array($uncommitted_future, $untracked_future); Futures($futures)->resolveAll(); // We're clear to start the `git diff-files` now. $unstaged_future->start(); $result = new PhutilArrayWithDefaultValue(); list($stdout) = $uncommitted_future->resolvex(); $uncommitted_files = $this->parseGitStatus($stdout); foreach ($uncommitted_files as $path => $mask) { $result[$path] |= $mask | self::FLAG_UNCOMMITTED; } list($stdout) = $untracked_future->resolvex(); $stdout = rtrim($stdout, "\n"); if (strlen($stdout)) { $stdout = explode("\n", $stdout); foreach ($stdout as $path) { $result[$path] |= self::FLAG_UNTRACKED; } } list($stdout, $stderr) = $unstaged_future->resolvex(); $stdout = rtrim($stdout, "\n"); if (strlen($stdout)) { $stdout = explode("\n", $stdout); foreach ($stdout as $path) { $result[$path] |= self::FLAG_UNSTAGED; } } return $result->toArray(); }
protected function buildUncommittedStatus() { list($stdout) = $this->execxLocal('status'); $results = new PhutilArrayWithDefaultValue(); $working_status = ArcanistMercurialParser::parseMercurialStatus($stdout); foreach ($working_status as $path => $mask) { if (!($mask & ArcanistRepositoryAPI::FLAG_UNTRACKED)) { // Mark tracked files as uncommitted. $mask |= self::FLAG_UNCOMMITTED; } $results[$path] |= $mask; } return $results->toArray(); }