Skip to content

Commit

Permalink
fix for running arc patch on Windows with SVN
Browse files Browse the repository at this point in the history
  • Loading branch information
oujesky committed May 5, 2015
1 parent 8919a9c commit b728af9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 58 deletions.
11 changes: 11 additions & 0 deletions src/repository/api/ArcanistSubversionAPI.php
Expand Up @@ -45,6 +45,17 @@ protected function buildLocalFuture(array $argv) {
return $future;
}

public function execPassthru($pattern /* , ... */) {

$args = func_get_args();

$args[0] = 'svn ' . $args[0];

$passthru = newv('PhutilExecPassthru', $args);
$passthru->setCWD($this->getPath());
return $passthru->execute();
}

protected function buildCommitRangeStatus() {
// In SVN, the commit range is always "uncommitted changes", so these
// statuses are equivalent.
Expand Down
98 changes: 40 additions & 58 deletions src/workflow/ArcanistPatchWorkflow.php
Expand Up @@ -536,25 +536,20 @@ public function run() {
$this->createParentDirectoryOf($add);
}

// TODO: The SVN patch workflow likely does not work on windows because
// of the (cd ...) stuff.

foreach ($copies as $copy) {
list($src, $dst) = $copy;
passthru(
csprintf(
'(cd %s; svn cp %s %s)',
$repository_api->getPath(),
ArcanistSubversionAPI::escapeFileNameForSVN($src),
ArcanistSubversionAPI::escapeFileNameForSVN($dst)));
$repository_api->execPassthru(
'cp %s %s',
ArcanistSubversionAPI::escapeFileNameForSVN($src),
ArcanistSubversionAPI::escapeFileNameForSVN($dst)
);
}

foreach ($deletes as $delete) {
passthru(
csprintf(
'(cd %s; svn rm %s)',
$repository_api->getPath(),
ArcanistSubversionAPI::escapeFileNameForSVN($delete)));
$repository_api->execPassthru(
'rm %s',
ArcanistSubversionAPI::escapeFileNameForSVN($delete)
);
}

foreach ($symlinks as $symlink) {
Expand All @@ -565,12 +560,13 @@ public function run() {
case ArcanistDiffChangeType::TYPE_CHANGE:
case ArcanistDiffChangeType::TYPE_MOVE_HERE:
case ArcanistDiffChangeType::TYPE_COPY_HERE:
execx(
'(cd %s && ln -sf %s %s)',
$repository_api->getPath(),
$future = new ExecFuture(
'ln -sf %s %s',
$link_target,
$link_path);
break;
$link_path
);
$future->setCWD($repository_api->getPath());
$future->resolvex();
}
}

Expand All @@ -579,31 +575,24 @@ public function run() {
if ($patch) {
$tmp = new TempFile();
Filesystem::writeFile($tmp, $patch);
passthru(
csprintf(
'(cd %s; patch -p0 < %s)',
$repository_api->getPath(),
$tmp),
$err);
$passthru = new PhutilExecPassthru('patch -p0 -i %s', $tmp);
$passthru->setCWD($repository_api->getPath());
$err = $passthru->execute();
} else {
passthru(
csprintf(
'(cd %s; touch %s)',
$repository_api->getPath(),
$path),
$err);
$passthru = new PhutilExecPassthru('touch %s', $path);
$passthru->setCWD($repository_api->getPath());
$err = $passthru->execute();
}
if ($err) {
$patch_err = max($patch_err, $err);
}
}

foreach ($adds as $add) {
passthru(
csprintf(
'(cd %s; svn add %s)',
$repository_api->getPath(),
ArcanistSubversionAPI::escapeFileNameForSVN($add)));
$repository_api->execPassthru(
'add %s',
ArcanistSubversionAPI::escapeFileNameForSVN($add)
);
}

foreach ($propset as $path => $changes) {
Expand All @@ -614,20 +603,18 @@ public function run() {
$value = (octdec($value) & 0111 ? 'on' : null);
}
if ($value === null) {
passthru(
csprintf(
'(cd %s; svn propdel %s %s)',
$repository_api->getPath(),
$prop,
ArcanistSubversionAPI::escapeFileNameForSVN($path)));
$repository_api->execPassthru(
'propdel %s %s',
$prop,
ArcanistSubversionAPI::escapeFileNameForSVN($path)
);
} else {
passthru(
csprintf(
'(cd %s; svn propset %s %s %s)',
$repository_api->getPath(),
$prop,
$value,
ArcanistSubversionAPI::escapeFileNameForSVN($path)));
$repository_api->execPassthru(
'propset %s %s %s',
$prop,
$value,
ArcanistSubversionAPI::escapeFileNameForSVN($path)
);
}
}
}
Expand Down Expand Up @@ -1008,15 +995,10 @@ private function createParentDirectoryOf($path) {
} else {
// Make sure the parent directory exists before we make this one.
$this->createParentDirectoryOf($dir);
execx(
'(cd %s && mkdir %s)',
$repository_api->getPath(),
$dir);
passthru(
csprintf(
'(cd %s && svn add %s)',
$repository_api->getPath(),
$dir));
$future = new ExecFuture('mkdir %s', $dir);
$future->setCWD($repository_api->getPath());
$future->resolvex();
$repository_api->execPassthru('add %s', $dir);
}
}

Expand Down

3 comments on commit b728af9

@ydsood
Copy link

@ydsood ydsood commented on b728af9 Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes. The arc patch utility works after this.

@SwordreamLj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I use the patch for latest arcanist in https://github.com/phacility/arcanist
This is my fork link https://github.com/ljian-1989/arcanist/commit/6c6124368a3aa5d7c3077d96e613e766f0f4571b
when I use the arc patch on windows
I get this error like below:

PS D:\workspace\code\tmp\test> arc --trace patch D12
ARGV "D:\programs\arcanist\bin..\scripts\arcanist.php" "--trace" "patch" "D12"
LOAD Loaded "phutil" from "D:\programs\libphutil\src".
LOAD Loaded "arcanist" from "D:\programs\arcanist\src".
Config: Reading user configuration file "C:\Users\liujj\AppData\Roaming/.arcrc"...
Config: Did not find system configuration at "C:\ProgramData\Phabricator/Arcanist/config".
Working Copy: Reading .arcconfig from "D:\workspace\code\tmp\test/.arcconfig".
Working Copy: Path "D:\workspace\code\tmp\test" is part of svn working copy "D:\workspace\code\tmp\test".
Working Copy: Project root is at "D:\workspace\code\tmp\test".
Config: Did not find local configuration at "D:\workspace\code\tmp\test.svn\arc/config".

[0] (+0) http://phabricator.com/api/differential.querydiffs
<<< [0] (+285) 285,370 us
[1] (+285) http://phabricator.com/api/user.whoami
<<< [1] (+396) 110,209 us
[2] (+396) http://phabricator.com/api/differential.querydiffs
<<< [2] (+559) 163,321 us
[3] (+562) http://phabricator.com/api/repository.query
<<< [3] (+670) 108,146 us
[4] (+672) $ svn --xml status
<<< [4] (+1,346) 673,614 us
[5] (+1,350) $ patch -p0 -i "C:\Users\liujj\AppData\Local\Temp\3441il6nt7cw8ck0\2129C98.tmp"

[2019-05-09 04:28:10] EXCEPTION: (Exception) Failed to passthru proc_open(): proc_open(): CreateProcess failed, error code - 2 at [\src\future\exec\PhutilExecPassthru.php:103]
arcanist(head=master, ref.master=9830c9316d38), phutil(head=master, ref.master=70ac0d66e300)
#0 PhutilExecPassthru::execute() called at [\src\workflow\ArcanistPatchWorkflow.php:621]
phacility#1 ArcanistPatchWorkflow::run() called at [\src\workflow\ArcanistPatchWorkflow.php:398]
phacility#2 ArcanistPatchWorkflow::run() called at [\scripts\arcanist.php:394]

@SwordreamLj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I use the patch for latest arcanist in https://github.com/phacility/arcanist
This is my fork link ljian-1989@6c61243
when I use the arc patch on windows
I get this error like below:

PS D:\workspace\code\tmp\test> arc --trace patch D12
ARGV "D:\programs\arcanist\bin..\scripts\arcanist.php" "--trace" "patch" "D12"
LOAD Loaded "phutil" from "D:\programs\libphutil\src".
LOAD Loaded "arcanist" from "D:\programs\arcanist\src".
Config: Reading user configuration file "C:\Users\liujj\AppData\Roaming/.arcrc"...
Config: Did not find system configuration at "C:\ProgramData\Phabricator/Arcanist/config".
Working Copy: Reading .arcconfig from "D:\workspace\code\tmp\test/.arcconfig".
Working Copy: Path "D:\workspace\code\tmp\test" is part of svn working copy "D:\workspace\code\tmp\test".
Working Copy: Project root is at "D:\workspace\code\tmp\test".
Config: Did not find local configuration at "D:\workspace\code\tmp\test.svn\arc/config".

[0] (+0) http://phabricator.com/api/differential.querydiffs
<<< [0] (+285) 285,370 us
[1] (+285) http://phabricator.com/api/user.whoami
<<< [1] (+396) 110,209 us
[2] (+396) http://phabricator.com/api/differential.querydiffs
<<< [2] (+559) 163,321 us
[3] (+562) http://phabricator.com/api/repository.query
<<< [3] (+670) 108,146 us
[4] (+672) $ svn --xml status
<<< [4] (+1,346) 673,614 us
[5] (+1,350) $ patch -p0 -i "C:\Users\liujj\AppData\Local\Temp\3441il6nt7cw8ck0\2129C98.tmp"

[2019-05-09 04:28:10] EXCEPTION: (Exception) Failed to passthru proc_open(): proc_open(): CreateProcess failed, error code - 2 at [\src\future\exec\PhutilExecPassthru.php:103]
arcanist(head=master, ref.master=9830c9316d38), phutil(head=master, ref.master=70ac0d66e300)
#0 PhutilExecPassthru::execute() called at [\src\workflow\ArcanistPatchWorkflow.php:621]
phacility#1 ArcanistPatchWorkflow::run() called at [\src\workflow\ArcanistPatchWorkflow.php:398]
phacility#2 ArcanistPatchWorkflow::run() called at [\scripts\arcanist.php:394]

I finally find the reason which case this problems. Because the patch.exe is not in PATH.
After I join the "C:\Git\usr\bin" to PATH, it is solved

Please sign in to comment.