pascalc/vcs

git/hg/svn命令的简单封装

0.5 2015-10-06 08:27 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:58:10 UTC


README

#vcs

PHP库,用于从Mozilla使用的各种版本控制系统(VCS)中轻松获取数据。

目前,它仅有的功能包括:

  • 通过svn|git|hg log命令从Subversion/Git/Mercurial存储库中提取提交数据,并以相同的结构返回这些数据(因此,从这些日志中提取的数据可以更容易地合并/比较)。
  • 在存储库上运行更新命令

###通过Composer安装

{
    "require": {
        "pascalc/vcs" : "dev-master"
    }
}

###使用示例

<?php
// Import classes in the current namespace
use VCS\Mercurial;
use VCS\Git;
use VCS\Subversion;

// Composer autoloading
require_once __DIR__ . '/vendor/autoload.php';

// Create objects for each repository we want to analyse
$hg  = new Mercurial('/path/to/hg/repo');
$git = new Git('/path/to/git/repo');
$svn = new Subversion('/path/to/svn/repo');

// Update local repos from remote server
$hg->update();
$git->update();
$svn->update();

// Dump all the commits extracted
var_dump($hg->getCommits());
var_dump($git->getCommits());
var_dump($svn->getCommits());

###数据以结构化数组的形式返回

[
    0 => [
        ['commit']  => (string) '116254',
        ['author']  => (string) 'Joe Bar',
        ['email']   => (string) 'joe@bar.com',
        ['date']    => (object) DateTime(),
        ['summary'] => (string) 'Commit summary field'
        ['vcs']     => (string) 'hg'
    ],
]

commit字段包含一个子版本修订号(116254)、一个简短的Mercurial更改集引用(1645:0be17cfdfdb1)或一个完整的Git sha1(dbf6cf2cdc9bf0ddc65e0b9b5fc330a90db6fc40)。

author字段包含提交者的姓名。对于Subversion,它与电子邮件相同,因为Subversion没有作者字段。

email字段是用于提交的电子邮件,如果电子邮件不在日志中(例如,通过工具推送),则此电子邮件为空。

date是提交日期,作为DateTime对象,所有存储库的格式相同。

summary是提交消息的第一行。

vcs是提交所进行的版本控制系统的类型。可能的值是svnhggit

请注意,由于Subversion是一个集中式VCS,它不保留任何本地历史记录,并且需要有效的互联网连接才能从远程服务器获取日志。因此,在无法建立连接的情况下,缓存这些数据是一个好主意,以避免过载远程Subversion服务器。