Skip to content

Instantly share code, notes, and snippets.

@rfay
Created February 18, 2011 04:07
Show Gist options
  • Save rfay/833238 to your computer and use it in GitHub Desktop.
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.
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);
}
@rfay
Copy link
Author

rfay commented Feb 18, 2011

It seems to me like the regex is going to be fragile if we make it work for -p1 and -p0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment