Commit e02e74afec955012935260a66e7710c537092c95

Stefan Sperling 2019-05-28T14:43:25

make it possible to pass reference names to 'got diff'

diff --git a/got/got.1 b/got/got.1
index f18db31..400c8b4 100644
--- a/got/got.1
+++ b/got/got.1
@@ -202,9 +202,9 @@ If a
 .Ar path
 is specified, only show changes within this path.
 .Pp
-If two arguments are provided, treat each argument as a SHA1 hash which
-corresponds to an object in the repository, and display differences
-between these objects.
+If two arguments are provided, treat each argument as a reference,
+or a SHA1 hash, which corresponds to an object in the repository,
+and display differences between these objects.
 Both objects must be of the same type (blobs, trees, or commits).
 .Pp
 The options for
diff --git a/got/got.c b/got/got.c
index 16eef00..98337ea 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1360,12 +1360,32 @@ cmd_diff(int argc, char *argv[])
 	}
 
 	error = got_object_resolve_id_str(&id1, repo, id_str1);
-	if (error)
-		goto done;
+	if (error) {
+		struct got_reference *ref;
+		if (error->code != GOT_ERR_BAD_OBJ_ID_STR)
+			goto done;
+		error = got_ref_open(&ref, repo, id_str1, 0);
+		if (error != NULL)
+			goto done;
+		error = got_ref_resolve(&id1, repo, ref);
+		got_ref_close(ref);
+		if (error != NULL)
+			goto done;
+	}
 
 	error = got_object_resolve_id_str(&id2, repo, id_str2);
-	if (error)
-		goto done;
+	if (error) {
+		struct got_reference *ref;
+		if (error->code != GOT_ERR_BAD_OBJ_ID_STR)
+			goto done;
+		error = got_ref_open(&ref, repo, id_str2, 0);
+		if (error != NULL)
+			goto done;
+		error = got_ref_resolve(&id2, repo, ref);
+		got_ref_close(ref);
+		if (error != NULL)
+			goto done;
+	}
 
 	error = got_object_get_type(&type1, repo, id1);
 	if (error)