瀏覽代碼

Merge branch 'master' of https://github.com/composer/packagist into autoload

* 'master' of https://github.com/composer/packagist:
  Update phar
  Bugfix
  Updated composer.phar
  Update About page for new changes
  Cleanup
  Update package parsing rules, added auto-versioning
  Add --force option for pkg:update
  Updated vendors
  Use sha1 for branches instead of names, fixes #39
Igor Wiedler 13 年之前
父節點
當前提交
aa6491c79e

+ 2 - 2
deps

@@ -1,10 +1,10 @@
 [symfony]
     git=http://github.com/symfony/symfony.git
-    version=v2.0.3
+    version=v2.0.4
 
 [twig]
     git=http://github.com/fabpot/Twig.git
-    version=v1.1.2
+    version=v1.3.0
 
 [monolog]
     git=http://github.com/Seldaek/monolog.git

+ 3 - 3
deps.lock

@@ -1,5 +1,5 @@
-symfony 6a25df0ebf92074bf541fc7ca53d9fcd27981c3d
-twig 396435ecd05556adb0a8bd05b14641cb4f8a8aa5
+symfony 1f2e72d84aa9a4829185d6b2a0b814f6b933b30a
+twig 4b929992df65808f36e8f93f87fa66a9fce03629
 monolog 303b8a83c87d5c6d749926cf02620465a5dcd0f2
 doctrine-common b385ca770888248241bd3086a40d5b3bd082a706
 doctrine-dbal e0b69790ab1ffd646fd70a04fdb91e5dfbb3ccf1
@@ -8,7 +8,7 @@ swiftmailer 8c3165691e36302405926abbae7526549db8b899
 assetic f829ad23d23c87480151a21faad49fefe7c09e5d
 twig-extensions eba4f5d572bec05c72a47bbd73ba0a3330cf8f54
 metadata 8717ad2a5689480765d9ffafe925cd8a2457e582
-composer da6566b3438f4fcfa4d4eae05519fc9ae2e7eb63
+composer 19f89069a4dddf65888f6779774b540244e0ffbf
 SensioFrameworkExtraBundle 9b9194a47effc66b08d44ae110b982352119ca17
 JMSSecurityExtraBundle b8b7eb294ed83d83ca7260ac018e701f08003538
 SensioDistributionBundle 2082cb99d408fd89243059c6eff866347ec00bbe

+ 52 - 22
src/Packagist/WebBundle/Command/UpdatePackagesCommand.php

@@ -49,6 +49,7 @@ class UpdatePackagesCommand extends ContainerAwareCommand
         $this
             ->setName('pkg:update')
             ->setDefinition(array(
+                new InputOption('force', null, InputOption::VALUE_NONE, 'Force a re-crawl of all packages'),
             ))
             ->setDescription('Updates packages')
             ->setHelp(<<<EOF
@@ -64,6 +65,7 @@ EOF
     protected function execute(InputInterface $input, OutputInterface $output)
     {
         $verbose = $input->getOption('verbose');
+        $force = $input->getOption('force');
         $doctrine = $this->getContainer()->get('doctrine');
 
         $logger = $this->getContainer()->get('logger');
@@ -71,7 +73,11 @@ EOF
 
         $this->versionParser = new VersionParser;
 
-        $packages = $doctrine->getRepository('PackagistWebBundle:Package')->getStalePackages();
+        if ($force) {
+            $packages = $doctrine->getRepository('PackagistWebBundle:Package')->findAll();
+        } else {
+            $packages = $doctrine->getRepository('PackagistWebBundle:Package')->getStalePackages();
+        }
 
         foreach ($packages as $package) {
             $repository = $provider->getRepository($package->getRepository());
@@ -87,38 +93,57 @@ EOF
 
             try {
                 foreach ($repository->getTags() as $tag => $identifier) {
-                    if ($repository->hasComposerFile($identifier) && $this->validateTag($tag)) {
+                    if ($repository->hasComposerFile($identifier) && $parsedTag = $this->validateTag($tag)) {
                         $data = $repository->getComposerInformation($identifier);
-                        $data['version_normalized'] = $this->versionParser->normalize($data['version']);
-                        // Strip -dev that could have been left over accidentally in a tag
-                        $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
+
+                        // manually versioned package
+                        if (isset($data['version'])) {
+                            $data['version_normalized'] = $this->versionParser->normalize($data['version']);
+                            if ($data['version_normalized'] !== $parsedTag) {
+                                // broken package, version doesn't match tag
+                                continue;
+                            }
+                        } else {
+                            // auto-versionned package, read value from tag
+                            $data['version'] = preg_replace('{[.-]?dev$}i', '', $tag);
+                            $data['version_normalized'] = preg_replace('{[.-]?dev$}i', '', $parsedTag);
+                        }
                         $this->updateInformation($output, $doctrine, $package, $repository, $identifier, $data);
                         $doctrine->getEntityManager()->flush();
                     }
                 }
 
                 foreach ($repository->getBranches() as $branch => $identifier) {
-                    if ($repository->hasComposerFile($identifier) && $this->validateBranch($branch)) {
+                    if ($repository->hasComposerFile($identifier) && $parsedBranch = $this->validateBranch($branch)) {
                         $data = $repository->getComposerInformation($identifier);
-                        $data['version_normalized'] = $this->versionParser->normalize($data['version']);
 
-                        // Skip branches that contain a version that's been tagged already
+                        // manually versioned package
+                        if (isset($data['version'])) {
+                            $data['version_normalized'] = $this->versionParser->normalize($data['version']);
+                        } else {
+                            // auto-versionned package, read value from branch name
+                            $data['version'] = $branch;
+                            $data['version_normalized'] = $parsedBranch;
+                        }
+
+                        // make sure branch packages have a -dev flag
+                        $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']) . '-dev';
+                        $data['version_normalized'] = preg_replace('{[.-]?dev$}i', '', $data['version_normalized']) . '-dev';
+
+                        // Skip branches that contain a version that has been tagged already
                         foreach ($package->getVersions() as $existingVersion) {
                             if ($data['version_normalized'] === $existingVersion->getNormalizedVersion() && !$existingVersion->getDevelopment()) {
                                 continue;
                             }
                         }
 
-                        // Force branches to use -dev releases
-                        if (!preg_match('{[.-]?dev$}i', $data['version'])) {
-                            $data['version'] .= '-dev';
-                        }
-
                         $this->updateInformation($output, $doctrine, $package, $repository, $identifier, $data);
                         $doctrine->getEntityManager()->flush();
                     }
                 }
 
+                // TODO -dev versions that were not updated should be deleted
+
                 $package->setUpdatedAt(new \DateTime);
                 $package->setCrawledAt(new \DateTime);
                 $doctrine->getEntityManager()->flush();
@@ -131,18 +156,17 @@ EOF
 
     private function validateBranch($branch)
     {
-        if (in_array($branch, array('master', 'trunk'))) {
-            return true;
+        try {
+            return $this->versionParser->normalizeBranch($branch);
+        } catch (\Exception $e) {
+            return false;
         }
-
-        return (Boolean) preg_match('#^v?(\d+)(\.(?:\d+|[x*]))?(\.(?:\d+|[x*]))?(\.[x*])?$#i', $branch, $matches);
     }
 
     private function validateTag($version)
     {
         try {
-            $this->versionParser->normalize($version);
-            return true;
+            return $this->versionParser->normalize($version);
         } catch (\Exception $e) {
             return false;
         }
@@ -154,9 +178,7 @@ EOF
         $version = new Version();
 
         $version->setName($package->getName());
-        $version->setVersion($data['version']);
-        $version->setNormalizedVersion($data['version_normalized']);
-        $version->setDevelopment(substr($data['version'], -4) === '-dev');
+        $version->setNormalizedVersion(preg_replace('{-dev$}i', '', $data['version_normalized']));
 
         // check if we have that version yet
         foreach ($package->getVersions() as $existingVersion) {
@@ -169,9 +191,13 @@ EOF
             }
         }
 
+        $version->setVersion($data['version']);
+        $version->setDevelopment(substr($data['version_normalized'], -4) === '-dev');
+
         $em->persist($version);
 
         $version->setDescription($data['description']);
+        $package->setDescription($data['description']);
         $version->setHomepage($data['homepage']);
         $version->setLicense(is_array($data['license']) ? $data['license'] : array($data['license']));
 
@@ -259,5 +285,9 @@ EOF
                 }
             }
         }
+
+        if (!$package->getVersions()->contains($version)) {
+            $package->addVersions($version);
+        }
     }
 }

+ 0 - 1
src/Packagist/WebBundle/Entity/Package.php

@@ -106,7 +106,6 @@ class Package
         $data = array(
             'name' => $this->getName(),
             'description' => $this->getDescription(),
-            'dist-tags' => array(),
             'maintainers' => $maintainers,
             'versions' => $versions,
             'type' => $this->getType(),

+ 1 - 1
src/Packagist/WebBundle/Entity/Version.php

@@ -230,7 +230,7 @@ class Version
     public function equals(Version $version)
     {
         return strtolower($version->getName()) === strtolower($this->getName())
-            && $version->getNormalizedVersion() === $this->getNormalizedVersion();
+            && strtolower($version->getNormalizedVersion()) === strtolower($this->getNormalizedVersion());
     }
 
     /**

+ 1 - 1
src/Packagist/WebBundle/Repository/Repository/GitHubRepository.php

@@ -60,7 +60,7 @@ class GitHubRepository implements RepositoryInterface
         $attempts = 3;
 
         while ($attempts--) {
-            $label = array_search($identifier, (array) $this->tags) ?: array_search($identifier, (array) $this->branches) ?: $identifier;
+            $label = array_search($identifier, (array) $this->tags) ?: $identifier;
             $url = 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$label;
             if (!$checksum = @hash_file('sha1', $url)) {
                 continue;

+ 11 - 6
src/Packagist/WebBundle/Resources/views/About/about.html.twig

@@ -35,7 +35,6 @@ acme/email
     "description": "Logging for PHP 5.3",
     "keywords": ["log","logging"],
     "homepage": "http://github.com/Seldaek/monolog",
-    "version": "1.0.0",
     "license": "MIT",
     "authors": [
         {
@@ -49,26 +48,32 @@ acme/email
     }
 }
 </pre>
-Most of this information is obvious, keywords are tags, require are list of dependencies that your package has. This can of course be packages, not only a php version. You can use ext/foo to require php extensions (e.g. ext/apc). Note that most extensions don't expose version information, so unless you know for sure it does, it's safer to use <code>"ext-apc": "*"</code> to allow any version of it. Finally the type field is in this case indicating that this is a library. If you do plugins for frameworks etc, and if they integrate composer, they may have a custom package type for their plugins that you can use to install the package with their own installer. In the absence of custom type, you can omit it or use "library".</p>
+Most of this information is obvious, keywords are tags, require are list of dependencies that your package has. This can of course be packages, not only a php version. You can use ext-foo to require php extensions (e.g. ext-apc). Note that most extensions don't expose version information, so unless you know for sure it does, it's safer to use <code>"ext-apc": "*"</code> to allow any version of it. Finally the type field is in this case indicating that this is a library. If you do plugins for frameworks etc, and if they integrate composer, they may have a custom package type for their plugins that you can use to install the package with their own installer. In the absence of custom type, you can omit it or use "library".</p>
     <p>Known package types include: symfony-bundle</p>
     <p>Once you have this file committed in your repository root, you can <a href="{{ path('submit') }}">submit the package</a> to Packagist by entering the public repository URL.</p>
+
     <h1>Managing package versions</h1>
-    <p>New versions of your package are automatically fetched from tags you create in your repository. You should update the version field in the composer.json file before creating a tag. Tag/version names should match 'X.Y.Z', or 'vX.Y.Z', with an optional suffix for RC, beta, alpha or patch versions. Here are a few examples of valid tag names:
+    <p>New versions of your package are automatically fetched from tags you create in your VCS repository.</p>
+    <p>There are two ways to manage version numbering. The easiest is to just omit the version field from the composer.json file. If it is missing, the version name will be parsed from the tag and branch names. The other way which offers you a bit more flexibility is to define it yourself, but that means you should update the version field in the composer.json file before creating a tag, otherwise the tag will be considered broken and not imported. If you think you're likely to forget, you probably should use the first method.</p>
+    <p>Tag/version names should match 'X.Y.Z', or 'vX.Y.Z', with an optional suffix for RC, beta, alpha or patch versions. Here are a few examples of valid tag names:
 <pre>
 1.0.0
 v1.0.0
 1.10.5-RC1
 v4.4.4beta2
 v2.0.0-alpha
+v2.0.4-p1
 </pre>
-    In your master branch, or any other dev branch, you should change the composer.json version to the next future version that will be released from this branch (e.g. <code>1.1.0</code>), packagist will automatically suffix -dev to it until it is moved to a tag.</p>
+    With manual versioning, in your master branch, or any other dev branch, you should change the composer.json version to the next future version that will be released from this branch (e.g. <code>1.1.0</code>), packagist will automatically add a -dev suffix to it until it is moved to a tag.</p>
     <p>Note that dev branches should follow one of the following patterns to be recognized:
 <pre>
+master
+trunk
 1.0
 1.*
 v1.x
-1.x.x
-1.*.*
+1.1.x
+1.1.*
 </pre>
     Doing so will allow people to easily install pre-release versions of your code for testing or development purposes.</p>
 {% endblock %}

二進制
web/get/composer.phar