Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for revsets #175

Closed
arxanas opened this issue Oct 29, 2021 · 1 comment · Fixed by #398
Closed

Implement support for revsets #175

arxanas opened this issue Oct 29, 2021 · 1 comment · Fixed by #398
Labels
enhancement New feature or request

Comments

@arxanas
Copy link
Owner

arxanas commented Oct 29, 2021

See discussion at #157.

@arxanas arxanas added the enhancement New feature or request label Oct 29, 2021
@claytonrcarter
Copy link
Collaborator

This probably won't be helpful, but FWIW I hacked around a little bit last night was able to get this working w/ the following changes in dag.rs:

+use gitrevset::SetExt;

pub fn resolve_commits<'repo>(
    effects: &Effects,
    repo: &'repo Repo,
    dag: &mut Dag,
    hashes: Vec<String>,
) -> eyre::Result<ResolveCommitsResult<'repo>> {
    let mut commits = Vec::new();
+
+    // FIXME can we share the already opened git2::Repository from repo.inner?
+    let git_repo = git2::Repository::open(repo.get_path())?;
+    let revset_repo = gitrevset::Repo::open_from_repo(Box::new(git_repo))?;
+
    for hash in hashes {
-       let commit = match repo.revparse_single_commit(&hash)? {
+       let set = revset_repo.anyrevs(hash.as_str())?;
+
+       for oid in set.to_oids()? {
+           // FIXME yuck: oid -> to_string -> as_str ???
+           let commit = match repo.revparse_single_commit(oid?.to_string().as_str())? {
            let commit = match repo.revparse_single_commit(&hash)? {
                Some(commit) => commit,
                None => return Ok(ResolveCommitsResult::CommitNotFound { commit: hash }),
            };
            commits.push(commit)
        }
+    }

    let commit_oids = commits.iter().map(|commit| commit.get_oid()).collect_vec();
    dag.sync_from_oids(
        effects,
        repo,
        CommitSet::empty(),
        CommitSet::from_iter(commit_oids.into_iter().map(CommitVertex::from).map(Ok)),
    )?;
    Ok(ResolveCommitsResult::Ok { commits })
}

Not pretty and theres room for much improvement, but it was fun to play with and this was enough to get something like git hide 'desc("foo")' to actually work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants