]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Arcanist: Apply symlink patches correctly
authorepriestley <epriestley@javelinjs.com>
Tue, 8 Mar 2011 05:33:36 +0000 (21:33 -0800)
committerepriestley <epriestley@javelinjs.com>
Wed, 9 Mar 2011 08:47:01 +0000 (00:47 -0800)
Summary:
When an arcbundle includes a symlink, we fail to apply it correctly
when applying to a subversion working copy.

Test Plan:
created a diff which added a symlink, removed it locally, bundled
and applied the patch, got a good symlink out

Reviewed By: aran
Reviewers: aran
CC: epriestley, aran
Differential Revision: 63

src/parser/diff/change/ArcanistDiffChange.php
src/workflow/patch/ArcanistPatchWorkflow.php

index ff7ced1decc8d3c723ac233be0ac734564ffa9c5..2a2a3a7f24ece5559477855ec9fdc27cb3596226 100644 (file)
@@ -225,5 +225,18 @@ class ArcanistDiffChange {
     return implode("\n", $summary);
   }
 
+  public function getSymlinkTarget() {
+    if ($this->getFileType() != ArcanistDiffChangeType::FILE_SYMLINK) {
+      throw new Exception("Not a symlink!");
+    }
+    $hunks = $this->getHunks();
+    $hunk = reset($hunks);
+    $corpus = $hunk->getCorpus();
+    $match = null;
+    if (!preg_match('/^\+(?:link )?(.*)$/m', $corpus, $match)) {
+      throw new Exception("Failed to extract link target!");
+    }
+    return trim($match[1]);
+  }
 
 }
index 71ec07e75e1a4d250bf79202281ccbfe166baf3b..963f50cb0180272429ebb702917ec4a90924285b 100644 (file)
@@ -177,11 +177,21 @@ EOTEXT
       $patches = array();
       $propset = array();
       $adds = array();
+      $symlinks = array();
 
       $changes = $bundle->getChanges();
       foreach ($changes as $change) {
         $type = $change->getType();
         $should_patch = true;
+
+        $filetype = $change->getFileType();
+        switch ($filetype) {
+          case ArcanistDiffChangeType::FILE_SYMLINK:
+            $should_patch = false;
+            $symlinks[] = $change;
+            break;
+        }
+
         switch ($type) {
           case ArcanistDiffChangeType::TYPE_MOVE_AWAY:
           case ArcanistDiffChangeType::TYPE_MULTICOPY:
@@ -270,6 +280,23 @@ EOTEXT
             $delete));
       }
 
+      foreach ($symlinks as $symlink) {
+        $link_target = $symlink->getSymlinkTarget();
+        $link_path = $symlink->getCurrentPath();
+        switch ($symlink->getType()) {
+          case ArcanistDiffChangeType::TYPE_ADD:
+          case ArcanistDiffChangeType::TYPE_MODIFY:
+          case ArcanistDiffChangeType::TYPE_MOVE_HERE:
+          case ArcanistDiffChangeType::TYPE_COPY_HERE:
+            execx(
+              '(cd %s && ln -sf %s %s)',
+              $repository_api->getPath(),
+              $link_target,
+              $link_path);
+            break;
+        }
+      }
+
       foreach ($patches as $path => $patch) {
         $tmp = new TempFile();
         Filesystem::writeFile($tmp, $patch);