Apostrophe SVN Foreign Copy


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. if (count($argv) !== 4)
  4. {
  5. die("Usage: svnforeigncopy from-repo-url to-repo-url local-checkout-dir\n");
  6. }
  7.  
  8. $from = $argv[1];
  9. $to = $argv[2];
  10. $local = $argv[3];
  11.  
  12. echo("Creating $to\n");
  13. mysystem("svn mkdir --parents " . escapeshellarg($to));
  14. echo("Checking out $to\n");
  15. mysystem("svn co " . escapeshellarg($to) . " " . escapeshellarg($local));
  16. echo("Exporting non-external content of $from to $local\n");
  17. mysystem("svn export --force --ignore-externals " . escapeshellarg($from) . " " . escapeshellarg($local));
  18. echo("Checking out $from to $local.tmp without externals so that we can do efficient recursive propgets\n");
  19. mysystem("svn co --ignore-externals " . escapeshellarg($from) . " " . escapeshellarg("$local.tmp"));
  20. echo("Querying svn:externals properties of $from\n");
  21. $externals = simplexml_load_string(stream_get_contents(popen("svn propget --xml --recursive svn:externals " . escapeshellarg("$local.tmp"), "r")));
  22. echo("Querying svn:ignore properties of $from\n");
  23. $ignores = simplexml_load_string(stream_get_contents(popen("svn propget --xml --recursive svn:ignore " . escapeshellarg("$local.tmp"), "r")));
  24. echo("Adding $local contents (necessary before externals can be set)\n");
  25. mysystem("cd " . escapeshellarg($local) . "; svn add *; cd ..");
  26. echo("Applying externals\n");
  27. applyProperties($externals);
  28. echo("Applying ignores\n");
  29. applyProperties($ignores);
  30. echo("Removing $local.tmp");
  31. mysystem("rm -rf " . escapeshellarg("$local.tmp"));
  32. echo("Committing $local\n");
  33. mysystem("svn commit " . escapeshellarg($local));
  34. echo("Updating $local\n");
  35. mysystem("svn update " . escapeshellarg($local));
  36. echo("Done!\n");
  37.  
  38. function applyProperties($properties)
  39. {
  40. global $local;
  41. foreach ($properties->target as $target)
  42. {
  43. $path = $target['path'];
  44. $path = str_replace("$local.tmp/", "", $path);
  45. foreach ($target->property as $property)
  46. {
  47. $name = $property['name'];
  48. $value = (string) $property;
  49. mysystem("svn propset " . escapeshellarg($name) . " " . escapeshellarg($value) . " " . escapeshellarg("$local/$path"));
  50. }
  51. }
  52. }
  53.  
  54. function mysystem($cmd)
  55. {
  56. passthru($cmd, $val);
  57. if ($val != 0)
  58. {
  59. die("Command $cmd exited with nonzero exit status $val\n");
  60. }
  61. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.