make it possible to pass reference names to 'got diff'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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)