Last active
February 5, 2022 00:29
-
-
Save ammarfaizi2/b3d2b3721b536b8c5ff443ec491b5c4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
chdir("/opt/systemd/linux2"); | |
$handle = fopen("/tmp/.linux.git_lock", "a"); | |
while (!flock($handle, LOCK_EX | LOCK_NB)) { | |
printf("Waiting for the lock...\n"); | |
sleep(1); | |
} | |
function ca($str) | |
{ | |
return substr($str, 1); | |
} | |
$remotes = [ | |
"@acme/linux", | |
"@arm64/linux", | |
"@axboe/linux-block", | |
"@bluetooth/bluez", | |
"@bp/bp", | |
"@bpf/bpf", | |
"@bpf/bpf-next", | |
"@brauner/linux", | |
"@brauner/xfstests-dev", | |
"@clk/linux", | |
"@crng/random", | |
"@dhowells/linux-fs", | |
"@google/android/kernel/common", | |
"@gregkh/char-misc", | |
"@gregkh/driver-core", | |
"@gregkh/staging", | |
"@herbert/cryptodev-2.6", | |
"@kdave/linux", | |
"@kvalo/ath", | |
"@luto/linux", | |
"@mchehab/linux-media", | |
"@mellanox/linux", | |
"@mingo/tip", | |
"@netdev/net", | |
"@netdev/net-next", | |
"@palmer/linux", | |
"@paulmck/linux-rcu", | |
"@rdma/rdma", | |
"@robh/linux", | |
"@rostedt/linux-trace", | |
"@shuah/linux-kselftest", | |
"@snawrocki/clk", | |
"@stable/linux", | |
"@stable/linux-stable-rc", | |
"@terrelln/linux", | |
"@tglx/devel", | |
"@tiwai/sound", | |
"@tj/cgroup", | |
"@torvalds/linux", | |
]; | |
$pids = []; | |
foreach ($remotes as $remote) { | |
$pid = pcntl_fork(); | |
if (!$pid) { | |
printf("Fetching {$remote}...\n"); | |
$remote = escapeshellarg($remote); | |
shell_exec("git fetch --prune {$remote}"); | |
exit(0); | |
} | |
$pids[] = $pid; | |
} | |
foreach ($pids as $pid) | |
pcntl_waitpid($pid, $status, WUNTRACED); | |
printf("Fetch finished!\n"); | |
$active_branches = []; | |
$tmp = preg_split("/\s+/", trim(shell_exec("git branch --list | grep -oE '\s.+'"))); | |
foreach ($tmp as $p) | |
$active_branches[trim($p)] = true; | |
unset($p); | |
$remote_branches = preg_split("/\s+/", trim(shell_exec("git branch --list --remote | grep -oE '\s.+'"))); | |
foreach ($remote_branches as &$p) | |
$p = ca(trim($p)); | |
unset($p); | |
$i = 0; | |
printf("Tracking new branches...\n"); | |
foreach ($remote_branches as $branch) { | |
/* Skip target push. */ | |
if (preg_match("/git(hub|lab)/", $branch)) | |
continue; | |
if (!isset($active_branches[$branch])) { | |
$i++; | |
$t_branch = escapeshellarg($branch); | |
$t_remote = escapeshellarg("remotes/@{$branch}"); | |
shell_exec("git branch --track {$t_branch} {$t_remote}"); | |
$active_branches[$branch] = true; | |
} | |
} | |
printf("There are %d new branch(es)\n", $i); | |
// Pull for master | |
shell_exec("git pull"); | |
$pidRefUpdate = pcntl_fork(); | |
if (!$pidRefUpdate) { | |
printf("Updating refs...\n"); | |
foreach ($active_branches as $branch => $p) { | |
if (!strcmp($branch, "master")) | |
continue; | |
$ref = escapeshellarg("refs/heads/{$branch}"); | |
$remote_target = escapeshellarg("remotes/@{$branch}"); | |
shell_exec("git update-ref {$ref} {$remote_target}"); | |
} | |
printf("Refs have been updated!\n"); | |
exit(0); | |
} | |
shell_exec("renice -n 20 ".escapeshellarg($pidRefUpdate)); | |
$remotes_for_push = [ | |
"@@github.com/ammarfaizi2/linux-block", | |
"@@gitlab.com/ammarfaizi2/linux-block", | |
"@@github.com/ammarfaizi2/linux-fork", | |
// "@@github.com/GNUWeeb/linux", | |
]; | |
$pids = []; | |
foreach ($remotes_for_push as $remote) { | |
$remote_esc = escapeshellarg($remote); | |
printf("Pushing branches to %s...\n", $remote); | |
shell_exec("git push --force --all {$remote_esc}"); | |
printf("Pushing tags to %s...\n", $remote); | |
shell_exec("git push --force --tags {$remote_esc}"); | |
} | |
printf("Push finished!\n"); | |
pcntl_waitpid($pidRefUpdate, $status, WUNTRACED); | |
flock($handle, LOCK_UN); | |
fclose($handle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment