commit 54f61e527a91d6dcd55e9367832cea69fdff2254
parent 0b0b1e436f2eef139d48e57bc26c957202d53bd3
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Fri, 4 Sep 2026 22:06:50 -0300
If open file is open show line count istead of size
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/stagit.c b/stagit.c
@@ -1121,6 +1121,21 @@ formatsize(size_t size)
}
size_t
+bloblinecount(const git_blob *blob)
+{
+ const char *s = git_blob_rawcontent(blob);
+ size_t i, len = git_blob_rawsize(blob), n = 0;
+
+ for (i = 0; i < len; i++)
+ if (s[i] == '\n')
+ n++;
+ if (len > 0 && s[len - 1] != '\n')
+ n++;
+
+ return n;
+}
+
+size_t
writeblob(git_object *obj, const char *fpath, const char *rpath, const char *filename, const char *path, size_t filesize)
{
char tmp[PATH_MAX] = "", *file_parent;
@@ -1196,7 +1211,10 @@ writeblob(git_object *obj, const char *fpath, const char *rpath, const char *fil
xmlencode(fp, path, strlen(path));
fprintf(fp, "</a>%s", strlen(path) == 0 ? "" : "/");
xmlencode(fp, filename, strlen(filename));
- fprintf(fp, " (%s)</div>\n\n", formatsize(filesize));
+ if (!isbin)
+ fprintf(fp, " (%zu lines)</div>\n\n", bloblinecount((git_blob *)obj));
+ else
+ fprintf(fp, " (%s)</div>\n\n", formatsize(filesize));
if (!isbin) {
fputs("<div id=\"line-checkbox-div\"><input type=\"checkbox\""