From 43422b026d4728f9da372cb018bf33d223bb9569 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 8 Jul 2022 22:24:59 +0200 Subject: Added special matching case for root commit --- pkgrel.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/pkgrel.c b/pkgrel.c index 653a0db..d7551e1 100644 --- a/pkgrel.c +++ b/pkgrel.c @@ -9,10 +9,11 @@ enum match_result { - MATCH_RESULT_NEVER, - MATCH_RESULT_NEWDIFF, - MATCH_RESULT_NOTFOUND, - MATCH_RESULT_FOUND, + MATCH_RESULT_INIT, + MATCH_RESULT_ROOT, + MATCH_RESULT_COMMIT, + MATCH_RESULT_ANYTHING, + MATCH_RESULT_PKGVER, }; @@ -88,8 +89,8 @@ try_git(const int err, const char* msg) /// Callback for git_diff_foreach. Check each line reported by the diff looking for "pkgver" occurrance. If found, set -/// *payload* to MATCH_RESULT_FOUND, otherwise set it to MATCH_RESULT_NOTFOUND, but only if it is not set to FOUND -/// already. +/// *payload* to MATCH_RESULT_PKGVER, otherwise set it to MATCH_RESULT_ANYTHING, but only if it is not set to +/// MATCH_RESULT_PKGVER already. int match_line(const git_diff_delta* delta, const git_diff_hunk* hunk, const git_diff_line* line, void* payload) { @@ -100,12 +101,11 @@ match_line(const git_diff_delta* delta, const git_diff_hunk* hunk, const git_dif case GIT_DIFF_LINE_ADDITION: case GIT_DIFF_LINE_DELETION: if (PKGVER_LEN <= line->content_len && 0 == strncmp(line->content, PKGVER, PKGVER_LEN)) - *match = MATCH_RESULT_FOUND; + *match = MATCH_RESULT_PKGVER; + else if (MATCH_RESULT_PKGVER != *match) + *match = MATCH_RESULT_ANYTHING; break; default: - if (MATCH_RESULT_FOUND > *match) - *match = MATCH_RESULT_NOTFOUND; - break; } return 0; } @@ -133,10 +133,12 @@ main(int argc, char* argv[]) git_tree* earlier = NULL; git_tree* later = NULL; int relpkg = 1; - enum match_result match = MATCH_RESULT_NEVER; + enum match_result match = MATCH_RESULT_INIT; while (0 == git_revwalk_next(&oid, walker)) { git_commit* commit; try_git(git_commit_lookup(&commit, repo, &oid), "finding commit"); + if (0 == git_commit_parentcount(commit)) + match = MATCH_RESULT_ROOT; if (NULL != earlier) git_tree_free(earlier); earlier = later; @@ -146,17 +148,17 @@ main(int argc, char* argv[]) try_git(git_diff_tree_to_workdir_with_index(&diff, repo, later, &diffopts), "diff"); else try_git(git_diff_tree_to_tree(&diff, repo, later, earlier, &diffopts), "diff"); - if (MATCH_RESULT_NEVER < match) - match = MATCH_RESULT_NEWDIFF; - try_git(git_diff_foreach(diff, NULL, NULL, NULL, &match_line, &match), "searching lines"); + if (MATCH_RESULT_INIT != match) + match = MATCH_RESULT_COMMIT; + try_git(git_diff_foreach(diff, NULL, NULL, NULL, &match_line, &match), "searching history"); git_diff_free(diff); git_commit_free(commit); - if (MATCH_RESULT_FOUND == match) + if (MATCH_RESULT_PKGVER == match) break; - if (MATCH_RESULT_NOTFOUND == match) + if (MATCH_RESULT_ANYTHING == match) relpkg++; } - if (MATCH_RESULT_NEVER == match) { + if (MATCH_RESULT_INIT == match) { dprintf(2, "PKGBUILD not found\n"); exit(1); } -- cgit v1.1