commit: 837f35b2e25c7188e8bdbfb6177f0605ca38fb93
parent fd84696f5ec4eeaeba5a1927df573358835123d7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 23 Oct 2025 03:19:38 +0200
tags.xml: write tag message instead of commit message
Diffstat:
| M | stagit.c | 75 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ |
1 file changed, 63 insertions(+), 12 deletions(-)
diff --git a/stagit.c b/stagit.c
@@ -911,6 +911,65 @@ printcommitatom(FILE *fp, struct commitinfo *ci, const char *tag)
fputs("\n</content>\n</entry>\n", fp);
}
+static int
+tag_foreach_cb(const char *name, git_oid *oid, void *payload)
+{
+ FILE *fp = (FILE *)payload;
+
+ git_tag *tag = NULL;
+ int r = git_tag_lookup(&tag, repo, oid);
+ if(r != 0)
+ {
+ char *oid_str = git_oid_tostr_s(oid);
+ fprintf(stderr, "stagit: error: Failed looking up tag '%s' (id '%s'), got error code %d\n", name, oid_str, r);
+ return 0;
+ }
+
+ git_object_t tag_type = git_tag_target_type(tag);
+ /* skip non-annotated tags */
+ if(!(tag_type == GIT_OBJECT_TAG || tag_type == GIT_OBJECT_COMMIT))
+ {
+ fprintf(stderr, "stagit: info: Tag '%s' isn't an annotated tag (got type: %d), skipping\n", name, tag_type);
+ return 0;
+ }
+
+ fputs("<entry>\n", fp);
+
+ /* commit-id because stagit originally used those */
+ const git_oid *target_oid = git_tag_target_id(tag);
+ fprintf(fp, "<id>%s</id>\n", git_oid_tostr_s(target_oid));
+
+ const char *shortname = git_tag_name(tag);
+
+ fputs("<title>", fp);
+ xmlencode(fp, shortname, strlen(shortname));
+ fputs("</title>\n", fp);
+
+ const git_signature *tagger = git_tag_tagger(tag);
+ if (tagger) {
+ fputs("<published>", fp);
+ printtimez(fp, &(tagger->when));
+ fputs("</published>\n", fp);
+
+ fputs("<author>\n<name>", fp);
+ xmlencode(fp, tagger->name, strlen(tagger->name));
+ fputs("</name>\n<email>", fp);
+ xmlencode(fp, tagger->email, strlen(tagger->email));
+ fputs("</email>\n</author>\n", fp);
+ }
+
+ const char *msg = git_tag_message(tag);
+ if (msg) {
+ fputs("<content>", fp);
+ xmlencode(fp, msg, strlen(msg));
+ fputs("</content>\n", fp);
+ }
+
+ fputs("</entry>\n", fp);
+
+ return 0;
+}
+
int
writeatom(FILE *fp, int all)
{
@@ -924,7 +983,8 @@ writeatom(FILE *fp, int all)
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
xmlencode(fp, strippedname, strlen(strippedname));
- fputs(", branch HEAD</title>\n<subtitle>", fp);
+ if (all) fputs(", branch HEAD", fp);
+ fputs("</title>\n<subtitle>", fp);
xmlencode(fp, description, strlen(description));
fputs("</subtitle>\n", fp);
@@ -939,17 +999,8 @@ writeatom(FILE *fp, int all)
commitinfo_free(ci);
}
git_revwalk_free(w);
- } else if (getrefs(&ris, &refcount) != -1) {
- /* references: tags */
- for (i = 0; i < refcount; i++) {
- if (git_reference_is_tag(ris[i].ref))
- printcommitatom(fp, ris[i].ci,
- git_reference_shorthand(ris[i].ref));
-
- commitinfo_free(ris[i].ci);
- git_reference_free(ris[i].ref);
- }
- free(ris);
+ } else {
+ git_tag_foreach(repo, &tag_foreach_cb, fp);
}
fputs("</feed>\n", fp);