summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-07-07 22:38:31 +0200
committerAki <please@ignore.pl>2022-07-07 22:38:31 +0200
commit4977a18390f2bbbd8cd2f3e7a2a8a8e5b97df491 (patch)
tree8e5b3d4c0edfe8702201cab8d41a8c5bd85f4ad1
parent1ed4f63a03b94eb05a2b86f204b2eb9938a86581 (diff)
downloadpkgrel-4977a18390f2bbbd8cd2f3e7a2a8a8e5b97df491.zip
pkgrel-4977a18390f2bbbd8cd2f3e7a2a8a8e5b97df491.tar.gz
pkgrel-4977a18390f2bbbd8cd2f3e7a2a8a8e5b97df491.tar.bz2
It will now actually print pkgrel number accordingly
-rw-r--r--Makefile4
-rw-r--r--pkgrel.c31
2 files changed, 26 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 17249eb..89954cd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-CFLAGS=`pkg-config --cflags libgit2 libpcre2-8`
-LDLIBS=`pkg-config --libs libgit2 libpcre2-8`
+CFLAGS=`pkg-config --cflags libgit2`
+LDLIBS=`pkg-config --libs libgit2`
all: pkgrel
diff --git a/pkgrel.c b/pkgrel.c
index fe8d072..5c1d348 100644
--- a/pkgrel.c
+++ b/pkgrel.c
@@ -1,5 +1,3 @@
-#define PCRE2_CODE_UNIT_WIDTH 8
-
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -7,7 +5,14 @@
#include <unistd.h>
#include <git2.h>
-#include <pcre2.h>
+
+
+enum match_result
+{
+ MATCH_RESULT_INITIAL,
+ MATCH_RESULT_NOTFOUND,
+ MATCH_RESULT_FOUND,
+};
size_t
@@ -68,14 +73,19 @@ gerror(void)
int
line_line(const git_diff_delta* delta, const git_diff_hunk* hunk, const git_diff_line* line, void* payload)
{
+ const char* const pkgver = "pkgver";
+ const size_t len = strlen(pkgver);
+ enum match_result* matched = (enum match_result*) payload;
switch (line->origin) {
case GIT_DIFF_LINE_ADDITION:
- printf("+%.*s", line->content_len, line->content);
- break;
case GIT_DIFF_LINE_DELETION:
- printf("-%.*s", line->content_len, line->content);
+ if (len <= line->content_len && 0 == strncmp(line->content, pkgver, len))
+ *matched = MATCH_RESULT_FOUND;
break;
default:
+ if (MATCH_RESULT_FOUND != *matched)
+ *matched = MATCH_RESULT_NOTFOUND;
+ break;
}
return 0;
}
@@ -114,6 +124,7 @@ main(int argc, char* argv[])
git_oid oid;
git_tree* earlier = NULL;
git_tree* later = NULL;
+ int rel = 1;
while (0 == git_revwalk_next(&oid, walker)) {
git_commit* commit;
err = git_commit_lookup(&commit, repo, &oid);
@@ -138,9 +149,14 @@ main(int argc, char* argv[])
gerror();
return 1;
}
- git_diff_foreach(diff, NULL, NULL, NULL, &line_line, NULL);
+ enum match_result matched = MATCH_RESULT_INITIAL;
+ git_diff_foreach(diff, NULL, NULL, NULL, &line_line, &matched);
git_diff_free(diff);
git_commit_free(commit);
+ if (MATCH_RESULT_FOUND == matched)
+ break;
+ if (MATCH_RESULT_INITIAL != matched)
+ rel++;
}
if (NULL != earlier)
git_tree_free(earlier);
@@ -150,4 +166,5 @@ main(int argc, char* argv[])
git_pathspec_free(pathspec);
free(diffopts.pathspec.strings[0]);
git_repository_free(repo);
+ printf("%d\n", rel);
}