summaryrefslogtreecommitdiffstats
path: root/load-git.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-03-14 09:51:19 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-14 10:48:18 -0700
commit717f4ef102efcee479aa42678efe3d74b9cef9b2 (patch)
tree52811d28058773573cefb62d5556d9281418c388 /load-git.c
parent3fe0019bc2939aea4e89cbb8bc5aeb5edeb456d9 (diff)
downloadsubsurface-717f4ef102efcee479aa42678efe3d74b9cef9b2.tar.gz
git access: allow arbitrary revision specifiers on reading
Commit 13e2210d75bb ("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>
Diffstat (limited to 'load-git.c')
-rw-r--r--load-git.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/load-git.c b/load-git.c
index 12bf66141..c861799b4 100644
--- a/load-git.c
+++ b/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);