All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: Kees Cook <keescook@chromium.org>, tools@linux.kernel.org
Subject: [PATCH 5/5] patchwork-bot: Allow initial database to skip recent commits
Date: Tue, 30 Nov 2021 16:11:26 -0800	[thread overview]
Message-ID: <20211201001126.4106635-6-keescook@chromium.org> (raw)
In-Reply-To: <20211201001126.4106635-1-keescook@chromium.org>

To test patchwork-bot, it is helpful to create the initial database
without a certain number of the latest commits, so that on the next
execution, the "missing" commits will appear new, and will be used for
processing state changes. Add the --ancestors argument (defaulting to
0, the existing behavior), to provide this ability.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 git-patchwork-bot.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/git-patchwork-bot.py b/git-patchwork-bot.py
index 9be945d92a8a..2ebe5b4e88e4 100755
--- a/git-patchwork-bot.py
+++ b/git-patchwork-bot.py
@@ -409,13 +409,17 @@ def git_run_command(gitdir, args, stdin=None):
     return output
 
 
-def git_get_repo_heads(gitdir, branch):
+def git_get_repo_heads(gitdir, branch, ancestry=None):
     refs = list()
     lines = git_get_command_lines(gitdir, ['show-ref', branch])
+    if ancestry == None:
+        ancestry = ''
+    else:
+        ancestry = f'~{ancestry}'
     if lines is not None:
         for line in lines:
             (commit_id, refname) = line.split()
-            refs.append((refname, commit_id))
+            refs.append((refname, commit_id + ancestry))
     return refs
 
 
@@ -1082,7 +1086,9 @@ def pwrun(repo, rsettings):
 
     if not db_exists:
         db_init_pw_sqlite_db(c)
-        db_save_repo_heads(c, git_heads)
+        initial_git_heads = git_get_repo_heads(repo, branch=rsettings.get('branch', '--heads'),
+                                               ancestry=cmdargs.ancestors)
+        db_save_repo_heads(c, initial_git_heads)
         # Exit early
         dbconn.commit()
         return
@@ -1353,6 +1359,8 @@ if __name__ == '__main__':
                         help='Cache directory to use instead of ~/.cache/git-patchwork-bot')
     parser.add_argument('--domain', default=None,
                         help='Domain to use when creating message-ids')
+    parser.add_argument('--ancestors', default=None,
+                        help='During initial database creation, consider this many ancestor commits as fresh')
 
     cmdargs = parser.parse_args()
 
-- 
2.30.2


  parent reply	other threads:[~2021-12-01  0:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-01  0:11 [PATCH 0/5] patchwork-bot: Use worktrees for repos Kees Cook
2021-12-01  0:11 ` [PATCH 1/5] patchwork-bot: Note which actions are part of "housekeeping" Kees Cook
2021-12-01  0:11 ` [PATCH 2/5] patchwork-bot: Create CACHEDIR if it is missing Kees Cook
2021-12-01  0:11 ` [PATCH 3/5] patchwork-bot: Allow limiting heads to single branch Kees Cook
2021-12-01  0:11 ` [PATCH 4/5] patchwork-bot: Handle repo being a worktree Kees Cook
2021-12-01  0:11 ` Kees Cook [this message]
2021-12-13 22:30 ` [PATCH 0/5] patchwork-bot: Use worktrees for repos Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211201001126.4106635-6-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@linux.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.