commit d24820bf831196d55a112663501e8e67ac79911c from: Stefan Sperling date: Sun Aug 11 19:19:14 2019 UTC add support for tag objects to 'got diff' commit - 0adb71964c3ec56241e7a6600b8ee8c20097cb85 commit + d24820bf831196d55a112663501e8e67ac79911c blob - d79284e1499b9086363020eab8ccd8444815bb32 blob + 107ba1a8a7eae7b928b47ce2fc6d87aa0df0f383 --- got/got.1 +++ got/got.1 @@ -332,8 +332,9 @@ If a .Ar path is specified, only show changes within this path. .Pp -If two arguments are provided, treat each argument as a reference, -or an object ID SHA1 hash, and display differences between these objects. +If two arguments are provided, treat each argument as a reference, a tag +name, or an object ID SHA1 hash, and display differences between the +corresponding objects. Both objects must be of the same type (blobs, trees, or commits). An abbreviated hash argument will be expanded to a full SHA1 hash automatically, provided the abbreviation is unique. blob - 6303aab4047a2dd1d93962a67a7ddc198a481671 blob + 02fe06d3bbf4fbb43366d95c9fadaab51208aba1 --- got/got.c +++ got/got.c @@ -1858,10 +1858,24 @@ match_object_id(struct got_object_id **id, char **labe const char *id_str, int obj_type, struct got_repository *repo) { const struct got_error *err; + struct got_tag_object *tag; struct got_reference *ref = NULL; *id = NULL; *label = NULL; + + err = got_repo_object_match_tag(&tag, id_str, GOT_OBJ_TYPE_ANY, repo); + if (err == NULL) { + *id = got_object_id_dup(got_object_tag_get_object_id(tag)); + if (*id == NULL) + err = got_error_from_errno("got_object_id_dup"); + if (asprintf(label, "refs/tags/%s", + strdup(got_object_tag_get_name(tag))) == -1) + err = got_error_from_errno("asprintf"); + got_object_tag_close(tag); + return err; + } else if (err->code != GOT_ERR_NO_OBJ) + return err; err = got_repo_match_object_id_prefix(id, id_str, obj_type, repo); if (err) { blob - 5e46d49dc5d829ba1d253df00d650c7dae466bbe blob + 505fd64b4138ac8c0f740dfc79384bdfb668fb49 --- include/got_object.h +++ include/got_object.h @@ -221,6 +221,9 @@ const struct got_error *got_object_open_as_tag(struct /* Dispose of a tag object. */ void got_object_tag_close(struct got_tag_object *); +/* Get the name of a tag. */ +const char *got_object_tag_get_name(struct got_tag_object *); + /* Get type of the object a tag points to. */ int got_object_tag_get_object_type(struct got_tag_object *); blob - d247b0992efbf07b2fd9eef08e34004c0ae0fbc3 blob + 42e0035977023ee76bd78dbd06474f29da5c19c5 --- lib/object.c +++ lib/object.c @@ -1354,6 +1354,12 @@ got_object_tag_open(struct got_tag_object **tag, struct got_repository *repo, struct got_object *obj) { return open_tag(tag, repo, got_object_get_id(obj), 1); +} + +const char * +got_object_tag_get_name(struct got_tag_object *tag) +{ + return tag->tag; } int blob - 60e8e27f0ead8fbd0ef767acaaa4a7618826a10d blob + 293708998a14514dfef24428b4aa26e8e2c97ffc --- lib/repository.c +++ lib/repository.c @@ -1147,7 +1147,8 @@ got_repo_object_match_tag(struct got_tag_object **tag, free(tag_id); if (err) break; - if (got_object_tag_get_object_type(*tag) == obj_type) + if (obj_type == GOT_OBJ_TYPE_ANY || + got_object_tag_get_object_type(*tag) == obj_type) break; got_object_tag_close(*tag); *tag = NULL; blob - 9193624ff0a715ee9b6277aa6ffaa68cbcd8f4de blob + e7cea61d9e58dea9e040440ecd3b58e1fd85df0e --- regress/cmdline/diff.sh +++ regress/cmdline/diff.sh @@ -136,5 +136,66 @@ function test_diff_shows_conflict { test_done "$testroot" "$ret" } +function test_diff_tag { + local testroot=`test_init diff_tag` + local commit_id0=`git_show_head $testroot/repo` + local tag1=1.0.0 + local tag2=2.0.0 + + echo "modified alpha" > $testroot/repo/alpha + git_commit $testroot/repo -m "changed alpha" + local commit_id1=`git_show_head $testroot/repo` + + (cd $testroot/repo && git tag -m "test" $tag1) + + echo "new file" > $testroot/repo/new + (cd $testroot/repo && git add new) + git_commit $testroot/repo -m "new file" + local commit_id2=`git_show_head $testroot/repo` + + (cd $testroot/repo && git tag -m "test" $tag2) + + echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected + echo -n 'blob - ' >> $testroot/stdout.expected + got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \ + cut -d' ' -f 1 >> $testroot/stdout.expected + echo -n 'blob + ' >> $testroot/stdout.expected + got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \ + >> $testroot/stdout.expected + echo '--- alpha' >> $testroot/stdout.expected + echo '+++ alpha' >> $testroot/stdout.expected + echo '@@ -1 +1 @@' >> $testroot/stdout.expected + echo '-alpha' >> $testroot/stdout.expected + echo '+modified alpha' >> $testroot/stdout.expected + + got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected + echo "blob - /dev/null" >> $testroot/stdout.expected + echo -n 'blob + ' >> $testroot/stdout.expected + got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \ + cut -d' ' -f 1 >> $testroot/stdout.expected + echo '--- /dev/null' >> $testroot/stdout.expected + echo '+++ new' >> $testroot/stdout.expected + echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected + echo '+new file' >> $testroot/stdout.expected + + got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + run_test test_diff_basic run_test test_diff_shows_conflict +run_test test_diff_tag