mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
git access: allow arbitrary revision specifiers on reading
Commit 13e2210d75
("Allow remote branch names when reading a git
object tree") made it possible to read (but not write) remote branches,
which is very convenient when you just want to look at somebody elses
dives in a shared repository.
However, it was really quite stupidly done - both overly complicated,
and overly restrictive.
It's much better and simpler to just allow general git revision
specifications, which includes branches (both remote and local) as a
simple case, but also allows general git revision expressions. So you
can tag things, and use a tag-name instead. Or you can say that you
want to look at the previous save, by using the "branchname^" syntax.
Or, you can use the git reflog, and do things like
subsurface ~/scuba/[linus@{two.days.ago}]
to see the dives that your repository contained two days ago.
Obviously, you will not be able to save to this kind of ref-spec (and I
really will have to make error handling work better), but for browsing
state it's quite useful.
And in git terms, this is actually simpler than the "lets try to first
see if we have a local branch of that name, and then if we have a remote
one", as shown by the fact that this removes more lines than it adds.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3fe0019bc2
commit
717f4ef102
1 changed files with 5 additions and 9 deletions
14
load-git.c
14
load-git.c
|
@ -1216,18 +1216,14 @@ void set_git_id(const struct git_oid * id)
|
|||
static int do_git_load(git_repository *repo, const char *branch)
|
||||
{
|
||||
int ret;
|
||||
git_reference *ref;
|
||||
git_object *object;
|
||||
git_commit *commit;
|
||||
git_tree *tree;
|
||||
|
||||
ret = git_branch_lookup(&ref, repo, branch, GIT_BRANCH_LOCAL);
|
||||
if (ret) {
|
||||
ret = git_branch_lookup(&ref, repo, branch, GIT_BRANCH_REMOTE);
|
||||
if (ret)
|
||||
return report_error("Unable to look up branch '%s'", branch);
|
||||
}
|
||||
if (git_reference_peel((git_object **)&commit, ref, GIT_OBJ_COMMIT))
|
||||
return report_error("Could not look up commit of branch '%s'", branch);
|
||||
if (git_revparse_single(&object, repo, branch))
|
||||
return report_error("Unable to look up revision '%s'", branch);
|
||||
if (git_object_peel((git_object **)&commit, object, GIT_OBJ_COMMIT))
|
||||
return report_error("Revision '%s' is not a valid commit", branch);
|
||||
if (git_commit_tree(&tree, commit))
|
||||
return report_error("Could not look up tree of commit in branch '%s'", branch);
|
||||
ret = load_dives_from_tree(repo, tree);
|
||||
|
|
Loading…
Reference in a new issue