Skip to content

Commit 0ba6dc0

Browse files
committed
Comment / var name updates
1 parent abf8ffd commit 0ba6dc0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

merge.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#!/usr/bin/env php
22
<?php
33

4+
// placeholder to denote a conflict in a json property
45
define('CONFLICT_PLACEHOLDER', '=c=o=n=f=(\d+)=l=i=c=t=');
6+
// options for json encode
57
define('JSON_ENCODE_OPTIONS', JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
68
// file states
79
$states = ['ancestor', 'ours', 'theirs'];
810
// unique object that represents a void
911
$void = (object) [];
1012
// conflicts we have identified
1113
$conflicts = [];
12-
// options for json encode
14+
// length for conflict marker (<<<)
1315
$markerLen = $argv[4];
16+
// are we working with the lock file?
17+
$isLock = strtolower($argv[5]) === 'composer.lock';
1418

1519
// grab the contents of each file state
1620
foreach ($states as $i => $state) {
@@ -92,21 +96,21 @@ function merge($ancestor, $ours, $theirs) {
9296
}
9397

9498
// special handling for lock files
95-
if (strtolower($argv[5]) === 'composer.lock') {
96-
$packageKeys = ['packages', 'packages-dev', 'aliases'];
99+
if ($isLock) {
100+
// @todo handle alias property as well
101+
$packageKeys = ['packages', 'packages-dev'];
97102

98103
foreach ($states as $state) {
99104
// ensure we don't get a conflict on the content hash
100105
${$state}['content-hash'] = null;
101106

102107
// convert package array to assoc array, mapping package name to json-encoded package definition
103108
foreach ($packageKeys as $key) {
104-
$newArray = [];
109+
$packageArray = [];
105110
foreach (${$state}[$key] as $package) {
106-
// @todo this is different for alias
107-
$newArray[$package['name']] = json_encode($package);
111+
$packageArray[$package['name']] = json_encode($package);
108112
}
109-
${$state}[$key] = $newArray;
113+
${$state}[$key] = $packageArray;
110114
}
111115
}
112116

@@ -118,25 +122,26 @@ function merge($ancestor, $ours, $theirs) {
118122
// sort the packages
119123
ksort($merged[$key]);
120124

121-
$newArray = [];
125+
$packageArray = [];
122126
foreach ($merged[$key] as $package) {
123127
// if we have a conflict, convert the conflicting values back to package definition arrays
124128
if (preg_match('/^' . CONFLICT_PLACEHOLDER . '$/', $package, $matches)) {
125129
$conflicts[$matches[1]] = array_map(function($json) {
126130
return json_decode($json, true);
127131
}, $conflicts[$matches[1]]);
128-
$newArray[] = $package;
132+
$packageArray[] = $package;
129133
}
130134
// otherwise just convert the value back to a package definition array
131135
else {
132-
$newArray[] = json_decode($package, true);
136+
$packageArray[] = json_decode($package, true);
133137
}
134138
}
135-
$merged[$key] = $newArray;
139+
$merged[$key] = $packageArray;
136140
}
137141

138-
// update the content-hash key
139-
$merged['content-hash'] = (count($conflicts) ? 'Merge conflict!' : 'Auto-merged!') . ' Run `composer update --lock` to regenerate';
142+
// update the content-hash key with a helpful message
143+
$merged['content-hash'] = sprintf(count($conflicts) ? 'Merge conflict! %s after fixing conflict(s)' : 'Auto-merged! %s',
144+
'Run `composer update --lock` to regenerate');
140145

141146
$merged = json_encode($merged, JSON_ENCODE_OPTIONS);
142147
} else {

0 commit comments

Comments
 (0)