From patchwork Tue Nov 12 10:38:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 598521515 for ; Tue, 12 Nov 2019 10:38:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3996C206BA for ; Tue, 12 Nov 2019 10:38:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f6tYHRat" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726484AbfKLKid (ORCPT ); Tue, 12 Nov 2019 05:38:33 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38269 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725865AbfKLKic (ORCPT ); Tue, 12 Nov 2019 05:38:32 -0500 Received: by mail-wm1-f68.google.com with SMTP id z19so2367547wmk.3 for ; Tue, 12 Nov 2019 02:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VH1R/IfHdgKEIPpomWN06FnlIkXtVZrD8Hf/gCipgYk=; b=f6tYHRatsibsX2/3NyDZLmFcclbOK8Hkt2W662ewkumS+o3SQHLkCzrlGIvQ1BmdWz 7rc8suTzMhoFqL4kNznih+BTdjIuyhPQoRKggK/fclkN57BRDx0TChR7I39mvRVqQSgA 51PmIX+dy6A9Qtrumc7+DrD2ml+W8kenITSQj3cOpqTTe801cqwy+inI/bvkkm1LDTCw qqMFkXWp87gsiEpQQjWh/BxzpQVyBwgvJQCCW4GVcqBO1RBCykwmuVyBJR8ePEeGiLPq hC5UVK2cCwQkxsWakEOlbTJjVtQovIyHvXONa/v3KDmxDC9Iqc9YqPKOTL7RPphLpRNf wiqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VH1R/IfHdgKEIPpomWN06FnlIkXtVZrD8Hf/gCipgYk=; b=q9y0qIW/0NOwFMfJ9wPk9ODl70hSoiYGQNE44bsXRGxnB4CQU0PkUEgAAHKTjqA9LG d7dxvStLkG87+RfJWEwSLwL4ZGIR9gdZ51pP2pNqpNgvSvHKxtoz6gQ1fIN5+sl9p1wo sk4zA32dX+JO7sLrMstNKQ/aVmLX53XmVq3SlN9/m8GeH4ysCgpDTQvHXnCt1ltQaIPL 3XH4R919PM6gX+AHA1ZtbpAie7ZSSrxVECj2U9GqnnwyKmsU3HE9Da1qCUEzj0YlUetq 4nO9TDh+UXretNXuf9yh1Ux9cxyGe0MSpHkBY6ThFRFABXXR1ks6do6hFYcz8I30yr72 J5NA== X-Gm-Message-State: APjAAAV5fq+VS/gUCFm+83IE0lGgEhE4k3laPJ+TvYlMIbLxl+GSmyOl TQ6+iuqtVO/BvoXrXJTwuMAWmjWN X-Google-Smtp-Source: APXvYqxIBJ8i4TJeBULS0L09PjwZ4RASS0n+bWM14FtKvR31MZpVkCbCLBPgRvNGhQwoKG9fhiyzLA== X-Received: by 2002:a7b:c307:: with SMTP id k7mr3013850wmj.134.1573555111252; Tue, 12 Nov 2019 02:38:31 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:30 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 01/13] t6120-describe: correct test repo history graph in comment Date: Tue, 12 Nov 2019 11:38:09 +0100 Message-Id: <20191112103821.30265-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org At the top of 't6120-describe.sh' an ASCII graph illustrates the repository's history used in this test script. This graph is a bit misleading, because it swapped the second merge commit's first and second parents. When describing/naming a commit it does make a difference which parent is the first and which is the second/Nth, so update this graph to accurately represent that second merge. While at it, move this history graph from the 'test_description' variable to a regular comment. Signed-off-by: SZEDER Gábor --- t/t6120-describe.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 45047d0a72..9b184179d1 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -1,15 +1,16 @@ #!/bin/sh -test_description='test describe +test_description='test describe' + +# o---o-----o----o----o-------o----x +# \ D,R e / +# \---o-------------o-' +# \ B / +# `-o----o----o-' +# A c +# +# First parent of a merge commit is on the same line, second parent below. - B - .--------------o----o----o----x - / / / - o----o----o----o----o----. / - \ A c / - .------------o---o---o - D,R e -' . ./test-lib.sh check_describe () { From patchwork Tue Nov 12 10:38:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B4ED17E6 for ; Tue, 12 Nov 2019 10:38:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6C97E21A49 for ; Tue, 12 Nov 2019 10:38:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lKk5sjLK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfKLKih (ORCPT ); Tue, 12 Nov 2019 05:38:37 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55799 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725954AbfKLKie (ORCPT ); Tue, 12 Nov 2019 05:38:34 -0500 Received: by mail-wm1-f67.google.com with SMTP id b11so2517164wmb.5 for ; Tue, 12 Nov 2019 02:38:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L3dT5vldE1tZcMpAvBDoXj9cWhy9cI+NNGQtImbC7IY=; b=lKk5sjLKNAct5zAhYHtbAPF8PXutRAsSxrhsRxrPd6HpAfpGDbRooBxDnP62cCSqYT oiiP0Rl9sYN8tOI5SpQz0gOPZJZGN1yWXoRoWXUlPXH4NavfX5TuE2GH6hgJz2CXHIX0 xUc2zIZ2AtyNbxd/GGmZElbuRrX3B4TvbwvdKgqR9WgMOdY/G6rh6I0OAGL0OaOU+AYg QVlTUht3l2Y6ODaEDOnLweIqgv3rMbxmX43t+kvamXitvs9hGnVY/yF8Xny5hdvBkJOp QQcEmJBHwSGOtEW2CAmW3YgDfs2p33A0yG6u8tJI+yJwkzl3NAzvj307YL9lGuP6T0t5 cl9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L3dT5vldE1tZcMpAvBDoXj9cWhy9cI+NNGQtImbC7IY=; b=eRd/HEWhabv2uiBjce0wfpncBTqXLBIGu81VMfNTNFMtixjS0kXQvXFX8wR2dJT28C L0KpvlZeBzOXbCOCSNahuBnztIyJIHY++Qbx4ug3S3PBmVNtjmE6SeeUoGH5TCzM1bDd S4RCwERQP02hx8ALKmAz1memOFWpkV7VlnmfsIcBHjyGOfkLSmIjmC+fkv4ouFbT/WFn 0pm8FVnWIkwjSrkD3CW2wYGVHwWYOjnseeF0+0XyJ5gofqZ+5kjld37Bp6TTn2bNkYSh iraQY/GgeJVBNYcVnlPSV2+RLp0OzFZA6KRco9BYVeJw5VWPwmbvLKEWlTK/Mz95nZ/h 3Yjg== X-Gm-Message-State: APjAAAUNwUcK0vDSCC+1wAPgapPvxEQGLB7aYo2cMkUG5XZa+hntZO+p RbetEyLax002l7M7xFWF21g= X-Google-Smtp-Source: APXvYqzYUWqRP9efPhbNRrNKg3Co6PNbQvOZuzRJuAWrWbPRX8IYPGrg9dfPi5Pk0xbqkpKp7VVO+A== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr3397094wmc.130.1573555112325; Tue, 12 Nov 2019 02:38:32 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:31 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 02/13] t6120-describe: modernize the 'check_describe' helper Date: Tue, 12 Nov 2019 11:38:10 +0100 Message-Id: <20191112103821.30265-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The 'check_describe' helper function runs 'git describe' outside of 'test_expect_success' blocks, with extra hand-rolled code to record and examine its exit code. Update this helper and move the 'git decribe' invocation inside the 'test_expect_success' block. Signed-off-by: SZEDER Gábor --- t/t6120-describe.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 9b184179d1..a2988fa0c2 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -16,14 +16,12 @@ test_description='test describe' check_describe () { expect="$1" shift - R=$(git describe "$@" 2>err.actual) - S=$? - cat err.actual >&3 - test_expect_success "describe $*" ' - test $S = 0 && + describe_opts="$@" + test_expect_success "describe $describe_opts" ' + R=$(git describe $describe_opts 2>err.actual) && case "$R" in $expect) echo happy ;; - *) echo "Oops - $R is not $expect"; + *) echo "Oops - $R is not $expect" && false ;; esac ' From patchwork Tue Nov 12 10:38:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2787139A for ; Tue, 12 Nov 2019 10:38:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D31CE20674 for ; Tue, 12 Nov 2019 10:38:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WFnGGcIy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbfKLKig (ORCPT ); Tue, 12 Nov 2019 05:38:36 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41584 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725944AbfKLKif (ORCPT ); Tue, 12 Nov 2019 05:38:35 -0500 Received: by mail-wr1-f68.google.com with SMTP id p4so17909367wrm.8 for ; Tue, 12 Nov 2019 02:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O+uwDpL5C8Es92Es/gA1mmITlPbqqGIFZ6Uf0BqL2es=; b=WFnGGcIy21BBJxSjisKFF1b676Q1PS62/eT9lS612GCyl+Cx5NDB4aIwYh/SlHpMQd +IGhsKZa8udxrUm4IrBndSGSqpYgKeYWxixoIEBUsao8ziATzLf7WaNyTf2W3WNuCkV+ okZ/fXZMJEnZkVismLAXO008MR+R963zF0phmAESugEM0eUfx0GkpMWYfagIYQi+p05T N+zoUv8zTCbttfIXXMJcv80+DBm10pDwKdT/c8kxVx3f0mTZQdaaPt6FNQHD6q08BU0o s4O3VSoyCNW5kOrnqex5XT5/kzb4ZwD9FJVfY86O7pNOi+PNasyOFQLXWAsqiCDsWI0t yfIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O+uwDpL5C8Es92Es/gA1mmITlPbqqGIFZ6Uf0BqL2es=; b=OwiGD7q19IMYcec8MvOAWbxGDunguGCuYhC/yuA+gvkdetw7xKk5w9c5wEdhJ9qEOj BEMN+g1ifRHgTE2vCMgezyqXozvjQWgiInfQ1zDtyWYdbj567kiBKlA2Jwh8IUtuNoAO OnQr92rcAWg95Dqq6TRGzcvllqEMbbfj8UNPgPfcBYL0yYuujypka+nwldf1SE/jzKYf pjFjWB69LYi6gRCzdRBGnRMO/ucD5J+HMTJjRI+HjGszsOhhCjcT6vNq8aEDfNPMFhMK F2IVsqikneEp7IKrDcwLJaw61F0/p63xh4FcdmgSgn7CHVQhUm0unad8rpF93og2p+m2 PV/A== X-Gm-Message-State: APjAAAV9rgUuRr9FMVTybfBILmLjw+cK+ZfOby950vSESBWwFNyqW/C2 nW7GDdIldxElQXXDvY/A1bM= X-Google-Smtp-Source: APXvYqzTGRUHJCWdLX6Wnq39DuW7SowYtUFyZ5AmMdqGvrYsTeur9MQh5wytqNY+rPKetdfXDCP9Xw== X-Received: by 2002:a05:6000:343:: with SMTP id e3mr26332671wre.20.1573555113337; Tue, 12 Nov 2019 02:38:33 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:32 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 03/13] name-rev: use strbuf_strip_suffix() in get_rev_name() Date: Tue, 12 Nov 2019 11:38:11 +0100 Message-Id: <20191112103821.30265-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: René Scharfe get_name_rev() basically open-codes strip_suffix() before adding a string to a strbuf. Let's use the strbuf right from the beginning, i.e. add the whole string to the strbuf and then use strbuf_strip_suffix(), making the code more idiomatic. [TODO: René's signoff!] Signed-off-by: SZEDER Gábor Signed-off-by: René Scharfe --- builtin/name-rev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index b0f0776947..15919adbdb 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -321,11 +321,10 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf) if (!n->generation) return n->tip_name; else { - int len = strlen(n->tip_name); - if (len > 2 && !strcmp(n->tip_name + len - 2, "^0")) - len -= 2; strbuf_reset(buf); - strbuf_addf(buf, "%.*s~%d", len, n->tip_name, n->generation); + strbuf_addstr(buf, n->tip_name); + strbuf_strip_suffix(buf, "^0"); + strbuf_addf(buf, "~%d", n->generation); return buf->buf; } } From patchwork Tue Nov 12 10:38:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 284721515 for ; Tue, 12 Nov 2019 10:38:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0729120674 for ; Tue, 12 Nov 2019 10:38:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dI3pGwTq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbfKLKih (ORCPT ); Tue, 12 Nov 2019 05:38:37 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35637 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbfKLKig (ORCPT ); Tue, 12 Nov 2019 05:38:36 -0500 Received: by mail-wm1-f67.google.com with SMTP id 8so2396490wmo.0 for ; Tue, 12 Nov 2019 02:38:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u2AEGP1QPKiIhkCklSJxe5J+zHiFnypcWdV0DyTM6+8=; b=dI3pGwTqRxOsAAvPhy7+WOJC8LoqX5pefEV0V8YutRo/B32mLS4Vf22Lrko+IKOEZP DDt1sgURV+e6n10sORMCIuLsvN8vHsRdpLl2UEzGATvtVJQ/TJEAOqg0zIBTIw+6rRzd kjInC1pgzC3Mx6M8mwQ5+vJd5rWb3xQfDozJ77NytyuUP1MpbZLvERjgqZwUiyZCIqyX jpYNJ4Qf58hpqw8cRrNNhek6Lac1U8ScnNgaGyxEN3WkhkKulAv2lMbAsHG3zH3mTQXT Zy5n1AxX8J8nDHUnFMPex5MezlR3/AXk/zqYLDIEPEJdHyP36zLISTbaAry0tt2ksTsP NfAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u2AEGP1QPKiIhkCklSJxe5J+zHiFnypcWdV0DyTM6+8=; b=SRbfGnikpuNa7pDA3T516sXdimOwk6Sr72MNGkMdDCdzhJICmvzsK6iKF/2MX+C/r5 R5UTIfGNtuOKf/JhLeYoOWxxbUDSS3SshPYSvYcD+LJIJ+rS+rEuyqpkrfe8ZnSrHQ6y 3AKNz9oMCzWZv8OdILDly7d2wzJJ2Ee1e/1Bgl/BNFLsgAHDsFzpeF8GU158wjf65NtV vkk2IB2V3BmSdHAtaXy6mRB2Npxd0wZndjmyO1lQFD/8Up4830aG0etf7+CIE7ESzgsb ZzBzpIgZskBCnPwnXkhap+UbtdXzxHSJt/SUvjfv//PUD4VupNuCz1VH9YCOAfxbHU28 iNXw== X-Gm-Message-State: APjAAAWrv2QAsgSs+2M7qlOBKbKCsy4rhDorRKiPRQhNSHqvP7v6MU6J Xqy0IfkMnNZXi7HmwQInZG8= X-Google-Smtp-Source: APXvYqzpTCVSZQQZJF7WDyuog8apbcXSoHYe865cHHiQerESHhx+YZobvTUoTOCG3v6kjQ8nMNxdwA== X-Received: by 2002:a1c:113:: with SMTP id 19mr3486612wmb.42.1573555114365; Tue, 12 Nov 2019 02:38:34 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:33 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 04/13] name-rev: avoid unnecessary cast in name_ref() Date: Tue, 12 Nov 2019 11:38:12 +0100 Message-Id: <20191112103821.30265-5-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Casting a 'struct object' to 'struct commit' is unnecessary there, because it's already available in the local 'commit' variable. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 15919adbdb..e40f51c2b4 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -271,9 +271,9 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo struct commit *commit = (struct commit *)o; int from_tag = starts_with(path, "refs/tags/"); if (taggerdate == TIME_MAX) - taggerdate = ((struct commit *)o)->date; + taggerdate = commit->date; path = name_ref_abbrev(path, can_abbreviate_output); name_rev(commit, xstrdup(path), taggerdate, 0, 0, from_tag, deref); } From patchwork Tue Nov 12 10:38:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239019 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16ABF1515 for ; Tue, 12 Nov 2019 10:38:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EB1F121A49 for ; Tue, 12 Nov 2019 10:38:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j8s41WnL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbfKLKij (ORCPT ); Tue, 12 Nov 2019 05:38:39 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54536 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbfKLKih (ORCPT ); Tue, 12 Nov 2019 05:38:37 -0500 Received: by mail-wm1-f67.google.com with SMTP id z26so2517968wmi.4 for ; Tue, 12 Nov 2019 02:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xsQZugQmzx96C464Lk8l0tqamlHfE4WUnRulbZfg6J0=; b=j8s41WnLpYXx5TXDUHXlJdbf3fVs+gowL/3z2RMyxKkW3szHXc6K06bVUjlmo220y1 69wBajBT8A+Rwl9kxHGe6uxvIhJ/lHB94CWbIJBkpIs96/rLJAQ+qYFw1WWTF9SSKBxW 4Gy2NzAJ3pcxHN/PA9LIrAg1zCuxF50oJcWSxYn4ADPU6PcgXRQwOCl2QmjdSy13OF7c ggH2NzFCoAW//kRuPbyfPTeETVsXxFx9MQfCPhZyMJbx9frlGp4MlixR03tz19LuBqHy RJ/RW1J6tzUp0l40ct8s0X1hhU4jkzAkOFscNitr0ONhZOnjNotWyRnqInTBHV2zhlTn B+9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xsQZugQmzx96C464Lk8l0tqamlHfE4WUnRulbZfg6J0=; b=QNcjp3RjZMDQX4HG29ACHJthbAHI8vJB+llkkCTbBBugO5KsBc0aVSTHyvudELfgKL orw9SFz9ZhBiOTkU/7sRepOR/KPDz4UEyH2P02lUjrD4tWxB08V+8kzEnswnnSgDDeh4 6hfPvHSqijs1QQWhrdtGevbk87yTBwk7m4PMHhbGv/jW7SA5UzNreDX78kq7/lss0xUA d2M6YvhzTEyWa7/+qzYWA+ukAPRDj/ZdhlHq+C3uYw1UuwW38JrvZwyylh72DDUZ/Typ Bz+BBA8OnfUqSyDrLVIEnC7yaoq49mlHTRxAAgmbVs+iYtRUSwPZrEJbFttgvLQYXinT pQgg== X-Gm-Message-State: APjAAAVXUEjGEWA7w8/+gwcBQvVEpZ/37bAlmJn/FjDvSCBGcaKIKh7E r1lGl6Ysd5UkFqAyjfWuY/0= X-Google-Smtp-Source: APXvYqzSSLcE7HK03ePzGsKD/oSI5UoXfXMPT3ZVKwFEtVnZnrTwGf0gujJigKSsJoXqeDA1iThlQg== X-Received: by 2002:a7b:cf32:: with SMTP id m18mr3339880wmg.166.1573555115526; Tue, 12 Nov 2019 02:38:35 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:34 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 05/13] name-rev: use sizeof(*ptr) instead of sizeof(type) in allocation Date: Tue, 12 Nov 2019 11:38:13 +0100 Message-Id: <20191112103821.30265-6-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index e40f51c2b4..7e003c2702 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -102,7 +102,7 @@ static void name_rev(struct commit *commit, } if (name == NULL) { - name = xmalloc(sizeof(rev_name)); + name = xmalloc(sizeof(*name)); set_commit_rev_name(commit, name); goto copy_data; } else if (is_better_name(name, taggerdate, distance, from_tag)) { From patchwork Tue Nov 12 10:38:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239023 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F27717E6 for ; Tue, 12 Nov 2019 10:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1FE2120674 for ; Tue, 12 Nov 2019 10:38:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dw6/noeh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbfKLKil (ORCPT ); Tue, 12 Nov 2019 05:38:41 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40901 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbfKLKij (ORCPT ); Tue, 12 Nov 2019 05:38:39 -0500 Received: by mail-wm1-f67.google.com with SMTP id f3so2366639wmc.5 for ; Tue, 12 Nov 2019 02:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oxQJMVMvd806F3eiPo0ttLu51dBwa15NS2dBeMSGmZM=; b=dw6/noehkdl17KhdgLDWEMCKfOg0cihRYSPHg982CDGiL3Vm0+eB/TdIXqsYYal9J3 eAEuN/I180Talyyr29lbjhnbRk2Rwb9BV8puHWWGEJJLrGQy7NiI2kaTxEuKP347n6bP E/ZLC+5I2DonMHN8bVkRYoWOF2fCtF/i5EXkvk/e0F1Kbs7M6Q91etF6qbbrE+sP4mZh 2Pii0BEWwQ9S55FY06rPQknNb5lj8UZXg2LP7YSJVtYif/dmgy+UH4xBkNBA41Zb4se3 9fg5etLoATAD2trwTabqmeJ8NoeGPncrNiV8W9xvatUEJ/vXE2iMko4V+BBEcB9xLzIL 57kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oxQJMVMvd806F3eiPo0ttLu51dBwa15NS2dBeMSGmZM=; b=OsuZ2xg3mC0nwLi+xED24aRbKnJ2algKpI7rQFdo7gV+Ahrw3lgqtmeZhexjyJQMc8 NyjomuP138pi1dlr01ajzIhuhMX1odJZDiwKkZf4Tn7y0piH18cmdDtSotAOcR5LDoHc 4RWDzvgg07452iDs3rf0U29uD9YHiXZ7r8yB9GJwjvX6YUkuS/afK/r8p9x2h3ALuujD xKVa5hi08MSxFQAXukTY44kcgwnuIGLVYn2cwTNKA22f+h9PwGz9Mpv1iZZOIRCWPVQc rIVA7jWbbcBmR138dPbm16zQT3cExHyUpveg3kzdd32adnQwd6s/2ZrEeXK88FblQIJw Dgiw== X-Gm-Message-State: APjAAAWjXI4JbYzy6sibdUYtErEteZKg95DWvpP37wDK+Si7AirNqXX8 cAXR8Zx1yzbmYX+/9+5gr5o= X-Google-Smtp-Source: APXvYqw0gTyr5VLy5pOd5gAmBpqRCfZt3bKYcyPxfWxUucdl9IsDdwWZ6P9PiUjK+463MgAPtFot+Q== X-Received: by 2002:a05:600c:20e:: with SMTP id 14mr3118048wmi.107.1573555116548; Tue, 12 Nov 2019 02:38:36 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:35 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 06/13] t6120: add a test to cover inner conditions in 'git name-rev's name_rev() Date: Tue, 12 Nov 2019 11:38:14 +0100 Message-Id: <20191112103821.30265-7-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 'builtin/name-rev.c' in the name_rev() function there is a loop iterating over all parents of the given commit, and the loop body looks like this: if (parent_number > 1) { if (generation > 0) // branch #1 new_name = ... else // branch #2 new_name = ... name_rev(parent, new_name, ...); } else { // branch #3 name_rev(...); } These conditions are not covered properly in the test suite. As far as purely test coverage goes, they are all executed several times over in 't6120-describe.sh'. However, they don't directly influence the command's output, because the repository used in that test script contains several branches and tags pointing somewhere into the middle of the commit DAG, and thus result in a better name for the to-be-named commit. This can hide bugs: e.g. by replacing the 'new_name' parameter of the first recursive name_rev() call with 'tip_name' (effectively making both branch #1 and #2 a noop) 'git name-rev --all' shows thousands of bogus names in the Git repository, but the whole test suite still passes successfully. In an early version of a later patch in this series I managed to mess up all three branches (at once!), but the test suite still passed. So add a new test case that operates on the following history: A--------------master \ / \----------M2 \ / \---M1-C \ / B and names the commit 'B' to make sure that all three branches are crucial to determine 'B's name: - There is only a single ref, so all names are based on 'master', without any undesired interference from other refs. - Each time name_rev() follows the second parent of a merge commit, it appends "^2" to the name. Following 'master's second parent right at the start ensures that all commits on the ancestry path from 'master' to 'B' have a different base name from the original 'tip_name' of the very first name_rev() invocation. Currently, while name_rev() is recursive, it doesn't matter, but it will be necessary to properly cover all three branches after the recursion is eliminated later in this series. - Following 'M2's second parent makes sure that branch #2 (i.e. when 'generation = 0') affects 'B's name. - Following the only parent of the non-merge commit 'C' ensures that branch #3 affects 'B's name, and that it increments 'generation'. - Coming from 'C' 'generation' is 1, thus following 'M1's second parent makes sure that branch #1 affects 'B's name. Signed-off-by: SZEDER Gábor --- t/t6120-describe.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index a2988fa0c2..0d119e9652 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -438,4 +438,45 @@ test_expect_success 'name-rev a rev shortly after epoch' ' test_cmp expect actual ' +# A--------------master +# \ / +# \----------M2 +# \ / +# \---M1-C +# \ / +# B +test_expect_success 'name-rev covers all conditions while looking at parents' ' + git init repo && + ( + cd repo && + + echo A >file && + git add file && + git commit -m A && + A=$(git rev-parse HEAD) && + + git checkout --detach && + echo B >file && + git commit -m B file && + B=$(git rev-parse HEAD) && + + git checkout $A && + git merge --no-ff $B && # M1 + + echo C >file && + git commit -m C file && + + git checkout $A && + git merge --no-ff HEAD@{1} && # M2 + + git checkout master && + git merge --no-ff HEAD@{1} && + + echo "$B master^2^2~1^2" >expect && + git name-rev $B >actual && + + test_cmp expect actual + ) +' + test_done From patchwork Tue Nov 12 10:38:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C830B1515 for ; Tue, 12 Nov 2019 10:38:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4BF521783 for ; Tue, 12 Nov 2019 10:38:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rWDTp+BJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727089AbfKLKij (ORCPT ); Tue, 12 Nov 2019 05:38:39 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46462 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbfKLKij (ORCPT ); Tue, 12 Nov 2019 05:38:39 -0500 Received: by mail-wr1-f68.google.com with SMTP id b3so17882812wrs.13 for ; Tue, 12 Nov 2019 02:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v5mewiIbj/6DMKLd/iga1QO1cz2Xuabb0SmVqKZJhT4=; b=rWDTp+BJn2BDPO+YRudxKGiKxhTsySwcBMBG+wFX+28Zp+vkiySTokgU46gt9mTPUH RkXHheCM1FPsFPQZMOVHMxcpm7H5xHUGMPx65bt5xinj2rFncymqvXi/Nfr49aPaEFEJ NbwsLs74jNXHjHnXr4EoyMbAXTZ1+Ax2fXG0Zhx+jkV/pe/WtvS3ot3FrgByHU8vqWFP jd5EcD6cKQjiEO8gSMmr4C6j+9kkFTLBQik+KL8aYM10kedrVjy6h8RichDAy9IFN2+o e+88vkCpCwceJRNkdTR+soOyF8djVsLyjlM1RGfQpYjWkq6b5tKPwxqLFaoJvZKCQ/nC z9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v5mewiIbj/6DMKLd/iga1QO1cz2Xuabb0SmVqKZJhT4=; b=aZDJqMGZiZOmkXuy+gb+/CTnnQwB8FWVd5+MFLSu+MhZzyUB5ZMZCyZcG6yzHhenNX YKakztsSdN3dhWsIZpzFcaJgY/aY007Zc74sm2IVbdu2zpftXv67PbopRcvVT5Hegqz5 Tnab+yqOM0/tvmlLAIh6IgJp3rOF8gY+2d/o5IGNWkUlFDSJy6QjmxDamUKbKhUXW5zU LvhBEfCNXAaalwK8dDaT+9nJbtDSCSX+sxP/wy4g9og8gM75zPeejnT3IRS9ylXXQ+yS BStm+85l0shNK8NT1CPt7cG25rgHcD1VLznME3i7jEhf0Jq8K56kVMaGVKwZuEz56nLN MXfQ== X-Gm-Message-State: APjAAAV8RPtugt0796Kk2ttwsxBbIBIoJO9vo8x8l3XwWhcJado9BEP+ BZ1R9hH/74f/q5XLvPjschM= X-Google-Smtp-Source: APXvYqyIpEvJgd/IiMOhR79mkPrKjm5c4PGDzMIEWzvpfYKPPOvkOg6tZnwOrJj+NtBUdARxmnwsCA== X-Received: by 2002:a5d:61c6:: with SMTP id q6mr14433630wrv.13.1573555117749; Tue, 12 Nov 2019 02:38:37 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:37 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 07/13] name-rev: extract creating/updating a 'struct name_rev' into a helper Date: Tue, 12 Nov 2019 11:38:15 +0100 Message-Id: <20191112103821.30265-8-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a later patch in this series we'll want to do this in two places. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 7e003c2702..e43df19709 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -79,12 +79,36 @@ static int is_better_name(struct rev_name *name, return 0; } +static struct rev_name *create_or_update_name(struct commit *commit, + const char *tip_name, + timestamp_t taggerdate, + int generation, int distance, + int from_tag) +{ + struct rev_name *name = get_commit_rev_name(commit); + + if (name == NULL) { + name = xmalloc(sizeof(*name)); + set_commit_rev_name(commit, name); + goto copy_data; + } else if (is_better_name(name, taggerdate, distance, from_tag)) { +copy_data: + name->tip_name = tip_name; + name->taggerdate = taggerdate; + name->generation = generation; + name->distance = distance; + name->from_tag = from_tag; + + return name; + } else + return NULL; +} + static void name_rev(struct commit *commit, const char *tip_name, timestamp_t taggerdate, int generation, int distance, int from_tag, int deref) { - struct rev_name *name = get_commit_rev_name(commit); struct commit_list *parents; int parent_number = 1; char *to_free = NULL; @@ -101,18 +125,8 @@ static void name_rev(struct commit *commit, die("generation: %d, but deref?", generation); } - if (name == NULL) { - name = xmalloc(sizeof(*name)); - set_commit_rev_name(commit, name); - goto copy_data; - } else if (is_better_name(name, taggerdate, distance, from_tag)) { -copy_data: - name->tip_name = tip_name; - name->taggerdate = taggerdate; - name->generation = generation; - name->distance = distance; - name->from_tag = from_tag; - } else { + if (!create_or_update_name(commit, tip_name, taggerdate, generation, + distance, from_tag)) { free(to_free); return; } From patchwork Tue Nov 12 10:38:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239021 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DBC31515 for ; Tue, 12 Nov 2019 10:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E253E20674 for ; Tue, 12 Nov 2019 10:38:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bR6KNBnB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbfKLKim (ORCPT ); Tue, 12 Nov 2019 05:38:42 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50438 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727068AbfKLKik (ORCPT ); Tue, 12 Nov 2019 05:38:40 -0500 Received: by mail-wm1-f67.google.com with SMTP id l17so2555974wmh.0 for ; Tue, 12 Nov 2019 02:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vMv3vzr3BnanY2d+E5rxW0m9+LMWs5sc3C5exAsemYk=; b=bR6KNBnBKp2N3Ma7N2HU1OW9jarLgjEAuNJZ7Ckdzhi9R/63n+u+ckNyZdZEFtwFue aXJC9uROgmcwnDHrALCBgjfdveMEH998m0p+kkxKX6kj4OeFuMWuyddtQKZww0Hylo1u v+up2cjjZbWofm459JejJWuKbNPwSsfgu5Wu81RviP+9mRy5W6BRjsjH7Ue1PfGEQi4s NNeh9JcE2+EUpap+cnqb4R9sg6J5qLRO/ixk00tk79k1fT+ZatRJ3aLfpiNYzQR/LeNq yl7TkD4Wxjk89xxS69/rt7D6WqCE/NPf6xxb9Gm73BxWRQoP3d8M5iCMSBeN9Xtq5ebt 7A3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vMv3vzr3BnanY2d+E5rxW0m9+LMWs5sc3C5exAsemYk=; b=C42nh9V4ri7bns6UszMJUpPQpet9X5EwHcUEsUi++cBHq5zIEHHYyE62GVrLErtmjQ e+z1ajBT7CbmQJ9E1PFM/nJ/dT70mdrbuvvmj1BtQinibDrJYYCYqx1fg657PFV2Pdgd lYVmTx8WXwMvBsk463b+mGaEvNtuQ4N2rdi2/XrTuoRGqHpf7CV8mEFMWVmObwADKylS Carvb50u5BukT/DmY5R1IO2ZCqyDwt4NyJh9cW+KN2nmyAF7p0Hmcw79hkcYXDQ9ro2R qti1S7VRUHo6eRhHBfBd6Ruuot1OcbtUPPzYm0o0Svwww528G0/HhxIxCJqOU1nGkL0g Vm7w== X-Gm-Message-State: APjAAAUG/tLnY3jZaGkGC4pH/fOoLRJU2nGdUpby1mCmSD0LMAvQWhta iP8m6d0yGQ4+3hmKVwwMqkM= X-Google-Smtp-Source: APXvYqyhEycLVNJRfG9Irby99LiXcDOaU2yU/r67jVz5UXq4GFUgssL2NvyJVoJiM2UVV3uMG0D8Lw== X-Received: by 2002:a7b:c776:: with SMTP id x22mr3144651wmk.144.1573555118758; Tue, 12 Nov 2019 02:38:38 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:38 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 08/13] name-rev: pull out deref handling from the recursion Date: Tue, 12 Nov 2019 11:38:16 +0100 Message-Id: <20191112103821.30265-9-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The 'if (deref) { ... }' condition near the beginning of the recursive name_rev() function can only ever be true in the first invocation, because the 'deref' parameter is always 0 in the subsequent recursive invocations. Extract this condition from the recursion into name_rev()'s caller and drop the function's 'deref' parameter. This makes eliminating the recursion a bit easier to follow, and it will be moved back into name_rev() after the recursion is eliminated. Furthermore, drop the condition that die()s when both 'deref' and 'generation' are non-null (which should have been a BUG() to begin with). Note that this change reintroduces the memory leak that was plugged in in commit 5308224633 (name-rev: avoid leaking memory in the `deref` case, 2017-05-04), but a later patch (name-rev: restructure creating/updating 'struct rev_name' instances) in this series will plug it in again. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index e43df19709..e112a92b03 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -106,30 +106,19 @@ static struct rev_name *create_or_update_name(struct commit *commit, static void name_rev(struct commit *commit, const char *tip_name, timestamp_t taggerdate, - int generation, int distance, int from_tag, - int deref) + int generation, int distance, int from_tag) { struct commit_list *parents; int parent_number = 1; - char *to_free = NULL; parse_commit(commit); if (commit->date < cutoff) return; - if (deref) { - tip_name = to_free = xstrfmt("%s^0", tip_name); - - if (generation) - die("generation: %d, but deref?", generation); - } - if (!create_or_update_name(commit, tip_name, taggerdate, generation, - distance, from_tag)) { - free(to_free); + distance, from_tag)) return; - } for (parents = commit->parents; parents; @@ -148,11 +137,11 @@ static void name_rev(struct commit *commit, name_rev(parents->item, new_name, taggerdate, 0, distance + MERGE_TRAVERSAL_WEIGHT, - from_tag, 0); + from_tag); } else { name_rev(parents->item, tip_name, taggerdate, generation + 1, distance + 1, - from_tag, 0); + from_tag); } } } @@ -284,12 +273,16 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo if (o && o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; int from_tag = starts_with(path, "refs/tags/"); + const char *tip_name; if (taggerdate == TIME_MAX) taggerdate = commit->date; path = name_ref_abbrev(path, can_abbreviate_output); - name_rev(commit, xstrdup(path), taggerdate, 0, 0, - from_tag, deref); + if (deref) + tip_name = xstrfmt("%s^0", path); + else + tip_name = xstrdup(path); + name_rev(commit, tip_name, taggerdate, 0, 0, from_tag); } return 0; } From patchwork Tue Nov 12 10:38:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5498817E6 for ; Tue, 12 Nov 2019 10:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 351B020674 for ; Tue, 12 Nov 2019 10:38:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ENHjRoEx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727126AbfKLKio (ORCPT ); Tue, 12 Nov 2019 05:38:44 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35652 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbfKLKim (ORCPT ); Tue, 12 Nov 2019 05:38:42 -0500 Received: by mail-wm1-f66.google.com with SMTP id 8so2396771wmo.0 for ; Tue, 12 Nov 2019 02:38:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8Yhc89CS3weW6GxUja4uz4NhZYQ6syhZPk1E02ipre8=; b=ENHjRoExe+SS4krR9euCLGWG81GAKhHuVNhcOfLy/JZf2+KyBKZf4ELwYUniwY/ATb zEml/aLcsBYUN9OE+1Y+yjUbjMRMa7ry7VyAYCCYrKfz9x6qfc0y54asyqZj3NgLarBZ EdjdbkTq3rO1IA4sK/oCKBzwamaW+LzI3yLV7ws/5UZzEmLWopzvYcpNF+hbnni3kFdq WMfz9elb/Rg/Zw/WpH/M8l6yiOrnBt/oI2PWbXuvsic1K13LFzQ5R+0UwSBv5Xf2GnO/ w76aW8DtBX/0A8mPRgUfTNqLhXYrHdmKSgz/f12S3NCrbx4FInSl3ty4NNZ8Q6T/A2xn DYtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Yhc89CS3weW6GxUja4uz4NhZYQ6syhZPk1E02ipre8=; b=PzIoeXwL15p1K9OOhsr/DgD19Lh9PGGE5g5+wUCb4SoOsETNCu4sQwJOlgATcOsMnL k4KXFgZ5Ukry+q/1C3e/O7dRRXBlkqto6u62qP2/n6CjpH9EDZTHXNAsQzxe0AahGT8q EIw/vXBZxUOamX+b5kswo+aXWbxCAJpl0Q3QmMwQYIXByQ2qF8uVLVd/EhN9Ct8mUNY6 TOzzLE8QxVuQi0NXt0+MeuVazbo1htwV+KrCxh5gqUFwPO6O0vKEgHM9iaAD8bv/Ucdn 0/AexfHi3CL49GPObmrM0SFaFmQ9DZUcuG1SGY6wDuogvD7SOGzNk2ge7Im+/xFYriAT J2gw== X-Gm-Message-State: APjAAAXmI3j2fN3jBQMG6x2duPvCiuPIKXVGFpw+ApRr9/hD2O7ct/9O g/2s4F27oHS+nEc1yo5VtJNbfUss X-Google-Smtp-Source: APXvYqzRqEe2pIkFkKeXfhhiTCMxsu9zisQPJ/FGK/cBbr79IkieJxI+SNxHnYtC+Q9xFvaSjXU87g== X-Received: by 2002:a1c:30b:: with SMTP id 11mr2983028wmd.171.1573555119926; Tue, 12 Nov 2019 02:38:39 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:39 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 09/13] name-rev: restructure parsing commits and applying date cutoff Date: Tue, 12 Nov 2019 11:38:17 +0100 Message-Id: <20191112103821.30265-10-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org At the beginning of the recursive name_rev() function it parses the commit it got as parameter, and returns early if the commit is older than a cutoff limit. Restructure this so the caller parses the commit and checks its date, and doesn't invoke name_rev() if the commit to be passed as parameter is older than the cutoff, i.e. both name_ref() before calling name_rev() and name_rev() itself as it iterates over the parent commits. This makes eliminating the recursion a bit easier to follow, and the condition moved to name_ref() will be moved back to name_rev() after the recursion is eliminated. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index e112a92b03..5041227790 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -111,11 +111,6 @@ static void name_rev(struct commit *commit, struct commit_list *parents; int parent_number = 1; - parse_commit(commit); - - if (commit->date < cutoff) - return; - if (!create_or_update_name(commit, tip_name, taggerdate, generation, distance, from_tag)) return; @@ -123,6 +118,12 @@ static void name_rev(struct commit *commit, for (parents = commit->parents; parents; parents = parents->next, parent_number++) { + struct commit *parent = parents->item; + + parse_commit(parent); + if (parent->date < cutoff) + continue; + if (parent_number > 1) { size_t len; char *new_name; @@ -135,11 +136,11 @@ static void name_rev(struct commit *commit, new_name = xstrfmt("%.*s^%d", (int)len, tip_name, parent_number); - name_rev(parents->item, new_name, taggerdate, 0, + name_rev(parent, new_name, taggerdate, 0, distance + MERGE_TRAVERSAL_WEIGHT, from_tag); } else { - name_rev(parents->item, tip_name, taggerdate, + name_rev(parent, tip_name, taggerdate, generation + 1, distance + 1, from_tag); } @@ -273,16 +274,18 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo if (o && o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; int from_tag = starts_with(path, "refs/tags/"); - const char *tip_name; if (taggerdate == TIME_MAX) taggerdate = commit->date; path = name_ref_abbrev(path, can_abbreviate_output); - if (deref) - tip_name = xstrfmt("%s^0", path); - else - tip_name = xstrdup(path); - name_rev(commit, tip_name, taggerdate, 0, 0, from_tag); + if (commit->date >= cutoff) { + const char *tip_name; + if (deref) + tip_name = xstrfmt("%s^0", path); + else + tip_name = xstrdup(path); + name_rev(commit, tip_name, taggerdate, 0, 0, from_tag); + } } return 0; } From patchwork Tue Nov 12 10:38:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2330217E6 for ; Tue, 12 Nov 2019 10:38:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F00072196E for ; Tue, 12 Nov 2019 10:38:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CVPC1ETs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727136AbfKLKiq (ORCPT ); Tue, 12 Nov 2019 05:38:46 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53819 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727068AbfKLKio (ORCPT ); Tue, 12 Nov 2019 05:38:44 -0500 Received: by mail-wm1-f68.google.com with SMTP id u18so2528951wmc.3 for ; Tue, 12 Nov 2019 02:38:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a6MP/bZbj3rJQcHQQraeUyrLBln2w0orScmhIltzCEI=; b=CVPC1ETsI5KEv1IJgukSKLu6TA1baMo/RnCX/QIBEr99z9Bh8y+SkW6d92AkknXePz WJmeN8a3xxxCZkFvaoOpgcZs+J/HlVNPFt0C8Jim6dRi7xyby9eZLq48ySCERJGc5iTv ptW7nfL4zR4fOMsHf0sNsDcKT/q+lBQR91SfjakLr7H7EY/dbMZPVdMEAiX3WDjj7nV8 Uvn19mH7mIOkQdkP0v+LvK9yGAilaf2qBkS32IMYWhvBFYbrctZqsXLLd5tefHEPg0Rj 5gitrNfkpZ7JcM+UH/ymQCMe7l6gMnAkmIL2tBAVHtA6+LfkZqX49BGdTWz9XD4aJuhr HB1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a6MP/bZbj3rJQcHQQraeUyrLBln2w0orScmhIltzCEI=; b=AiNFiVUmQS5GTP9T5EeVFdC3ENxkQp1ks9nX0sTxGd4CCUPdc/PA8wHUzle8SUG1zz 6NEg15jvE+2WMfmZ0IpUZPcf6X1enmLzk5u93cpkWuPF7pmpo6uRvn9vT6EIb3SnUxFU gXI5j3zDWKyJN430zIAYULZOD4tV55AWRcE76OFoSfg/ZBCLpQ9AgOi5bcezWB9k3RVy AjYyc0adAG03cMZpj8EiEr/xAvR+G8dDsWT92JaDL4ngzQWQekECfGPOuEyuGbmWr6Iq Ru3yVLSz5s+dkwZww8jjw2Dxu4qtXo+hjinoOUcJDQaxLiB97jx6hWmaL5r7cPY5KDp9 XMEQ== X-Gm-Message-State: APjAAAW8yQAU4XeSfrT3KcAqfV1hB0E/t/UUmSPkgrTcGqQW0KGUChg8 nlk/TG8TJ2up1Xfc0bMuYtY= X-Google-Smtp-Source: APXvYqzcq30uWCw4enOCGJv8rRH0cVpwX9yM0og9yqfpMCgL5gsSdkr4ygi9HgzsSGUCVqiRQTLEJw== X-Received: by 2002:a05:600c:2550:: with SMTP id e16mr3096044wma.69.1573555121041; Tue, 12 Nov 2019 02:38:41 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:40 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 10/13] name-rev: restructure creating/updating 'struct rev_name' instances Date: Tue, 12 Nov 2019 11:38:18 +0100 Message-Id: <20191112103821.30265-11-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org At the beginning of the recursive name_rev() function it creates a new 'struct rev_name' instance for each previously unvisited commit or, if this visit results in better name for an already visited commit, then updates the 'struct rev_name' instance attached to the commit, or returns early. Restructure this so it's caller creates or updates the 'struct rev_name' instance associated with the commit to be passed as parameter, i.e. both name_ref() before calling name_rev() and name_rev() itself as it iterates over the parent commits. This makes eliminating the recursion a bit easier to follow, and the condition moved to name_ref() will be moved back to name_rev() after the recursion is eliminated. This change also plugs the memory leak that was temporarily unplugged in the earlier "name-rev: pull out deref handling from the recursion" patch in this series. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 5041227790..6416c49f67 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -111,14 +111,12 @@ static void name_rev(struct commit *commit, struct commit_list *parents; int parent_number = 1; - if (!create_or_update_name(commit, tip_name, taggerdate, generation, - distance, from_tag)) - return; - for (parents = commit->parents; parents; parents = parents->next, parent_number++) { struct commit *parent = parents->item; + const char *new_name; + int new_generation, new_distance; parse_commit(parent); if (parent->date < cutoff) @@ -126,7 +124,6 @@ static void name_rev(struct commit *commit, if (parent_number > 1) { size_t len; - char *new_name; strip_suffix(tip_name, "^0", &len); if (generation > 0) @@ -135,15 +132,19 @@ static void name_rev(struct commit *commit, else new_name = xstrfmt("%.*s^%d", (int)len, tip_name, parent_number); - - name_rev(parent, new_name, taggerdate, 0, - distance + MERGE_TRAVERSAL_WEIGHT, - from_tag); + new_generation = 0; + new_distance = distance + MERGE_TRAVERSAL_WEIGHT; } else { - name_rev(parent, tip_name, taggerdate, - generation + 1, distance + 1, - from_tag); + new_name = tip_name; + new_generation = generation + 1; + new_distance = distance + 1; } + + if (create_or_update_name(parent, new_name, taggerdate, + new_generation, new_distance, + from_tag)) + name_rev(parent, new_name, taggerdate, + new_generation, new_distance, from_tag); } } @@ -280,11 +281,17 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo path = name_ref_abbrev(path, can_abbreviate_output); if (commit->date >= cutoff) { const char *tip_name; + char *to_free = NULL; if (deref) - tip_name = xstrfmt("%s^0", path); + tip_name = to_free = xstrfmt("%s^0", path); else tip_name = xstrdup(path); - name_rev(commit, tip_name, taggerdate, 0, 0, from_tag); + if (create_or_update_name(commit, tip_name, taggerdate, + 0, 0, from_tag)) + name_rev(commit, tip_name, taggerdate, 0, 0, + from_tag); + else + free(to_free); } } return 0; From patchwork Tue Nov 12 10:38:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4D241515 for ; Tue, 12 Nov 2019 10:38:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5B0721783 for ; Tue, 12 Nov 2019 10:38:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ptWg1pVH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727151AbfKLKir (ORCPT ); Tue, 12 Nov 2019 05:38:47 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33575 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727113AbfKLKio (ORCPT ); Tue, 12 Nov 2019 05:38:44 -0500 Received: by mail-wr1-f67.google.com with SMTP id w9so11132588wrr.0 for ; Tue, 12 Nov 2019 02:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sa73V0138qjREEXwSdy7csXIRfVeLgAaUYEFtqXcrVs=; b=ptWg1pVH/uyeZNCYgtjXvvB4cxAnVVvADw9ByKlJP4UooFYtljd8DmUqvUQsuxmGPm wJ+Zsbt9o0zgUiZiNaUBjc9PRyhOeJkIzZ6tT9TwJVkl670KL/Ni/rWHkwVHNW6CAAm/ D7n5iFMw6fZKlmZRZsziPZqO3j+x+ncy2tYg4GU+zNPJ8gdpC3mGRJTVS6FXmF9RZWtP 52UJPfEXXlGoSqjh5Az1jUj7dffJCmyEu6d5IyG2ukIzkEn2Qc6ujiDbeqVqPSSpf1SO 7y/8CIZiD5k4PVmLLVZ6QDzYQmaDogQTmtbRdRsCwzeobMKJ/8uMG9pD+GzRxLU5Qmld qf8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sa73V0138qjREEXwSdy7csXIRfVeLgAaUYEFtqXcrVs=; b=pma0pOGerGWhgGtQFq6192OcLtnyrpcOm+OeOv73sM4wg39bf9WFAoUKq+itSQbDTO 1+TZaCzuMFl+6c/rk1zxBZ7bN9Q16eLqOKpU4uhul3uCwLIiNVSKwYjvwbsl6oBEp+2n dIOXK6Gt6NNO1OLUkqfYyO/jcGySYQyVBhS8Q00je8LdTrJYMVV/RU50gI/sxPp4bO5F 2UvXh183ZrYKdg31vNS3YmMLa2AhpsdB5lLisRB8Q5BN5ZeNBb0TfYpl2bPKLRFyllq3 B6LJBpqNUjXYO5uMInZ5RUWSb9LoJeW7yk/8VcBoOsO0RRNonKKcwpGGj11ax2BI+ahv kKHA== X-Gm-Message-State: APjAAAUieYf/aIYev8JYXmxWAOMy+Vv1RoSQIvEzYKZg4A+q4GwzChWV suleE8ecFs0oEIRUQL+yy/I= X-Google-Smtp-Source: APXvYqzNQYsUrCMxtbBfF4VTIX2mXPr7534Geb68BSdupC6UE+ul8e0qEbOspztuDQ1FYJulj22Y5g== X-Received: by 2002:adf:ed48:: with SMTP id u8mr23561961wro.28.1573555122166; Tue, 12 Nov 2019 02:38:42 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:41 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 11/13] name-rev: drop name_rev()'s 'generation' and 'distance' parameters Date: Tue, 12 Nov 2019 11:38:19 +0100 Message-Id: <20191112103821.30265-12-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Following the previous patches in this series we can get the values of name_rev()'s 'generation' and 'distance' parameters from the 'stuct rev_name' associated with the commit as well. Let's simplify the function's signature and remove these two unnecessary parameters. Note that at this point we could do the same with the 'tip_name', 'taggerdate' and 'from_tag' parameters as well, but those parameters will be necessary later, after the recursion is eliminated. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 6416c49f67..fc61d6fa71 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -106,8 +106,9 @@ static struct rev_name *create_or_update_name(struct commit *commit, static void name_rev(struct commit *commit, const char *tip_name, timestamp_t taggerdate, - int generation, int distance, int from_tag) + int from_tag) { + struct rev_name *name = get_commit_rev_name(commit); struct commit_list *parents; int parent_number = 1; @@ -116,7 +117,7 @@ static void name_rev(struct commit *commit, parents = parents->next, parent_number++) { struct commit *parent = parents->item; const char *new_name; - int new_generation, new_distance; + int generation, distance; parse_commit(parent); if (parent->date < cutoff) @@ -126,25 +127,25 @@ static void name_rev(struct commit *commit, size_t len; strip_suffix(tip_name, "^0", &len); - if (generation > 0) + if (name->generation > 0) new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name, - generation, parent_number); + name->generation, + parent_number); else new_name = xstrfmt("%.*s^%d", (int)len, tip_name, parent_number); - new_generation = 0; - new_distance = distance + MERGE_TRAVERSAL_WEIGHT; + generation = 0; + distance = name->distance + MERGE_TRAVERSAL_WEIGHT; } else { new_name = tip_name; - new_generation = generation + 1; - new_distance = distance + 1; + generation = name->generation + 1; + distance = name->distance + 1; } if (create_or_update_name(parent, new_name, taggerdate, - new_generation, new_distance, + generation, distance, from_tag)) - name_rev(parent, new_name, taggerdate, - new_generation, new_distance, from_tag); + name_rev(parent, new_name, taggerdate, from_tag); } } @@ -288,7 +289,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo tip_name = xstrdup(path); if (create_or_update_name(commit, tip_name, taggerdate, 0, 0, from_tag)) - name_rev(commit, tip_name, taggerdate, 0, 0, + name_rev(commit, tip_name, taggerdate, from_tag); else free(to_free); From patchwork Tue Nov 12 10:38:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239037 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DF6A139A for ; Tue, 12 Nov 2019 10:38:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 167B621783 for ; Tue, 12 Nov 2019 10:38:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jz+lyubI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725947AbfKLKix (ORCPT ); Tue, 12 Nov 2019 05:38:53 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42505 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727059AbfKLKiq (ORCPT ); Tue, 12 Nov 2019 05:38:46 -0500 Received: by mail-wr1-f68.google.com with SMTP id a15so17892302wrf.9 for ; Tue, 12 Nov 2019 02:38:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ATdesPK0Kjx1rwWjckSnBmKU5mjWMYxtnejXtoipAaE=; b=jz+lyubI2WWXlkmUSuWEuSD8fEMknGRHN38m9UT/kQxBqYS2eZ4V55r4kyME91FKBa tuacj1lH6GQjjQF4NzykgcYkee0zbYDE08fv8jiA39af+9wuKfYjGkG571a4pVR8IdFr TPDCFfLvLVSApCwR6ylnKbI8l2YVTyj1N58Zc+holKhOFwuTPZCEfNqqHOh9Mfy2kDdV +5zTds4kZTw7b0XcVze4g9gpyyIZ3k+ogqBv/Gxc0BP5GeOBF7wAGfXHG/MfW1uCx/uR zdVcC5R4PPWDK/FStS2/kd0IhsQAnK8QOqE+CfrpWhVbw6r7RJ3prLzehbgbQxKU0L1M uI3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ATdesPK0Kjx1rwWjckSnBmKU5mjWMYxtnejXtoipAaE=; b=IazTSRn5APMQvl90Gkk+x1nDeNLVYGy0rWrLpVMjiqCEseyQXEyH1WM4NygSWpRpcx FBD8kV31LGMSpsj1CUR3STsrGxWoZdB1FxWfQYC0ShMVseXTByAxntWkVnPk+q+N65d6 MAkNY4ZiwxfWWlAzeiQez9TI4mVmbEBN7Nnkq/v+fP9NuxgK06twx37VErzGM+cV03Im jr889hhlGKh2tMVL9/pECucTjifmHKSWsiLPV/HH9/K3gREcZ/pVg3sfG4YCHwkJSArR pyKFLWhm71GTEyrAqgDgxtesvPiVEaBTblRXPG2qaWJ3JHP01CChwx1xUYuECtixAnOt y5lA== X-Gm-Message-State: APjAAAXflQPMtWv+7mlUBGSWjzpkHzYt5bRdFSpbKt1sqjhUmR0krpJf T51C7zNUrwdKuc2UxVCLphM= X-Google-Smtp-Source: APXvYqz3WNrtfyf1cmtawjPHIQv96NOVE+AA1AkEjglzghh9miWdNL9gTR23YYbMIEFqt4Jt16SWOg== X-Received: by 2002:adf:9ec7:: with SMTP id b7mr25320297wrf.221.1573555123316; Tue, 12 Nov 2019 02:38:43 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:42 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 12/13] name-rev: eliminate recursion in name_rev() Date: Tue, 12 Nov 2019 11:38:20 +0100 Message-Id: <20191112103821.30265-13-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The name_rev() function calls itself recursively for each interesting parent of the commit it got as parameter, and, consequently, it can segfault when processing a deep history if it exhausts the available stack space. E.g. running 'git name-rev --all' and 'git name-rev HEAD~100000' in the gcc, gecko-dev, llvm, and WebKit repositories results in segfaults on my machine ('ulimit -s' reports 8192kB of stack size limit), and nowadays the former segfaults in the Linux repo as well (it reached the necessasry depth sometime between v5.3-rc4 and -rc5). Eliminate the recursion by inserting the interesting parents into a LIFO 'prio_queue' [1] and iterating until the queue becomes empty. Note that the parent commits must be added in reverse order to the LIFO 'prio_queue', so their relative order is preserved during processing, i.e. the first parent should come out first from the queue, because otherwise performance greatly suffers on mergy histories [2]. The stacksize-limited test 'name-rev works in a deep repo' in 't6120-describe.sh' demonstrated this issue and expected failure. Now the recursion is gone, so flip it to expect success. Also gone are the dmesg entries logging the segfault of that segfaulting 'git name-rev' process on every execution of the test suite. Note that this slightly changes the order of lines in the output of 'git name-rev --all', usually swapping two lines every 35 lines in git.git or every 150 lines in linux.git. This shouldn't matter in practice, because the output has always been unordered anyway. This patch is best viewed with '--ignore-all-space'. [1] Early versions of this patch used a 'commit_list', resulting in ~15% performance penalty for 'git name-rev --all' in 'linux.git', presumably because of the memory allocation and release for each insertion and removal. Using a LIFO 'prio_queue' has basically no effect on performance. [2] We prefer shorter names, i.e. 'v0.1~234' is preferred over 'v0.1^2~5', meaning that usually following the first parent of a merge results in the best name for its ancestors. So when later we follow the remaining parent(s) of a merge, and reach an already named commit, then we usually find that we can't give that commit a better name, and thus we don't have to visit any of its ancestors again. OTOH, if we were to follow the Nth parent of the merge first, then the name of all its ancestors would include a corresponding '^N'. Those are not the best names for those commits, so when later we reach an already named commit following the first parent of that merge, then we would have to update the name of that commit and the names of all of its ancestors as well. Consequently, we would have to visit many commits several times, resulting in a significant slowdown. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 99 +++++++++++++++++++++++++++++---------------- t/t6120-describe.sh | 2 +- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index fc61d6fa71..a3b796eac4 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -6,6 +6,7 @@ #include "tag.h" #include "refs.h" #include "parse-options.h" +#include "prio-queue.h" #include "sha1-lookup.h" #include "commit-slab.h" @@ -104,49 +105,77 @@ static struct rev_name *create_or_update_name(struct commit *commit, return NULL; } -static void name_rev(struct commit *commit, +static void name_rev(struct commit *start_commit, const char *tip_name, timestamp_t taggerdate, int from_tag) { - struct rev_name *name = get_commit_rev_name(commit); - struct commit_list *parents; - int parent_number = 1; - - for (parents = commit->parents; - parents; - parents = parents->next, parent_number++) { - struct commit *parent = parents->item; - const char *new_name; - int generation, distance; - - parse_commit(parent); - if (parent->date < cutoff) - continue; + struct prio_queue queue; + struct commit *commit; + struct commit **parents_to_queue = NULL; + size_t parents_to_queue_nr, parents_to_queue_alloc = 0; + + memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */ + prio_queue_put(&queue, start_commit); + + while ((commit = prio_queue_get(&queue))) { + struct rev_name *name = get_commit_rev_name(commit); + struct commit_list *parents; + int parent_number = 1; + + parents_to_queue_nr = 0; + + for (parents = commit->parents; + parents; + parents = parents->next, parent_number++) { + struct commit *parent = parents->item; + const char *new_name; + int generation, distance; + + parse_commit(parent); + if (parent->date < cutoff) + continue; - if (parent_number > 1) { - size_t len; + if (parent_number > 1) { + size_t len; + + strip_suffix(name->tip_name, "^0", &len); + if (name->generation > 0) + new_name = xstrfmt("%.*s~%d^%d", + (int)len, + name->tip_name, + name->generation, + parent_number); + else + new_name = xstrfmt("%.*s^%d", (int)len, + name->tip_name, + parent_number); + generation = 0; + distance = name->distance + MERGE_TRAVERSAL_WEIGHT; + } else { + new_name = name->tip_name; + generation = name->generation + 1; + distance = name->distance + 1; + } - strip_suffix(tip_name, "^0", &len); - if (name->generation > 0) - new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name, - name->generation, - parent_number); - else - new_name = xstrfmt("%.*s^%d", (int)len, tip_name, - parent_number); - generation = 0; - distance = name->distance + MERGE_TRAVERSAL_WEIGHT; - } else { - new_name = tip_name; - generation = name->generation + 1; - distance = name->distance + 1; + if (create_or_update_name(parent, new_name, taggerdate, + generation, distance, + from_tag)) { + ALLOC_GROW(parents_to_queue, + parents_to_queue_nr + 1, + parents_to_queue_alloc); + parents_to_queue[parents_to_queue_nr] = parent; + parents_to_queue_nr++; + } } - if (create_or_update_name(parent, new_name, taggerdate, - generation, distance, - from_tag)) - name_rev(parent, new_name, taggerdate, from_tag); + /* The first parent must come out first from the prio_queue */ + while (parents_to_queue_nr) + prio_queue_put(&queue, + parents_to_queue[--parents_to_queue_nr]); } + + clear_prio_queue(&queue); + free(parents_to_queue); } static int subpath_matches(const char *path, const char *filter) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 0d119e9652..09c50f3f04 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -381,7 +381,7 @@ test_expect_success 'describe tag object' ' test_i18ngrep "fatal: test-blob-1 is neither a commit nor blob" actual ' -test_expect_failure ULIMIT_STACK_SIZE 'name-rev works in a deep repo' ' +test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' ' i=1 && while test $i -lt 8000 do From patchwork Tue Nov 12 10:38:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11239033 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E2F6139A for ; Tue, 12 Nov 2019 10:38:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DBC220674 for ; Tue, 12 Nov 2019 10:38:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PGisO+XT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727170AbfKLKis (ORCPT ); Tue, 12 Nov 2019 05:38:48 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35667 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726994AbfKLKiq (ORCPT ); Tue, 12 Nov 2019 05:38:46 -0500 Received: by mail-wm1-f68.google.com with SMTP id 8so2397029wmo.0 for ; Tue, 12 Nov 2019 02:38:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uwz9seY6ydl8LCUkBENexJrsht3CXOCEdyWSV+zSBZ0=; b=PGisO+XTRg87fJd7agU878F9AIMQdZJdQAtOhwDmg7Vbu9hN2UyUMcFKxqJKyGJtZj 6BD/QPmS0F6HaoUno3DNVbcySmHvEGq04pkChZGovwHj+G2mMrPvF4KJgXq8R6Sk/F4g Ypfn4uja5ix0QaBnLBJilSwvTx/fkIszi+D/7PJ7xWYZdW1KUcMqIstL9kHTVSuNxU9K jxXdWRnqDGlqrnrHPsPfhRWW3Cl8P0VCT8iU3V2epTKEL4HI7bIqBJ4bnz10qaZGDiuh EWyVjrrGuVg8L3yd1h/qlmy5pSPbNkNptlYu0q+IGSLkFYXCnaYJTCHDJYCxRAwlJx1z CXmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uwz9seY6ydl8LCUkBENexJrsht3CXOCEdyWSV+zSBZ0=; b=V0ZjwTumV8omaH2RadgMcm4qhwbVzaWXYJMDMa/ogn5iNXqq1e/WAMthPrY1hsl6ra 2d6FsuIod+NOIEgEUHzns0O4r805fJD91u8LSXBp7E0u7XaxtSa8FaLA6qFvkntcM7fa 4qtg0AjeiL0/co220QKAnZc5FLhIM7lfG7AEmXUyRIb1a754M9FoX15WwlyZcPfMWZBN R8tXGxnW11H04YrpYG992jDKXdTnVXuEHxNe1FYpa8xjZqcKYAhskIYqKfMnYgPb/iYn 3Qvc98hjsLePeUASMW92RzOHtt6y+FPhU31Qd4pR0fEbVCJ3OMZ8yUpvYonOBrTQqDWy qULg== X-Gm-Message-State: APjAAAXAcUL/l7pOrZ+ubKdHQ7Pa/1L6PMNWmo9I8eEuukLOeQDw+T4g DoXj89QaKZKo72FK9Crf+Fk= X-Google-Smtp-Source: APXvYqzvuidmEbbOOnB22VNXyFf2MaamKl2kKlXTs628msnHKQS7+E6ZiJn9tL/3sMWAJTuqS41c/g== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr3397932wmc.130.1573555124621; Tue, 12 Nov 2019 02:38:44 -0800 (PST) Received: from localhost.localdomain (x4d0c65ae.dyn.telefonica.de. [77.12.101.174]) by smtp.gmail.com with ESMTPSA id f24sm2313759wmb.37.2019.11.12.02.38.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Nov 2019 02:38:44 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH v2 13/13] name-rev: cleanup name_ref() Date: Tue, 12 Nov 2019 11:38:21 +0100 Message-Id: <20191112103821.30265-14-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.388.gde53c094ea In-Reply-To: <20191112103821.30265-1-szeder.dev@gmail.com> References: <20190919214712.7348-1-szeder.dev@gmail.com> <20191112103821.30265-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Earlier patches in this series moved a couple of conditions from the recursive name_rev() function into its caller name_ref(), for no other reason than to make eliminating the recursion a bit easier to follow. Since the previous patch name_rev() is not recursive anymore, so let's move all those conditions back into name_rev(). Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index a3b796eac4..cc488ee319 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -107,12 +107,26 @@ static struct rev_name *create_or_update_name(struct commit *commit, static void name_rev(struct commit *start_commit, const char *tip_name, timestamp_t taggerdate, - int from_tag) + int from_tag, int deref) { struct prio_queue queue; struct commit *commit; struct commit **parents_to_queue = NULL; size_t parents_to_queue_nr, parents_to_queue_alloc = 0; + char *to_free = NULL; + + parse_commit(start_commit); + if (start_commit->date < cutoff) + return; + + if (deref) + tip_name = to_free = xstrfmt("%s^0", tip_name); + + if (!create_or_update_name(start_commit, tip_name, taggerdate, 0, 0, + from_tag)) { + free(to_free); + return; + } memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */ prio_queue_put(&queue, start_commit); @@ -309,20 +323,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo if (taggerdate == TIME_MAX) taggerdate = commit->date; path = name_ref_abbrev(path, can_abbreviate_output); - if (commit->date >= cutoff) { - const char *tip_name; - char *to_free = NULL; - if (deref) - tip_name = to_free = xstrfmt("%s^0", path); - else - tip_name = xstrdup(path); - if (create_or_update_name(commit, tip_name, taggerdate, - 0, 0, from_tag)) - name_rev(commit, tip_name, taggerdate, - from_tag); - else - free(to_free); - } + name_rev(commit, xstrdup(path), taggerdate, from_tag, deref); } return 0; }