Skip to content
This repository

Add support for alternative SVN structures #1037

Merged
merged 3 commits into from over 1 year ago

5 participants

Bart Don't Add Me To Your Organization a.k.a The Travis Bot Jordi Boggiano Christophe Coevoet Serge Smertin
Bart

This feature adds basic support for the SvnDriver to work with a non-default directory structure.

By default most repositories are set-up with the trunk/branches/tags directories, however since Subversion does not enforce this (best-practice) structure it does happen that within companies the folder structure (slightly) differs from the best practice.

I added this pull request because (surprising) the company I work for uses a different structure which is a company policy to follow, so to be able to use composer (since I like it a lot) this feature could really make my life a lot better (and maybe others as well if they use a different structure).

Regards, Bart

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 93628c4 into e2f8098).

Jordi Boggiano
Owner

Could you just change trunkLocation and others to trunk-path (or at least trunk-location)? I'm not sure if location or path is best, but we use dash separated words everywhere in composer.json, so it'd be best to follow that.

Jordi Boggiano
Owner

Oh also I didn't realize you read it from the main Config instance, that's probably not a good idea because it makes the setting apply to all SVN repos. Ideally the VcsRepository should forward the whole $repoConfig array to VcsDrivers, so that you can get the data from there and configure it like:

{
    "repositories": [
        { "type": "svn", "url": "svn://..", "trunk-path": "boing" }
    ]
}

If you have no idea what I'm talking about, I guess I'll do the change myself while merging the PR :)

Bart

Hi Seldaek, I'd like to try and implement it the way you are suggesting. To be able to forward the whole repoConfig would it be ok to add the repoConfig as an option to the VcsDriver constructor, or maybe as a parameter on the initialize method of the VcsDriver?

Jordi Boggiano
Owner

@bboer I think the easiest would be to replace the $url arg of the constructor by the full repoConfig, otherwise you end up sending the url twice.

Bart

Hi Seldaek, Just made some changes to pass the repoConfig through the constructor. It is indeed a nicer way to do it like this. Dit some tests locally with an alternative svn structure and it works nicely.

Jordi Boggiano
Owner

Ok thanks, I'm leaving for a few days and will take a look at merging this when I get back, looks good though at first sight.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged d1a452b into e2f8098).

Christophe Coevoet
stof commented August 30, 2012

@bboer please fox the tests for the drivers

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 00361e0 into e2f8098).

Serge Smertin
nfx commented October 18, 2012

+1, the sooner the better :)

Jordi Boggiano Seldaek merged commit 00361e0 into from October 19, 2012
Jordi Boggiano Seldaek closed this October 19, 2012
Jordi Boggiano
Owner

Finally merged this, thanks. Also added docs http://getcomposer.org/doc/05-repositories.md#subversion-options

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

Showing 3 unique commits by 1 author.

Aug 29, 2012
Bart Add support for alternative structures 93628c4
Aug 30, 2012
Bart Made repoConfig available for the VcsDriver to be able to provide add…
…itional configuration options easily.
d1a452b
Aug 31, 2012
Bart Fixed tests 00361e0
This page is out of date. Refresh to see the latest.
2  src/Composer/Repository/Vcs/GitHubDriver.php
@@ -270,7 +270,7 @@ protected function fetchRootIdentifier()
270 270
                             // cannot ask for authentication credentials (because we
271 271
                             // are not interactive) then we fallback to GitDriver.
272 272
                             $this->gitDriver = new GitDriver(
273  
-                                $this->generateSshUrl(),
  273
+                                array('url' => $this->generateSshUrl()),
274 274
                                 $this->io,
275 275
                                 $this->config,
276 276
                                 $this->process,
33  src/Composer/Repository/Vcs/SvnDriver.php
@@ -32,6 +32,10 @@ class SvnDriver extends VcsDriver
32 32
     protected $branches;
33 33
     protected $infoCache = array();
34 34
 
  35
+    protected $trunkPath    = 'trunk';
  36
+    protected $branchesPath = 'branches';
  37
+    protected $tagsPath     = 'tags';
  38
+
35 39
     /**
36 40
      * @var \Composer\Util\Svn
37 41
      */
@@ -44,7 +48,17 @@ public function initialize()
44 48
     {
45 49
         $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/');
46 50
 
47  
-        if (false !== ($pos = strrpos($this->url, '/trunk'))) {
  51
+        if (isset($this->repoConfig['trunk-path'])) {
  52
+            $this->trunkPath = $this->repoConfig['trunk-path'];
  53
+        }
  54
+        if (isset($this->repoConfig['branches-path'])) {
  55
+            $this->branchesPath = $this->repoConfig['branches-path'];
  56
+        }
  57
+        if (isset($this->repoConfig['tags-path'])) {
  58
+            $this->tagsPath = $this->repoConfig['tags-path'];
  59
+        }
  60
+
  61
+        if (false !== ($pos = strrpos($this->url, '/' . $this->trunkPath))) {
48 62
             $this->baseUrl = substr($this->url, 0, $pos);
49 63
         }
50 64
 
@@ -59,7 +73,7 @@ public function initialize()
59 73
      */
60 74
     public function getRootIdentifier()
61 75
     {
62  
-        return 'trunk';
  76
+        return $this->trunkPath;
63 77
     }
64 78
 
65 79
     /**
@@ -145,13 +159,14 @@ public function getTags()
145 159
         if (null === $this->tags) {
146 160
             $this->tags = array();
147 161
 
148  
-            $output = $this->execute('svn ls --verbose', $this->baseUrl . '/tags');
  162
+            $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath);
149 163
             if ($output) {
150 164
                 foreach ($this->process->splitLines($output) as $line) {
151 165
                     $line = trim($line);
152 166
                     if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
153 167
                         if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
154  
-                            $this->tags[rtrim($match[2], '/')] = '/tags/'.$match[2].'@'.$match[1];
  168
+                            $this->tags[rtrim($match[2], '/')] = '/' . $this->tagsPath .
  169
+                                '/' . $match[2] . '@' . $match[1];
155 170
                         }
156 171
                     }
157 172
                 }
@@ -174,8 +189,9 @@ public function getBranches()
174 189
                 foreach ($this->process->splitLines($output) as $line) {
175 190
                     $line = trim($line);
176 191
                     if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
177  
-                        if (isset($match[1]) && isset($match[2]) && $match[2] === 'trunk/') {
178  
-                            $this->branches['trunk'] = '/trunk/@'.$match[1];
  192
+                        if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkPath . '/') {
  193
+                            $this->branches[$this->trunkPath] = '/' . $this->trunkPath .
  194
+                                '/@'.$match[1];
179 195
                             break;
180 196
                         }
181 197
                     }
@@ -183,13 +199,14 @@ public function getBranches()
183 199
             }
184 200
             unset($output);
185 201
 
186  
-            $output = $this->execute('svn ls --verbose', $this->baseUrl . '/branches');
  202
+            $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesPath);
187 203
             if ($output) {
188 204
                 foreach ($this->process->splitLines(trim($output)) as $line) {
189 205
                     $line = trim($line);
190 206
                     if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
191 207
                         if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
192  
-                            $this->branches[rtrim($match[2], '/')] = '/branches/'.$match[2].'@'.$match[1];
  208
+                            $this->branches[rtrim($match[2], '/')] = '/' . $this->branchesPath .
  209
+                                '/' . $match[2] . '@' . $match[1];
193 210
                         }
194 211
                     }
195 212
                 }
10  src/Composer/Repository/Vcs/VcsDriver.php
@@ -27,6 +27,7 @@
27 27
 {
28 28
     protected $url;
29 29
     protected $originUrl;
  30
+    protected $repoConfig;
30 31
     protected $io;
31 32
     protected $config;
32 33
     protected $process;
@@ -35,16 +36,17 @@
35 36
     /**
36 37
      * Constructor.
37 38
      *
38  
-     * @param string          $url              The URL
  39
+     * @param array           $repoConfig       The repository configuration
39 40
      * @param IOInterface     $io               The IO instance
40 41
      * @param Config          $config           The composer configuration
41 42
      * @param ProcessExecutor $process          Process instance, injectable for mocking
42 43
      * @param callable        $remoteFilesystem Remote Filesystem, injectable for mocking
43 44
      */
44  
-    final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
  45
+    final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
45 46
     {
46  
-        $this->url = $url;
47  
-        $this->originUrl = $url;
  47
+        $this->url = $repoConfig['url'];
  48
+        $this->originUrl = $repoConfig['url'];
  49
+        $this->repoConfig = $repoConfig;
48 50
         $this->io = $io;
49 51
         $this->config = $config;
50 52
         $this->process = $process ?: new ProcessExecutor;
8  src/Composer/Repository/VcsRepository.php
@@ -33,6 +33,7 @@ class VcsRepository extends ArrayRepository
33 33
     protected $versionParser;
34 34
     protected $type;
35 35
     protected $loader;
  36
+    protected $repoConfig;
36 37
 
37 38
     public function __construct(array $repoConfig, IOInterface $io, Config $config, array $drivers = null)
38 39
     {
@@ -50,6 +51,7 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config,
50 51
         $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
51 52
         $this->verbose = $io->isVerbose();
52 53
         $this->config = $config;
  54
+        $this->repoConfig = $repoConfig;
53 55
     }
54 56
 
55 57
     public function setLoader(LoaderInterface $loader)
@@ -61,7 +63,7 @@ public function getDriver()
61 63
     {
62 64
         if (isset($this->drivers[$this->type])) {
63 65
             $class = $this->drivers[$this->type];
64  
-            $driver = new $class($this->url, $this->io, $this->config);
  66
+            $driver = new $class($this->repoConfig, $this->io, $this->config);
65 67
             $driver->initialize();
66 68
 
67 69
             return $driver;
@@ -69,7 +71,7 @@ public function getDriver()
69 71
 
70 72
         foreach ($this->drivers as $driver) {
71 73
             if ($driver::supports($this->io, $this->url)) {
72  
-                $driver = new $driver($this->url, $this->io, $this->config);
  74
+                $driver = new $driver($this->repoConfig, $this->io, $this->config);
73 75
                 $driver->initialize();
74 76
 
75 77
                 return $driver;
@@ -78,7 +80,7 @@ public function getDriver()
78 80
 
79 81
         foreach ($this->drivers as $driver) {
80 82
             if ($driver::supports($this->io, $this->url, true)) {
81  
-                $driver = new $driver($this->url, $this->io, $this->config);
  83
+                $driver = new $driver($this->repoConfig, $this->io, $this->config);
82 84
                 $driver->initialize();
83 85
 
84 86
                 return $driver;
24  tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php
@@ -77,7 +77,11 @@ public function testPrivateRepository()
77 77
             ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
78 78
             ->will($this->returnValue('{"master_branch": "test_master"}'));
79 79
 
80  
-        $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem);
  80
+        $repoConfig = array(
  81
+            'url' => $repoUrl,
  82
+        );
  83
+
  84
+        $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
81 85
         $gitHubDriver->initialize();
82 86
         $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
83 87
 
@@ -125,7 +129,11 @@ public function testPublicRepository()
125 129
             ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
126 130
             ->will($this->returnValue('{"master_branch": "test_master"}'));
127 131
 
128  
-        $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem);
  132
+        $repoConfig = array(
  133
+            'url' => $repoUrl,
  134
+        );
  135
+
  136
+        $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
129 137
         $gitHubDriver->initialize();
130 138
         $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
131 139
 
@@ -183,7 +191,11 @@ public function testPublicRepository2()
183 191
             ->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer/packagist/commits/feature%2F3.2-foo'), $this->equalTo(false))
184 192
             ->will($this->returnValue('{"commit": {"committer":{ "date": "2012-09-10"}}}'));
185 193
 
186  
-        $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem);
  194
+        $repoConfig = array(
  195
+            'url' => $repoUrl,
  196
+        );
  197
+
  198
+        $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
187 199
         $gitHubDriver->initialize();
188 200
         $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
189 201
 
@@ -271,7 +283,11 @@ public function testPrivateRepositoryNoInteraction()
271 283
             ->method('splitLines')
272 284
             ->will($this->returnValue(array('* test_master')));
273 285
 
274  
-        $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem);
  286
+        $repoConfig = array(
  287
+            'url' => $repoUrl,
  288
+        );
  289
+
  290
+        $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
275 291
         $gitHubDriver->initialize();
276 292
 
277 293
         $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());
6  tests/Composer/Test/Repository/Vcs/SvnDriverTest.php
@@ -45,7 +45,11 @@ public function testWrongCredentialsInUrl()
45 45
                 'home' => sys_get_temp_dir() . '/composer-test',
46 46
             ),
47 47
         ));
48  
-        $svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, $config, $process);
  48
+        $repoConfig = array(
  49
+            'url' => 'http://till:secret@corp.svn.local/repo',
  50
+        );
  51
+
  52
+        $svn = new SvnDriver($repoConfig, $console, $config, $process);
49 53
         $svn->initialize();
50 54
     }
51 55
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.