#commit #git-commit #git-repository

bin+lib gitrevset

A domain-specific-language to select commits in a git repo. Similar to Mercurial's revset.

2 unstable releases

0.2.0 Oct 18, 2020
0.1.0 Sep 4, 2020

#108 in #commit

GPL-2.0-only

145KB
4K SLoC

gitrevset

Documentation Build Status

A domain-specific-language to select commits in a git repo. Similar to Mercurial's revset.

See the crate documentation for supported functions and operators. More functions might be added over time.

gitrevset provides the Rust library interface. There is also a simple command-line utility git-revs. It takes revset expressions as arguments, and outputs commit hashes.

Examples

Revset Expressions

The current commit (HEAD) and its parent:

. + .^

Merge base (common ancestor) of HEAD and origin/master:

gca(., origin/master)

The bottom of the current local (draft) branch:

roots(draft() & ::.)

Tagged commits since 100 days ago:

tag() & date("since 100 days ago")

Commits by "alice" or "bob" in the "dev" but not "master" branch:

(dev % master) & (author(alice) | author(bob))

Using gitrevset Library

Parse revset from a string at runtime. Execute it and iterate through the Oids:

use gitrevset::{Repo, SetExt};

let repo = Repo::open_from_env()?;
let set = repo.revs("(draft() & ::.)^ + .")?;
for oid in set.to_oids()? {
    dbg!(oid?)
}

Parse at compile time. Interact with local variables like strings, or calculated set:

use gitrevset::{ast, Repo};

let repo = Repo::open_from_env()?;
let master = "origin/master";
let stack = repo.revs(ast!(only(".", ref({ master }))))?;
let head = repo.revs(ast!(heads({ stack })))?;

Using git-revs CLI

git revs "(draft() & ::.)^ + ."

Configuration

Customized revset aliases or functions can be defined in git config:

[revsetalias]
d = draft()
f = ancestor($1, origin/master):$1

Then they can be used in git-revs or using the repo.anyrevs API.

git revs "f(d)"

Dependencies

~20–33MB
~552K SLoC