From patchwork Fri Jun 21 10:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Linden X-Patchwork-Id: 13707259 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E52DF74416 for ; Fri, 21 Jun 2024 10:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718966010; cv=none; b=i+5UdAt8qPdFnYYvVjB6MZKGFN9yblmZxWI+ZeRjj0LXhRwX6me5iEU185+BBAvL2g9XnlmT4A/6w19fUGklBIUAsai603QOl8u6VdBVmw3XvuYuPbAT4aMfh0iYeOO22s5hqTRJO9kqLh/z5WgCq17LhESz2stDRbGzltT6afI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718966010; c=relaxed/simple; bh=BLr1rsZiS3CCeOxsU+GqXDl5DBUks3z4MG16551c8GA=; h=MIME-Version:From:Date:Message-ID:Subject:To:Content-Type; b=R5VedqSVnUtTI+w8cZRnL/Vo1qmwpyqUZB4w2GQVEWe8kA8I+G6zavQ/tSGrBkpI/9znFcxnCa2lQnPXi8hC4fMg6mSDnMvvGY37Outh9EyW+cpYhPAX7vpO7BZiQqCFHAC0q+XRMNtRNsAGIQIMmKtCa+VKigVUIL5PkKKIWvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aXx+tDNt; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aXx+tDNt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718966007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=VP6+dBRNnFCxSPZ/ezzI7uSy8oE/54PEeL+yPj/Uyvc=; b=aXx+tDNt/RGi6WS5ORJmaOKMmaU8yhpGZpXSwuD3Og+0IGrENJSHuqaJZZyADYERHPIMBg 2o9CAWUBGO267b9O+aR3tVBhbVvSZS8jyIuGfAXjCRUYasQ5DRFYmMzwY/yyK3184qThss iXRnJgf7Ccd237NJC2S66ocddguv/2E= Received: from mail-vk1-f200.google.com (mail-vk1-f200.google.com [209.85.221.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-240-EtgIm3TxNBmvDre8YDGDlg-1; Fri, 21 Jun 2024 06:33:25 -0400 X-MC-Unique: EtgIm3TxNBmvDre8YDGDlg-1 Received: by mail-vk1-f200.google.com with SMTP id 71dfb90a1353d-4ef2da0987cso789265e0c.1 for ; Fri, 21 Jun 2024 03:33:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718966005; x=1719570805; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VP6+dBRNnFCxSPZ/ezzI7uSy8oE/54PEeL+yPj/Uyvc=; b=gX+l5LtB9FtL8UbZUimroBTcsemIOB+T3tEmLyCqwphYFejluwxKxwVF7NG1FD2l5n WZhk65XoTgGLKpTC0/khHoGHC0X+H2AOJFrmsEQdj/5KYWch85pXCt3rOXpv2CDAeaVq uUOkx8vWIRKSaqj+bix1lGu1lkdP245DV2OIIiK1j1NJEr9i1IDlZHXTcR6/CUNqXZIT m7PADzwZP7xRoeu9EVkSZrjWqxGsCaeIfNuPxtmAt3iTxzJqYWJ8r9khM33JOX4zrhi1 96OzzGx+M7eXk6yH5T8awqC3FBtDy3LGNm/cu1ovQPv8+YiE3VgZbYM/r9gFLbVOb2uY lPQg== X-Gm-Message-State: AOJu0YxHbP7tHVsNTyk5KyCZ4NFLdV+eta1MAQmX8m2ydVlATRUgv6um 0slwv/wJC2BpgwRojhmBMbN7IbRCCMXzcT2204gZaIsFqYA3jXvUhuygI2kpr3oqPWWEZbKqM8L 914C897ai+zOaYoi82lMDQEuLgY5da5vQhBLRGyUqBtcmVK0DfxAhpVAPvoWrYxQ9aVIni1I5aw YpBnNPwkr0ZBVCk8xtzQO5knye17wXVqluC2NUWw== X-Received: by 2002:ac5:c746:0:b0:4ef:27dc:7a9 with SMTP id 71dfb90a1353d-4ef27dc165emr7021375e0c.0.1718966005107; Fri, 21 Jun 2024 03:33:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEroOFucFxJp5S4kPpu8S5zxwmPtlXQb6SZEkyfNe4xQpunSje9XX9jDpGw1TwL2Q1kDmZ1Psgj/1sqnwwH3ys= X-Received: by 2002:ac5:c746:0:b0:4ef:27dc:7a9 with SMTP id 71dfb90a1353d-4ef27dc165emr7021361e0c.0.1718966004649; Fri, 21 Jun 2024 03:33:24 -0700 (PDT) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Rob Linden Date: Fri, 21 Jun 2024 12:33:10 +0200 Message-ID: Subject: problem with parsing of patch files for patch-id To: git@vger.kernel.org Hello! We noticed a problem with the parsing of a patch file for "git patch-id". I understand that the patch file format is very difficult and unpredictable and probably it's not even possible to correctly parse all of them (mostly due to missing restrictions on or escaping of commit messages). But in our specific case it can be improved to handle it correctly. I attached an example patch file. When feeding that to "git patch-id" (with git version 2.45.2.561.g66ac6e4bcd) the output is: 068a8a30a5b0e55b93fdc16b2a7dcd6886e420f3 1111111111111111111111111111111111111111 818756276fff2c6075da8effe36c65d25e6ed592 dcc59dffa5116bf96618065cd60742cb660224b8 b033e3eca8a60741bb414689ddfe00a0c1a09de5 3333333333333333333333333333333333333333 But it should be: 068a8a30a5b0e55b93fdc16b2a7dcd6886e420f3 1111111111111111111111111111111111111111 818756276fff2c6075da8effe36c65d25e6ed592 2222222222222222222222222222222222222222 b033e3eca8a60741bb414689ddfe00a0c1a09de5 3333333333333333333333333333333333333333 The reason is that the commit message of the second patch contains commit hashes which are parsed as if they were the commit hash for the patch, and not just some message. This patch (also attached) fixes it by only considering commit hashes in a "From xxxxx..." line: } But I'm not sure it is ok in all other cases [which are handled correctly now, i.e. it only makes it better for cases like ours, without making it worse for anything else). The unit-tests pass ok but I didn't check how comprehensive they are. Can somebody please have a look and tell me what they think about patch file parsing? Thanks & all the best, rob Signed-off-by: Junio C Hamano diff --git a/builtin/patch-id.c b/builtin/patch-id.c index 583099cacf..4b8a41bde8 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -86,7 +86,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result, continue; } - if (!get_oid_hex(p, next_oid)) { + if (starts_with(p-5, "From ") && !get_oid_hex(p, next_oid)) { found_next = 1; break; }