Bob Adams 5
Bob Adams 5

Reputation: 11

How to use the remote repository’s reference advertisement list in git2

In Rust's git2 library, there is a list function that returns a remote repositories reference advertisement list.

The resulting RemoteHead structs can return a name, oid, and loid, but how are these usable to determine what is point to by a reference? For example, are they all references to trees,blobs, commits? How do I then retrieve anything associated with those references?

Code snippet example to where I am stuck:

    let repo = Repository::open(".")?;
    // Value passed to function: url (&String)
    let remote = url;
    let mut remote = repo
        .find_remote(remote)
        .or_else(|_| repo.remote_anonymous(remote))?;

    // Connect to the remote and call the printing function for each of the
    // remote references.
    let connection = remote.connect_auth(Direction::Fetch, None, None)?;

    let mut retrieved_tags: Vec<String> = Vec::new();
    // Get the list of references on the remote and print out their name and oid
    for head in connection.list()?.iter() {
        println!("{}\t{}", head.oid(), head.name());
        if head.name().starts_with("refs/tags/") {
            retrieved_tags.push(head.name().to_string());
        }
    }

    // WHAT GOES HERE TO PULL DATA FROM REFERENCES, OR QUERY WHAT THEY ARE? 

I've been looking into fetchspecs since I'm not really familiar with git internals, but I can't find the exact method in git2 to work, or any methods that will give me more information on what the reference points to.

Upvotes: 1

Views: 46

Answers (0)

Related Questions