-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-full-import.php
executable file
·153 lines (126 loc) · 4.67 KB
/
run-full-import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env php
<?php
$concurrency = getenv('C2G_CONCURRENCY');
$concurrency = is_string($concurrency) ? $concurrency : 13;
$srcrepo = getenv('C2G_REPOSITORY');
$srcrepo = is_string($srcrepo) ? $srcrepo : '/var/git/cvsmirror';
$destpath = getenv('C2G_DESTINATION');
$destpath = is_string($destpath) ? $destpath : '/var/git/repositories';
$optsfile = getenv('C2G_CVS2GIT_OPTIONS');
$optsfile = is_string($optsfile) ? $optsfile : dirname(__FILE__) . '/cvs2git-trunk.options';
set_time_limit(0); // Ensure we don't time out.
// Load shared functions.
require_once dirname(__FILE__) . '/shared.php';
if (!file_exists(dirname(__FILE__) . '/project-migrate-info')) {
// No source transform file, bail out
echo 'No project migrate info file, cannot proceed.';
exit(1);
}
// Format: <srcpath> <dest> <strip translations>
$list = file(dirname(__FILE__) . '/project-migrate-info');
// Run forked subprocesses
$status = 0;
$forks = 0;
$empties = new SplFileObject(dirname(__FILE__) . '/empties', 'w');
$emptylist = array();
// Scrub the output dir, it needs to be clean for errors to be real
$shell_dest = escapeshellarg("$destpath/project");
`rm -rf $shell_dest`;
git_log("\n*****************\nBegin forking import processes\n*****************\n", 'DEBUG');
foreach ($list as $n => $line) {
if ($forks >= $concurrency) {
$pid = pcntl_wait($status);
$status = pcntl_wifstopped($status);
$forks--;
if (!empty($status)) {
break;
}
}
$projectdata = explode(',', $line);
// Core is stupid, as always. Here's hoping this is one of the last special cases we write for it
if ($projectdata[1] != 'drupal') {
if (file_exists("$destpath/project/{$projectdata[1]}.git")) {
git_log('Crap on a cracker, the target dir already exists!', 'WARN', $projectdata[1]);
continue;
}
if (empty($projectdata[0]) || !is_cvs_dir($srcrepo . '/contributions' . $projectdata[0])) {
git_log('No CVS source information for project; will spawn an empty repo for it later.', 'INFO', $projectdata[1]);
$empties->fwrite(sprintf('%s,%d' . PHP_EOL, $projectdata[1], $projectdata[3]));
$emptylist[] = $n;
continue;
}
}
// OK, we're ready to proceed. fork it FORK IT GOOD
$pid = pcntl_fork();
if ($pid == -1) {
die("oh noes! no fork!");
}
else if ($pid) {
// Parent; increment fork counter.
$forks++;
}
else {
if (preg_match('/^git:/', $projectdata[0])) {
git_invoke("git clone --bare $projectdata[0] $destpath/project/{$projectdata[1]}.git", FALSE);
convert_project_branches($projectdata[1], "$destpath/project/{$projectdata[1]}.git", $rename_patterns['contrib']['branches']);
convert_project_tags($projectdata[1], "$destpath/project/{$projectdata[1]}.git", $rename_patterns['contrib']['tagmatch'], $rename_patterns['contrib']['tags']);
exit(0);
}
else {
$success = import_directory($optsfile, $srcrepo, ($projectdata[1] == 'drupal' ? 'drupal' : 'contributions') . $projectdata[0], "$destpath/project/{$projectdata[1]}.git", TRUE);
}
exit(empty($success));
}
git_log("Finished import #$n\n", 'DEBUG');
}
git_log("\n*****************\nFinished forking import processes, now waiting for all children to complete\n*****************\n", 'DEBUG');
// Make sure all forked children finish.
while ($forks) {
git_log("Fork count remaining: $forks\n", 'DEBUG');
pcntl_wait($status);
$forks--;
}
if (!empty($status)) {
exit($status);
}
git_log("Empties list:\n" . print_r($emptylist, TRUE), 'DEBUG');
// Now do any necessary cleanup/stripping.
git_log("\n*****************\nBegin forking cleanup processes\n*****************\n", 'DEBUG');
$forks = 0; // Reinit just to be sure
foreach ($list as $n => $line) {
if ($forks >= $concurrency) {
$pid = pcntl_wait($status);
$status = pcntl_wifstopped($status);
$forks--;
if (!empty($status)) {
break;
}
}
// Skip this step if we know the repo doesn't exist.
if (in_array($n, $emptylist)) {
continue;
}
$projectdata = explode(',', $line);
// fork it FORK IT _BETTER_
$pid = pcntl_fork();
if ($pid == -1) {
die("oh noes! no fork!");
}
else if ($pid) {
// Parent; increment fork counter.
$forks++;
}
else {
$success = cleanup_migrated_repo($projectdata[1], "$destpath/project/{$projectdata[1]}.git", TRUE, $projectdata[2] == '1');
exit(empty($success));
}
git_log("Finished cleanup #$n\n", 'DEBUG');
}
// Make sure all forked children finish.
git_log("\n*****************\nFinished forking cleanup processes, now waiting for all children to complete\n*****************\n", 'DEBUG');
while ($forks) {
git_log("Fork count remaining: $forks\n", 'DEBUG');
pcntl_wait($status);
$forks--;
}
exit($status);