make 'got cat' output look more like raw object files
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
diff --git a/got/got.c b/got/got.c
index fac5ad8..9c6dc3c 100644
--- a/got/got.c
+++ b/got/got.c
@@ -6025,7 +6025,6 @@ cat_commit(struct got_object_id *id, struct got_repository *repo, FILE *outfile)
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_repository *repo, FILE *outfile)
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_repository *repo, FILE *outfile)
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);
diff --git a/include/got_object.h b/include/got_object.h
index 37d13ae..b0bf900 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -57,6 +57,25 @@ void got_object_id_queue_free(struct got_object_id_queue *);
#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;
/*
diff --git a/lib/got_lib_object.h b/lib/got_lib_object.h
index a69c317..f09d092 100644
--- a/lib/got_lib_object.h
+++ b/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 *,
diff --git a/regress/cmdline/cat.sh b/regress/cmdline/cat.sh
index 280f27a..ff28334 100755
--- a/regress/cmdline/cat.sh
+++ b/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 <flan_hacker@openbsd.org>" >> $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 <flan_hacker@openbsd.org> $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