commit 8aa93786da2fe8d0c2714dcda5c6a0d4676b08c1 from: Stefan Sperling date: Thu Aug 22 16:04:32 2019 UTC make 'got cat' output look more like raw object files commit - 24ea5512e058a018fb480a73576e051ee37991ff commit + 8aa93786da2fe8d0c2714dcda5c6a0d4676b08c1 blob - fac5ad88780771915571b063b0545b79b3749db3 blob + 9c6dc3c63f0bc8ec9884129798772094865b8aad --- got/got.c +++ got/got.c @@ -6025,7 +6025,6 @@ cat_commit(struct got_object_id *id, struct got_reposi struct got_object_qid *pid; char *id_str = NULL; const char *logmsg = NULL; - int i; err = got_object_open_as_commit(&commit, repo, id); if (err) @@ -6035,31 +6034,28 @@ cat_commit(struct got_object_id *id, struct got_reposi if (err) goto done; - fprintf(outfile, "tree: %s\n", id_str); + fprintf(outfile, "%s%s\n", GOT_COMMIT_LABEL_TREE, id_str); parent_ids = got_object_commit_get_parent_ids(commit); - fprintf(outfile, "parents: %d\n", + fprintf(outfile, "numparents %d\n", got_object_commit_get_nparents(commit)); - i = 1; SIMPLEQ_FOREACH(pid, parent_ids, entry) { char *pid_str; err = got_object_id_str(&pid_str, pid->id); if (err) goto done; - fprintf(outfile, "parent %d: %s\n", i++, pid_str); + fprintf(outfile, "%s%s\n", GOT_COMMIT_LABEL_PARENT, pid_str); free(pid_str); } - fprintf(outfile, "author: %s\n", - got_object_commit_get_author(commit)); - fprintf(outfile, "author-time: %lld\n", + fprintf(outfile, "%s%s %lld +0000\n", GOT_COMMIT_LABEL_AUTHOR, + got_object_commit_get_author(commit), got_object_commit_get_author_time(commit)); - fprintf(outfile, "committer: %s\n", - got_object_commit_get_author(commit)); - fprintf(outfile, "committer-time: %lld\n", + fprintf(outfile, "%s%s %lld +0000\n", GOT_COMMIT_LABEL_COMMITTER, + got_object_commit_get_author(commit), got_object_commit_get_committer_time(commit)); logmsg = got_object_commit_get_logmsg_raw(commit); - fprintf(outfile, "log-message: %zd bytes\n", strlen(logmsg)); + fprintf(outfile, "messagelen %zd\n", strlen(logmsg)); fprintf(outfile, "%s", logmsg); done: free(id_str); @@ -6083,33 +6079,36 @@ cat_tag(struct got_object_id *id, struct got_repositor if (err) goto done; - fprintf(outfile, "tag-name: %s\n", got_object_tag_get_name(tag)); + fprintf(outfile, "%s%s\n", GOT_TAG_LABEL_TAG, + got_object_tag_get_name(tag)); switch (got_object_tag_get_object_type(tag)) { case GOT_OBJ_TYPE_BLOB: - fprintf(outfile, "tagged-object-type: blob\n"); + fprintf(outfile, "%s%s\n", GOT_TAG_LABEL_TYPE, + GOT_OBJ_LABEL_BLOB); break; case GOT_OBJ_TYPE_TREE: - fprintf(outfile, "tagged-object-type: tree\n"); + fprintf(outfile, "%s%s\n", GOT_TAG_LABEL_TYPE, + GOT_OBJ_LABEL_TREE); break; case GOT_OBJ_TYPE_COMMIT: - fprintf(outfile, "tagged-object-type: commit\n"); + fprintf(outfile, "%s%s\n", GOT_TAG_LABEL_TYPE, + GOT_OBJ_LABEL_COMMIT); break; case GOT_OBJ_TYPE_TAG: - fprintf(outfile, "tagged-object-type: tag\n"); + fprintf(outfile, "%s%s\n", GOT_TAG_LABEL_TYPE, + GOT_OBJ_LABEL_TAG); break; default: break; } - fprintf(outfile, "tagged-object: %s\n", id_str); + fprintf(outfile, "%s%s\n", GOT_TAG_LABEL_OBJECT, id_str); - fprintf(outfile, "tagger: %s\n", - got_object_tag_get_tagger(tag)); - fprintf(outfile, "tagger-time: %lld %lld\n", - got_object_tag_get_tagger_time(tag), - got_object_tag_get_tagger_gmtoff(tag)); + fprintf(outfile, "%s%s %lld +0000\n", GOT_TAG_LABEL_TAGGER, + got_object_tag_get_tagger(tag), + got_object_tag_get_tagger_time(tag)); tagmsg = got_object_tag_get_message(tag); - fprintf(outfile, "tag-message: %zd bytes\n", strlen(tagmsg)); + fprintf(outfile, "messagelen %zd\n", strlen(tagmsg)); fprintf(outfile, "%s", tagmsg); done: free(id_str); blob - 37d13aed45bc4261d0258d102a275f5808d73bc8 blob + b0bf900c64d3a893263960c80bff6c6e0e3ac6cb --- include/got_object.h +++ include/got_object.h @@ -57,6 +57,25 @@ void got_object_id_queue_free(struct got_object_id_que #define GOT_OBJ_TYPE_OFFSET_DELTA 6 #define GOT_OBJ_TYPE_REF_DELTA 7 +/* + * Labels used in object data. + */ + +#define GOT_OBJ_LABEL_COMMIT "commit" +#define GOT_OBJ_LABEL_TREE "tree" +#define GOT_OBJ_LABEL_BLOB "blob" +#define GOT_OBJ_LABEL_TAG "tag" + +#define GOT_COMMIT_LABEL_TREE "tree " +#define GOT_COMMIT_LABEL_PARENT "parent " +#define GOT_COMMIT_LABEL_AUTHOR "author " +#define GOT_COMMIT_LABEL_COMMITTER "committer " + +#define GOT_TAG_LABEL_OBJECT "object " +#define GOT_TAG_LABEL_TYPE "type " +#define GOT_TAG_LABEL_TAG "tag " +#define GOT_TAG_LABEL_TAGGER "tagger " + struct got_repository; /* blob - a69c3177ceaac290e56335f2ae5a77a248750f9a blob + f09d092331780e3ebd0811893a864ed717f20689 --- lib/got_lib_object.h +++ lib/got_lib_object.h @@ -75,21 +75,6 @@ struct got_tag_object { int refcnt; /* > 0 if open and/or cached */ }; -#define GOT_OBJ_LABEL_COMMIT "commit" -#define GOT_OBJ_LABEL_TREE "tree" -#define GOT_OBJ_LABEL_BLOB "blob" -#define GOT_OBJ_LABEL_TAG "tag" - -#define GOT_COMMIT_LABEL_TREE "tree " -#define GOT_COMMIT_LABEL_PARENT "parent " -#define GOT_COMMIT_LABEL_AUTHOR "author " -#define GOT_COMMIT_LABEL_COMMITTER "committer " - -#define GOT_TAG_LABEL_OBJECT "object " -#define GOT_TAG_LABEL_TYPE "type " -#define GOT_TAG_LABEL_TAG "tag " -#define GOT_TAG_LABEL_TAGGER "tagger " - struct got_object_id *got_object_get_id(struct got_object *); const struct got_error *got_object_get_id_str(char **, struct got_object *); const struct got_error *got_object_get_path(char **, struct got_object_id *, blob - 280f27add37a11d0725d6fa7e4cd893a6bb74c36 blob + ff28334685c4012d71ab8d57303196127b851018 --- regress/cmdline/cat.sh +++ regress/cmdline/cat.sh @@ -47,15 +47,13 @@ function test_cat_basic { fi # cat commit - echo -n "tree: " > $testroot/stdout.expected + echo -n "tree " > $testroot/stdout.expected git_show_tree $testroot/repo >> $testroot/stdout.expected echo >> $testroot/stdout.expected - echo "parents: 0" >> $testroot/stdout.expected - echo "author: $GOT_AUTHOR" >> $testroot/stdout.expected - echo "author-time: $author_time" >> $testroot/stdout.expected - echo "committer: Flan Hacker " >> $testroot/stdout.expected - echo "committer-time: $author_time" >> $testroot/stdout.expected - echo "log-message: 22 bytes" >> $testroot/stdout.expected + echo "numparents 0" >> $testroot/stdout.expected + echo "author $GOT_AUTHOR $author_time +0000" >> $testroot/stdout.expected + echo "committer Flan Hacker $author_time +0000" >> $testroot/stdout.expected + echo "messagelen 22" >> $testroot/stdout.expected printf "\nadding the test tree\n" >> $testroot/stdout.expected got cat -r $testroot/repo $commit_id > $testroot/stdout