[PATCH] git access: allow arbitrary revision specifiers on reading

Linus Torvalds torvalds at linux-foundation.org
Fri Mar 14 10:02:41 PDT 2014


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Fri, 14 Mar 2014 09:51:19 -0700
Subject: [PATCH] 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 at linux-foundation.org>
---
 load-git.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/load-git.c b/load-git.c
index 12bf66141e88..c861799b469b 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);
-- 
1.9.0



More information about the subsurface mailing list