aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2022-01-25 11:52:31 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2022-01-25 11:52:31 -0500
commit10b7024b67ae4985a88d29abba46953497601ac3 (patch)
tree6e3d359e13cf8382195672a5e4b80636cdf41fba
parent3da44d217d546e8b7fe5b00f905ca38913255db2 (diff)
downloadkorg-helpers-10b7024b67ae4985a88d29abba46953497601ac3.tar.gz
Fix hash generation after switching to "git show"
When I switched to "git show" I didn't fully test whether it would generate the same patchwork hashes as "git diff" proper. The few sample tries I ran happened to do the right thing, but many other commits would generate different hashes. Make sure we ignore anything that comes before we find "diff " on the line. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-xgit-patchwork-bot.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/git-patchwork-bot.py b/git-patchwork-bot.py
index 5dcf2e9..2657ff6 100755
--- a/git-patchwork-bot.py
+++ b/git-patchwork-bot.py
@@ -481,7 +481,7 @@ def git_get_patch_id(diff: str) -> Optional[str]:
def get_patchwork_hash(diff: str) -> str:
- """Generate a hash from a diff. Lifted verbatim from patchwork."""
+ """Generate a hash from a diff. Lifted near verbatim from patchwork."""
# normalise spaces
diff = diff.replace('\r', '')
@@ -490,9 +490,15 @@ def get_patchwork_hash(diff: str) -> str:
prefixes = ['-', '+', ' ']
hashed = hashlib.sha1()
+ inpatch = False
for line in diff.split('\n'):
if len(line) <= 0:
continue
+ # Ignore any content before "^diff "
+ if not inpatch and not line.startswith('diff '):
+ continue
+
+ inpatch = True
hunk_match = HUNK_RE.match(line)
filename_match = FILENAME_RE.match(line)
@@ -1142,11 +1148,10 @@ def pwrun(repo: str, rsettings: Dict[str, Union[str, list, dict]]) -> None:
logger.debug('Skipping %s (no pwhash)', rev)
continue
msgid = None
- if info.find('Link:') > 0:
- lore_match = LORE_RE.search(info)
- if lore_match:
- msgid = lore_match.group(1)
- logger.debug('Msgid for %s: %s', rev, msgid)
+ lore_match = LORE_RE.search(info)
+ if lore_match:
+ msgid = lore_match.group(1)
+ logger.debug('Msgid for %s: %s', rev, msgid)
_rev_cache[rev] = (rev, logline, committer, pwhash, msgid)
rpwhashes[refname].add(_rev_cache[rev])
@@ -1313,20 +1318,21 @@ def check_repos() -> None:
def pwhash_differ() -> None:
diff = sys.stdin.read()
- pwhash = get_patchwork_hash(diff)
- print(pwhash)
+ inhash = get_patchwork_hash(diff)
+ logger.info('stdin hash: %s', inhash)
+ check_patch_id = cmdargs.pwhash
for pw in CONFIG['patchworks']:
- print(f"Patchwork: {pw}")
+ logger.info('Patchwork: %s', pw)
for pname, psettings in CONFIG['patchworks'][pw]['projects'].items():
- print(f"Project: {pname}")
project, rm, pconfig = project_by_name(pname)
- project_id = project['id']
- print(get_patchwork_patches_by_project_hash(rm, project_id, pwhash))
- print('-------')
- p = rm.get_patch(cmdargs.pwhash)
- pwdiff = p.get('diff')
- print(pwdiff)
- print(get_patchwork_hash(pwdiff))
+ patch = rm.get_patch(check_patch_id)
+ if patch.get('hash') != inhash:
+ logger.info('--- patchwork diff ---')
+ logger.info(patch.get('diff'))
+ logger.info('--- hash: %s ---', patch.get('hash'))
+ sys.exit(1)
+ logger.info('No mismatches found')
+ sys.exit(0)
if __name__ == '__main__':