Created
February 18, 2011 04:07
-
-
Save rfay/833238 to your computer and use it in GitHub Desktop.
This is the PIFR code that deals with applying the patch and then getting what files were changed by it.
This file contains 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
public function apply($patch) { | |
return pifr_client_review::exec("patch -p1 -i $patch"); | |
} | |
public function get_changed_files($patch) { | |
$contents = file_get_contents($patch); | |
// This regex looks through the patch file for lines of the format | |
// +++ b/install.php | |
// and removes the '+++ b/' from them, returning the filenames that have | |
// had content added. | |
preg_match_all('%^[\+-]{3}\s+[^/]\/(.*?)\s%m', $contents, $matches, PREG_SET_ORDER); | |
$files = array(); | |
foreach ($matches as $match) { | |
if ($match[1] != '/dev/null') { | |
$files[] = $match[1]; | |
} | |
} | |
return array_unique($files); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems to me like the regex is going to be fragile if we make it work for -p1 and -p0.