Skip to content

Commit d2bc5ea

Browse files
committed
Rewrite the README around an example
The README opened on the drivers, then installing gitlib, before any code. It now starts with a line on what gitlib is, and an example reading a log, a diff and a blame, which runs as it is. Then what gitlib does, with links to the documentation, its site, the two drivers, how to install it, and the license.
1 parent ff02401 commit d2bc5ea

1 file changed

Lines changed: 67 additions & 58 deletions

File tree

‎README.md‎

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
1-
Gitlib for Gitonomy
2-
===================
1+
gitlib
2+
======
33

4-
This library provides methods to access Git repository from PHP 8.4+.
4+
Access git repositories from PHP 8.4+, through the `git` binary or libgit2.
55

6-
By default, it runs the `git` binary (1.8.4 or later) for every operation: convenient, and it
7-
doesn't need anything built to use. It can instead run [libgit2](https://libgit2.org/) in-process
8-
via PHP's `FFI` extension, an experimental driver which is faster for small reads but slower on
9-
long histories: see
10-
["Choosing a driver"](doc/repository.md#choosing-a-driver) and
11-
["Performance"](doc/repository.md#performance).
12-
13-
Quick Start
14-
-----------
6+
```php
7+
use Gitonomy\Git\Repository;
158

16-
You can install gitlib using [Composer](https://getcomposer.org/). Simply require the version you need:
9+
$repository = new Repository('/path/to/repository');
1710

18-
```bash
19-
$ composer require gitonomy/gitlib
20-
```
11+
// The last 5 commits of main that changed src/
12+
foreach ($repository->getLog('main', 'src', limit: 5) as $commit) {
13+
echo $commit->getShortHash().' '.$commit->getSubjectMessage().PHP_EOL;
14+
}
2115

22-
or edit your `composer.json` file by hand:
16+
// The files the last commit changed
17+
foreach ($repository->getHeadCommit()->getDiff()->getFiles() as $file) {
18+
echo $file->getName().': +'.$file->getAdditions().' -'.$file->getDeletions().PHP_EOL;
19+
}
2320

24-
```json
25-
{
26-
"require": {
27-
"gitonomy/gitlib": "^2.0"
28-
}
21+
// Who wrote the first lines of README.md
22+
foreach ($repository->getBlame('main', 'README.md', 1, 3)->getLines() as $line) {
23+
echo $line->getCommit()->getAuthorName().': '.$line->getContent().PHP_EOL;
2924
}
3025
```
3126

32-
Upgrading from 1.x? Read [UPGRADE-2.0.md](UPGRADE-2.0.md).
33-
34-
Example Usage
35-
-------------
36-
37-
```php
38-
<?php
39-
40-
use Gitonomy\Git\Repository;
27+
The documentation is at **[gitonomy.github.io/gitlib](https://gitonomy.github.io/gitlib/)**.
4128

42-
$repository = new Repository('/path/to/repository');
29+
What it does
30+
------------
4331

44-
foreach ($repository->getReferences()->getBranches() as $branch) {
45-
echo '- '.$branch->getName().PHP_EOL;
46-
}
32+
- **Open** a bare repository, a working tree, a linked worktree or a submodule, or
33+
**create** one: init, clone, mirror. See [Opening a repository](doc/repository.md) and
34+
[Creating repositories](doc/admin.md).
35+
- **Read** commits, logs, trees, blobs, diffs, blames, branches and tags, as PHP objects.
36+
- **Change** the working copy: checkout, new branches, merges, and the diffs of what is
37+
pending or staged. See [Working copy](doc/workingcopy.md).
38+
- **Manage** the hooks of a repository: see [Hooks](doc/hooks.md).
39+
- **Run** any other git command: see
40+
[Running git commands](doc/repository.md#running-git-commands).
4741

48-
echo $repository->getHeadCommit()->getSubjectMessage().PHP_EOL;
42+
Two drivers
43+
-----------
4944

50-
// Any git command, with the default driver only
51-
$repository->run('fetch', ['--all']);
52-
```
45+
`Repository` runs git through a driver, its last argument:
5346

54-
The last argument of `Repository` is the driver running git. It is `CliDriver`, which runs the
55-
`git` binary, by default. To run libgit2 instead, pass a `LibGit2Driver`: everything above works
56-
the same, except `run()`, which needs the `git` binary.
47+
- `CliDriver`, the default, runs the `git` binary, 1.8.4 or later, and needs nothing else;
48+
- `LibGit2Driver`, experimental, runs [libgit2](https://libgit2.org/) 1.9 in-process, through
49+
PHP's `FFI` extension. It is faster for many small reads in a long-running process, and
50+
slower on long histories, like blames: see
51+
["Choosing a driver"](doc/repository.md#choosing-a-driver).
5752

5853
```php
5954
use Gitonomy\Git\Driver\Ffi\LibGit2Driver;
@@ -62,26 +57,40 @@ use Gitonomy\Git\Repository;
6257
$repository = new Repository('/path/to/repository', driver: new LibGit2Driver());
6358
```
6459

65-
API Documentation
66-
-----------------
67-
68-
+ [Blame](doc/blame.md)
69-
+ [Blob](doc/blob.md)
70-
+ [Branch](doc/branch.md)
71-
+ [Commit](doc/commit.md)
72-
+ [Creating repositories](doc/admin.md)
73-
+ [Diff](doc/diff.md)
74-
+ [Hooks](doc/hooks.md)
75-
+ [Log](doc/log.md)
76-
+ [References](doc/references.md)
77-
+ [Repository](doc/repository.md): opening a repository, drivers, errors
78-
+ [Revision](doc/revision.md)
79-
+ [Tree](doc/tree.md)
80-
+ [Working Copy](doc/workingcopy.md)
60+
Installation
61+
------------
62+
63+
```bash
64+
composer require gitonomy/gitlib
65+
```
66+
67+
Upgrading from 1.x? Read [UPGRADE-2.0.md](UPGRADE-2.0.md) and the [changelog](CHANGELOG.md).
68+
69+
Documentation
70+
-------------
71+
72+
- [Opening a repository](doc/repository.md): paths, drivers, errors, git configuration
73+
- [Creating repositories](doc/admin.md)
74+
- [Revisions](doc/revision.md)
75+
- [Commits](doc/commit.md)
76+
- [Log](doc/log.md)
77+
- [Trees](doc/tree.md)
78+
- [Blobs](doc/blob.md)
79+
- [Diffs](doc/diff.md)
80+
- [Blame](doc/blame.md)
81+
- [Tags and branches](doc/references.md)
82+
- [Branches](doc/branch.md)
83+
- [Working copy](doc/workingcopy.md)
84+
- [Hooks](doc/hooks.md)
8185

8286
For Enterprise
8387
--------------
8488

8589
Available as part of the Tidelift Subscription
8690

8791
The maintainers of `gitonomy/gitlib` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-gitonomy-gitlib?utm_source=packagist-gitonomy-gitlib&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
92+
93+
License
94+
-------
95+
96+
gitlib is released under the [MIT license](https://github.com/gitonomy/gitlib/blob/main/LICENSE).

0 commit comments

Comments
 (0)