···1919* Then aim for high performance
2020* Expect familiarity with Git internals
21212222-## Finding your way around
2323-2424-If you are working with a normal on-disk repository, start with
2525-`repository.Open(...)`. It opens the repository and wires together the refs
2626-storage, object storage, fetcher, (optional) commit-graph, commit queries, and
2727-reachability helpers. Note that it requires either a bare repository or a
2828-`.git` directory. Then,
2929-3030-* `repo.Refs()` is for branch names, tags, `HEAD`, and ref updates.
3131- * Use it when you are starting from names rather than object IDs.
3232- * A common pattern is to resolve a ref first, then pass the resulting object
3333- ID to the fetcher.
3434-3535-* `repo.Fetcher()` is the main object-facing API for most callers.
3636- * Use it when you want commits, trees, blobs, or tags as typed values.
3737- * It also handles peeling through annotated tags, resolving objects to the
3838- type you actually want, and walking paths inside trees.
3939- * It even allows you to access a tree as an `io/fs.FS`.
4040- * If your goal is "show me this commit", "read this tree", "follow this tag",
4141- or "get me the file at this path", this is usually the right layer.
4242-4343-* `repo.Objects()` is the storage layer underneath `Fetcher`.
4444- * Use it when you need to read object headers, read raw object contents,
4545- stream object data, or otherwise look up objects directly by ID.
4646- * Most callers who want to work with Git objects as commits, trees, blobs, or
4747- tags should prefer the fetcher instead.
4848- * However, checking an object ID's size and type are somewhat common
4949- operations that should be done here.
5050-5151-* `repo.CommitQueries()` is the main graph-query API.
5252- * Use it when you need ancestor checks or merge-base computation.
5353-5454-* `repo.Reachability()` is the graph-traversal API.
5555- * Use it when you need to walk reachable commits or objects, or to perform
5656- connectivity checks.
5757-5858-* `repo.CommitGraph()` exposes the low-level commit-graph reader.
5959- * Not all repositories have commit graphs, so it may be nil.
6060- * Most callers should prefer `repo.CommitQueries()` or `repo.Reachability()`
6161- unless they specifically need direct commit-graph access.
6262-6363-Note that:
6464-6565-* `object` contains parsed Git object values such as blobs, trees, commits, and
6666- tags. These are the decoded contents of Git objects and do not tell you
6767- anything about the object's identity.
6868-6969-* `object/stored` wraps a parsed object together with the object ID it was
7070- loaded from. This is used when you need both the parsed value and the
7171- identity it was loaded under.
7272-7373-As a rule of thumb:
7474-7575-* If you have a ref name, start with `repo.Refs()`.
7676-* If you want typed objects or path-based access, use `repo.Fetcher()`.
7777-* If you need raw object lookup by ID, object headers, or object streams, use
7878- `repo.Objects()`.
7979-* If you need ancestor checks or merge bases, use `repo.CommitQueries()`.
8080-* If you need commit or object graph traversal, use `repo.Reachability()`.
8181-8282-Some operations remain available if you want to work below those accessors:
8383-8484-* To accept pushes on the server side, construct `network/receivepack` or
8585- `network/receivepack/service` with the repository's ref store, object store,
8686- commit-graph reader, and object ID algorithm.
8787- * Push handling also needs the repository's object storage root so incoming
8888- objects can be quarantined and later promoted.
8989- * `Repository` does not currently expose that root directly (we'll consider
9090- possible solutions sometime later), so a push server usually keeps the
9191- repository path or object root handle alongside the `Repository` value.
9292- * Hook-based checks are just Go functions; for example, a fast-forward check
9393- can use `commitquery.Queries` over the existing and quarantined object
9494- stores. Some hooks are provided.
9595-9696-## Alternatives
9797-9898-Not endorsements.
9999-100100-* [github.com/go-git/go-git](https://github.com/go-git/go-git) (by far the most mature)
101101-* [github.com/driusan/dgit](https://github.com/driusan/dgit)
102102-* [github.com/Nivl/git-go](https://github.com/Nivl/git-go)
103103-* [github.com/unkn0wn-root/git-go.git](https://github.com/unkn0wn-root/git-go.git)
104104-* [github.com/speedata/gogit](https://github.com/speedata/gogit)
105105-10622## Community
1072310824* [#lindenii](https://webirc.runxiyu.org/kiwiirc/#lindenii)
···13349acceptance by the Designated Proxy of any subsequent version of the GNU Affero
13450General Public License shall permanently authorize the use of that accepted
13551version for this Program.
5252+5353+## Alternatives
5454+5555+Not endorsements.
5656+5757+* [github.com/go-git/go-git](https://github.com/go-git/go-git) (by far the most mature)
5858+* [github.com/driusan/dgit](https://github.com/driusan/dgit)
5959+* [github.com/Nivl/git-go](https://github.com/Nivl/git-go)
6060+* [github.com/unkn0wn-root/git-go.git](https://github.com/unkn0wn-root/git-go.git)
6161+* [github.com/speedata/gogit](https://github.com/speedata/gogit)
6262+