Skip to content

quark-zju/gitrevset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)"

Releases

No releases published

Packages

No packages published