Skip to content

Commit c04fcdb

Browse files
authored
Merge pull request #27 from totten/master-max-depth
Define option `--max-depth` to limit search depth
2 parents cde7b7f + cdb1bd5 commit c04fcdb

16 files changed

+181
-19
lines changed

nix/buildkit-update.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
{ # https://stackoverflow.com/a/21100710
3+
4+
## Re-generate the buildkit.nix file - with the current 'master' branch.
5+
6+
set -e
7+
8+
if [ ! -f "nix/buildkit.nix" ]; then
9+
echo >&2 "Must run in project root"
10+
exit 1
11+
fi
12+
13+
now=$( date -u '+%Y-%m-%d %H:%M %Z' )
14+
commit=$( git ls-remote https://github.com/civicrm/civicrm-buildkit.git | awk '/refs\/heads\/master$/ { print $1 }' )
15+
url="https://github.com/civicrm/civicrm-buildkit/archive/${commit}.tar.gz"
16+
hash=$( nix-prefetch-url "$url" --type sha256 --unpack )
17+
18+
function render_file() {
19+
echo "{ pkgs ? import <nixpkgs> {} }:"
20+
echo ""
21+
echo "## Get civicrm-buildkit from github."
22+
echo "## Based on \"master\" branch circa $now"
23+
echo "import (pkgs.fetchzip {"
24+
echo " url = \"$url\";"
25+
echo " sha256 = \"$hash\";"
26+
echo "})"
27+
echo
28+
echo "## Get a local copy of civicrm-buildkit. (Useful for developing patches.)"
29+
echo "# import ((builtins.getEnv \"HOME\") + \"/buildkit/default.nix\")"
30+
echo "# import ((builtins.getEnv \"HOME\") + \"/bknix/default.nix\")"
31+
}
32+
render_file > nix/buildkit.nix
33+
34+
exit
35+
}

nix/buildkit.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
## Get civicrm-buildkit from github.
4+
## Based on "master" branch circa 2024-02-26 04:30 UTC
5+
import (pkgs.fetchzip {
6+
url = "https://github.com/civicrm/civicrm-buildkit/archive/d6f6b8dd2d5944c35cd78cb319fef21673214b35.tar.gz";
7+
sha256 = "02p2yzdfgv66a2zf8i36h6pjfi78wnp92m3klij7fqbfd9mpvi5a";
8+
})
9+
10+
## Get a local copy of civicrm-buildkit. (Useful for developing patches.)
11+
# import ((builtins.getEnv "HOME") + "/buildkit/default.nix")
12+
# import ((builtins.getEnv "HOME") + "/bknix/default.nix")

shell.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* This shell is suitable for compiling PHAR executables.... and not much else.
3+
*
4+
* Ex: `nix-shell --run ./scripts/build.sh`
5+
*/
6+
7+
{ pkgs ? import <nixpkgs> {} }:
8+
9+
let
10+
11+
buildkit = (import ./nix/buildkit.nix) { inherit pkgs; };
12+
13+
in
14+
15+
pkgs.mkShell {
16+
nativeBuildInputs = buildkit.profiles.base ++ [
17+
18+
(buildkit.pins.v2305.php82.buildEnv {
19+
extraConfig = ''
20+
memory_limit=-1
21+
'';
22+
})
23+
24+
buildkit.pkgs.box
25+
buildkit.pkgs.composer
26+
buildkit.pkgs.phpunit9
27+
28+
pkgs.bash-completion
29+
];
30+
shellHook = ''
31+
source ${pkgs.bash-completion}/etc/profile.d/bash_completion.sh
32+
'';
33+
}

src/GitScan/Command/AutoMergeCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected function configure() {
5858
->addOption('keep', 'K', InputOption::VALUE_NONE, 'When applying patches, keep the current branch. Preserve local changes.')
5959
->addOption('new', 'N', InputOption::VALUE_NONE, 'When applying patches, create a new merge branch.')
6060
->addOption('path', NULL, InputOption::VALUE_REQUIRED, 'The local base path to search', getcwd())
61+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
6162
->addOption('url-split', NULL, InputOption::VALUE_REQUIRED, 'If listing multiple URLs in one argument, use the given delimiter', '|')
6263
// The preflight check is optional because 'git apply --check' can be too picky sometimes (e.g. commit A adds a file; commit B renames the file)
6364
->addOption('check', NULL, InputOption::VALUE_NONE, 'Before applying patches, do a preflight check.')
@@ -79,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7980
}
8081

8182
$scanner = new \GitScan\GitRepoScanner();
82-
$gitRepos = $scanner->scan($input->getOption('path'));
83+
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
8384

8485
// array(string $absDir => TRUE)
8586
$checkouts = array();

src/GitScan/Command/BranchCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected function configure() {
3131
->setName('branch')
3232
->setDescription('Create branches across repos')
3333
->addOption('path', NULL, InputOption::VALUE_REQUIRED, 'The local base path to search', getcwd())
34+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
3435
->addOption('prefix', 'p', InputOption::VALUE_NONE, 'Autodetect prefixed variations')
3536
->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete fully merged branches')
3637
->addOption('force-delete', 'D', InputOption::VALUE_NONE, 'Delete branch (even if not merged)')
@@ -60,7 +61,7 @@ protected function executeCreate(InputInterface $input, OutputInterface $output)
6061

6162
$helper = $this->getHelper('question');
6263
$scanner = new \GitScan\GitRepoScanner();
63-
$gitRepos = $scanner->scan($input->getOption('path'));
64+
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
6465
$batch = new ProcessBatch('Creating branch(es)...');
6566
$self = $this;
6667

@@ -103,7 +104,7 @@ function (GitRepo $gitRepo, $oldBranch, $newBranch) use ($input, $output, $helpe
103104
protected function executeDelete(InputInterface $input, OutputInterface $output): int {
104105
$helper = $this->getHelper('question');
105106
$scanner = new \GitScan\GitRepoScanner();
106-
$gitRepos = $scanner->scan($input->getOption('path'));
107+
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
107108
$batch = new ProcessBatch('Deleting branch(es)...');
108109

109110
$branchName = $input->getArgument('branchName');

src/GitScan/Command/DiffCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected function configure() {
3434
->setHelp('Compare the commits/revisions in different source trees')
3535
->addArgument('from', InputArgument::REQUIRED, 'Path to the project folder or JSON export')
3636
->addArgument('to', InputArgument::REQUIRED, 'Path to the project folder or JSON export')
37+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
3738
->addOption('format', NULL, InputOption::VALUE_REQUIRED, 'Output format (text|html|json)', 'text');
3839
}
3940

@@ -46,8 +47,8 @@ protected function initialize(InputInterface $input, OutputInterface $output) {
4647
}
4748

4849
protected function execute(InputInterface $input, OutputInterface $output): int {
49-
$fromDoc = $this->getCheckoutDocument($input->getArgument('from'));
50-
$toDoc = $this->getCheckoutDocument($input->getArgument('to'));
50+
$fromDoc = $this->getCheckoutDocument($input->getArgument('from'), $input->getOption('max-depth'));
51+
$toDoc = $this->getCheckoutDocument($input->getArgument('to'), $input->getOption('max-depth'));
5152

5253
$report = new DiffReport(
5354
$fromDoc,
@@ -87,12 +88,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8788

8889
/**
8990
* @param string $path path to a directory or JSON file
91+
* @param int $maxDepth
9092
* @return \GitScan\CheckoutDocument
9193
*/
92-
protected function getCheckoutDocument($path) {
94+
protected function getCheckoutDocument($path, $maxDepth = -1) {
9395
if (is_dir($path)) {
9496
$scanner = new \GitScan\GitRepoScanner();
95-
$gitRepos = $scanner->scan($path);
97+
$gitRepos = $scanner->scan($path, $maxDepth);
9698

9799
return CheckoutDocument::create($path)
98100
->importRepos($gitRepos);

src/GitScan/Command/ExportCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use GitScan\Util\Filesystem;
55
use Symfony\Component\Console\Input\InputArgument;
66
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Output\OutputInterface;
89

910
class ExportCommand extends BaseCommand {
@@ -26,6 +27,7 @@ protected function configure() {
2627
->setName('export')
2728
->setDescription('Show the status of any nested git repositories')
2829
->setHelp("Export the current checkout information to JSON format")
30+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
2931
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
3032
}
3133

@@ -42,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4244
return 1;
4345
}
4446

45-
$gitRepos = $scanner->scan($paths);
47+
$gitRepos = $scanner->scan($paths, $input->getOption('max-depth'));
4648
$output->writeln(
4749
\GitScan\CheckoutDocument::create($paths[0])
4850
->importRepos($gitRepos)

src/GitScan/Command/ForeachCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function configure() {
4242
. "Important: The example uses single-quotes to escape the $'s\n"
4343
)
4444
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()))
45+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
4546
->addOption('command', 'c', InputOption::VALUE_REQUIRED, 'The command to execute')
4647
->addOption('status', NULL, InputOption::VALUE_REQUIRED, 'Filter table output by repo statuses ("all","novel","boring")', 'all');
4748
}
@@ -70,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7071
$output->writeln("<comment>[[ Finding repositories ]]</comment>");
7172
}
7273
$scanner = new \GitScan\GitRepoScanner();
73-
$gitRepos = $scanner->scan($input->getArgument('path'));
74+
$gitRepos = $scanner->scan($input->getArgument('path'), $input->getOption('max-depth'));
7475

7576
foreach ($gitRepos as $gitRepo) {
7677
/** @var \GitScan\GitRepo $gitRepo */

src/GitScan/Command/HashCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use GitScan\Util\Filesystem;
55
use Symfony\Component\Console\Input\InputArgument;
66
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Output\OutputInterface;
89

910
class HashCommand extends BaseCommand {
@@ -26,6 +27,7 @@ protected function configure() {
2627
->setName('hash')
2728
->setDescription('Generate a hash')
2829
->setHelp("Generate a cumulative hash code for the current checkouts")
30+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
2931
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
3032
}
3133

@@ -42,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4244
return 1;
4345
}
4446

45-
$output->writeln($scanner->hash($paths[0]));
47+
$output->writeln($scanner->hash($paths[0], $input->getOption('max-depth')));
4648
return 0;
4749
}
4850

src/GitScan/Command/LsCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected function configure() {
3131
Example: git scan ls | while read dir; do ls -la $dir ; done
3232
')
3333
->addOption('absolute', 'A', InputOption::VALUE_NONE, 'Output absolute paths')
34+
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
3435
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
3536
}
3637

@@ -47,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4748
return 1;
4849
}
4950

50-
$gitRepos = $scanner->scan($paths);
51+
$gitRepos = $scanner->scan($paths, $input->getOption('max-depth'));
5152
foreach ($gitRepos as $gitRepo) {
5253
/** @var \GitScan\GitRepo $gitRepo */
5354
$path = $input->getOption('absolute')

0 commit comments

Comments
 (0)