summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-07-08 22:24:59 +0200
committerAki <please@ignore.pl>2022-07-08 22:24:59 +0200
commit43422b026d4728f9da372cb018bf33d223bb9569 (patch)
treeb632cc7a6a050c76455b9ff513c7d186384c07ab
parent976a304eb27a7fc6cb998541ffddc379b1d40cfd (diff)
downloadpkgrel-43422b026d4728f9da372cb018bf33d223bb9569.zip
pkgrel-43422b026d4728f9da372cb018bf33d223bb9569.tar.gz
pkgrel-43422b026d4728f9da372cb018bf33d223bb9569.tar.bz2
Added special matching case for root commit
-rw-r--r--pkgrel.c36
1 files 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);
}