From patchwork Thu Jun 6 10:39:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 1111034 X-Patchwork-Delegate: ruscur@russell.cc Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45KMbt2VRvz9sND for ; Thu, 6 Jun 2019 20:39:38 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 45KMbs71BNzDqfD for ; Thu, 6 Jun 2019 20:39:37 +1000 (AEST) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=ajd@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45KMbm3hPFzDqdM for ; Thu, 6 Jun 2019 20:39:31 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x56AdBww136360 for ; Thu, 6 Jun 2019 06:39:29 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2sy0vuh19d-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 06 Jun 2019 06:39:28 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 6 Jun 2019 11:39:26 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 6 Jun 2019 11:39:23 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x56AdMw225952324 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 6 Jun 2019 10:39:23 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DB220AE06E for ; Thu, 6 Jun 2019 10:39:21 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 468C1AE045 for ; Thu, 6 Jun 2019 10:39:21 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 6 Jun 2019 10:39:21 +0000 (GMT) Received: from intelligence.ozlabs.ibm.com (unknown [9.102.62.69]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 34267A017C for ; Thu, 6 Jun 2019 20:39:18 +1000 (AEST) From: Andrew Donnellan To: snowpatch@lists.ozlabs.org Date: Thu, 6 Jun 2019 20:39:12 +1000 X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19060610-0016-0000-0000-00000286382A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19060610-0017-0000-0000-000032E352B1 Message-Id: <20190606103912.26840-1-ajd@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-06_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906060078 Subject: [snowpatch] [RFC PATCH] Report apply_patch as a warning, not error, if matching commit found X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" If a patch can't be applied, check to see if there's a commit already in the repository that matches the title of the patch. If so, don't report the fact that it failed to apply as an error, only a warning. Closes: #24 ("Patch application can fail if snowpatch tries to apply patch after maintainer has merged") Signed-off-by: Andrew Donnellan --- like everything else i've done today, completely untested --- src/git.rs | 15 +++++++++++++++ src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/git.rs b/src/git.rs index ad4bb781d23b..be744fdf1934 100644 --- a/src/git.rs +++ b/src/git.rs @@ -155,3 +155,18 @@ pub fn cred_from_settings(settings: &Git) -> Result { passphrase, ) } + +pub fn find_commit_with_title(repo: &Repository, title: &str) -> bool { + let workdir = repo.workdir().unwrap(); + + // TODO: Perhaps limit this to a certain number of commits, etc + let result = Command::new("git") + .arg("log") + .arg("--oneline") + .arg("--grep") + .arg(title) + .current_dir(&workdir) + .output() + .expect("Couldn't run git"); + !result.stdout.is_empty() +} diff --git a/src/main.rs b/src/main.rs index 5ec0c37b2d7f..bbc773597cc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -191,6 +191,7 @@ fn test_patch( client: &Arc, project: &Project, path: &Path, + title: Option<&str>, hefty_tests: bool, ) -> Vec { let repo = project.get_repo().unwrap(); @@ -208,6 +209,8 @@ fn test_patch( push_opts.remote_callbacks(push_callbacks); let mut successfully_applied = false; + let mut possibly_applied = false; + for branch_name in project.branches.clone() { let tag = format!("{}_{}", tag, branch_name); info!("Configuring local branch for {}.", tag); @@ -261,19 +264,35 @@ fn test_patch( } Err(_) => { // It didn't apply. No need to bother testing. + + // Check if there's a patch with an identical title already in the repository + let mut possibly_applied_to_branch = false; + if let Some(title) = title { + possibly_applied_to_branch = git::find_commit_with_title(&repo, title); + } + results.push(TestResult { state: TestState::Warning, - description: Some( + description: Some(if possibly_applied_to_branch { + format!( + "Failed to apply on branch {} ({}) (possibly already applied)", + branch_name.to_string(), + commit.id().to_string() + ) + .to_string() + } else { format!( "Failed to apply on branch {} ({})", branch_name.to_string(), commit.id().to_string() ) - .to_string(), - ), + .to_string() + }), context: Some("apply_patch".to_string()), ..Default::default() }); + + possibly_applied = possibly_applied || possibly_applied_to_branch; continue; } } @@ -310,8 +329,13 @@ fn test_patch( } if !successfully_applied { + // If at least one branch found a commit with the same title, then use Warning rather than Fail results.push(TestResult { - state: TestState::Fail, + state: if possibly_applied { + TestState::Warning + } else { + TestState::Fail + }, description: Some("Failed to apply to any branch".to_string()), context: Some("apply_patch".to_string()), ..Default::default() @@ -398,7 +422,7 @@ fn run() -> Result<(), Box> { } else { patchwork.get_patch_mbox(&patch) }; - test_patch(&settings, &client, &project, &mbox, true); + test_patch(&settings, &client, &project, &mbox, Some(&patch.name), true); } } return Ok(()); @@ -416,7 +440,8 @@ fn run() -> Result<(), Box> { Some(project) => { let dependencies = patchwork.get_patch_dependencies(&patch); let mbox = patchwork.get_patches_mbox(dependencies); - let results = test_patch(&settings, &client, &project, &mbox, true); + let results = + test_patch(&settings, &client, &project, &mbox, Some(&patch.name), true); // Delete the temporary directory with the patch in it fs::remove_dir_all(mbox.parent().unwrap()) @@ -437,7 +462,8 @@ fn run() -> Result<(), Box> { if args.flag_mbox != "" { info!("snowpatch is testing a local patch."); let patch = Path::new(&args.flag_mbox); - test_patch(&settings, &client, &project, patch, true); + // TODO: Can't match patch title + test_patch(&settings, &client, &project, patch, None, true); return Ok(()); } @@ -517,7 +543,14 @@ fn run() -> Result<(), Box> { patchwork.get_patch_mbox(&patch) }; - let results = test_patch(&settings, &client, &project, &mbox, hefty_tests); + let results = test_patch( + &settings, + &client, + &project, + &mbox, + Some(&patch.name), + hefty_tests, + ); // Delete the temporary directory with the patch in it fs::remove_dir_all(mbox.parent().unwrap())