Revspec Repository::revparse(const char * spec) const { git_revspec revspec; if (git_revparse(&revspec, repo_, spec)) throw revparse_error(spec); return Revspec(revspec, *this); }
static int parse_revision(struct parse_state *ps, const char *revstr) { git_revspec rs; char str[GIT_OID_HEXSZ + 1]; if (!ps->repo) { if (!ps->repodir) ps->repodir = "."; check(git_repository_open_ext(&ps->repo, ps->repodir, 0, NULL), "Could not open repository from", ps->repodir); } check(git_revparse(&rs, ps->repo, revstr), "Could not parse", revstr); if ((rs.flags & GIT_REVPARSE_SINGLE) != 0) { git_oid_tostr(str, sizeof(str), git_object_id(rs.from)); printf("%s\n", str); git_object_free(rs.from); } else if ((rs.flags & GIT_REVPARSE_RANGE) != 0) { git_oid_tostr(str, sizeof(str), git_object_id(rs.to)); printf("%s\n", str); git_object_free(rs.to); if ((rs.flags & GIT_REVPARSE_MERGE_BASE) != 0) { git_oid base; check(git_merge_base(&base, ps->repo, git_object_id(rs.from), git_object_id(rs.to)), "Could not find merge base", revstr); git_oid_tostr(str, sizeof(str), &base); printf("%s\n", str); } git_oid_tostr(str, sizeof(str), git_object_id(rs.from)); printf("^%s\n", str); git_object_free(rs.from); } else { check(0, "Invalid results from git_revparse", revstr); } return 0; }
static int push_range(git_repository *repo, git_revwalk *walk, const char *range, int hide) { git_revspec revspec; int error = 0; if ((error = git_revparse(&revspec, repo, range))) return error; if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { /* TODO: support "<commit>...<commit>" */ return GIT_EINVALIDSPEC; } if ((error = push_commit(walk, git_object_id(revspec.from), !hide))) goto out; error = push_commit(walk, git_object_id(revspec.to), hide); out: git_object_free(revspec.from); git_object_free(revspec.to); return error; }
int git_revwalk_push_range(git_revwalk *walk, const char *range) { git_revspec revspec; int error = 0; if ((error = git_revparse(&revspec, walk->repo, range))) return error; if (revspec.flags & GIT_REVPARSE_MERGE_BASE) { /* TODO: support "<commit>...<commit>" */ giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk"); return GIT_EINVALIDSPEC; } if ((error = push_commit(walk, git_object_id(revspec.from), 1, false))) goto out; error = push_commit(walk, git_object_id(revspec.to), 0, false); out: git_object_free(revspec.from); git_object_free(revspec.to); return error; }