From e1c0aebde443979a524a944027b81f84f4323ff3 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 28 Nov 2020 12:28:05 +0100 Subject: [PATCH] fix warning with libgit2 v0.99+, remain compatible with older versions git_blob_rawsize now returns with git_object_size_t (unsigned). This was git_off_t (signed). In my current version 1.1.0: types.h:typedef uint64_t git_object_size_t; v0.28.5: https://libgit2.org/libgit2/#v0.28.5/group/blob/git_blob_rawsize changed from v0.99 onwards: https://libgit2.org/libgit2/#v0.99.0/group/blob/git_blob_rawsize Fix: use size_t to remain compatible (with a possible warning in older versions), since git_object_size_t is a new defined type. This assumes size_t is atleast uint32_t / uint64_t size. Adapted from a patch by Augustin Fabre , thanks! --- stagit.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/stagit.c b/stagit.c index 1cdaee8..d38aaa4 100644 --- a/stagit.c +++ b/stagit.c @@ -504,15 +504,15 @@ writefooter(FILE *fp) size_t writeblobhtml(FILE *fp, const git_blob *blob) { - size_t n = 0, i, prev; + size_t n = 0, i, len, prev; const char *nfmt = "%7zu "; const char *s = git_blob_rawcontent(blob); - git_off_t len = git_blob_rawsize(blob); + len = git_blob_rawsize(blob); fputs("
\n", fp);
 
 	if (len > 0) {
-		for (i = 0, prev = 0; i < (size_t)len; i++) {
+		for (i = 0, prev = 0; i < len; i++) {
 			if (s[i] != '\n')
 				continue;
 			n++;
@@ -886,7 +886,7 @@ writeatom(FILE *fp, int all)
 }
 
 size_t
-writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
+writeblob(git_object *obj, const char *fpath, const char *filename, size_t filesize)
 {
 	char tmp[PATH_MAX] = "", *d;
 	const char *p;
@@ -910,7 +910,7 @@ writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t fi
 	writeheader(fp, filename);
 	fputs("

", fp); xmlencode(fp, filename, strlen(filename)); - fprintf(fp, " (%juB)", (uintmax_t)filesize); + fprintf(fp, " (%zuB)", filesize); fputs("


", fp); if (git_blob_is_binary((git_blob *)obj)) { @@ -975,10 +975,9 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) { const git_tree_entry *entry = NULL; git_object *obj = NULL; - git_off_t filesize; const char *entryname; char filepath[PATH_MAX], entrypath[PATH_MAX], oid[8]; - size_t count, i, lc; + size_t count, i, lc, filesize; int r, ret; count = git_tree_entrycount(tree); @@ -1023,7 +1022,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) if (lc > 0) fprintf(fp, "%zuL", lc); else - fprintf(fp, "%juB", (uintmax_t)filesize); + fprintf(fp, "%zuB", filesize); fputs("\n", fp); git_object_free(obj); } else if (git_tree_entry_type(entry) == GIT_OBJ_COMMIT) { -- libgit2 1.1.1