From patchwork Mon Dec 9 11:52:45 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: 11279219 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 43C581575 for ; Mon, 9 Dec 2019 11:53:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2245F2080D for ; Mon, 9 Dec 2019 11:53:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QPml6zdH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727628AbfLILxG (ORCPT ); Mon, 9 Dec 2019 06:53:06 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54146 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfLILxG (ORCPT ); Mon, 9 Dec 2019 06:53:06 -0500 Received: by mail-wm1-f66.google.com with SMTP id n9so14639894wmd.3 for ; Mon, 09 Dec 2019 03:53:04 -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=9mupzvCgS/xIzZPP2Or6CXweNF6BFj867V7VzBIJkKU=; b=QPml6zdHPGOZBV3I3B3e2SX6NCn+6ugK5N+rROaXcNihnJCBUiiiI9ov9FXXgZnYpj 5mulcZoHpqQynVrEiWTKuqN4Er9rTP+6+0JHoTODMB2NG9+p0t1XkC7wfdhYEzkc9H4h q0DdQflESTsLo9fssDYZqe15ycL9zU/VebQZtx2QLVbMa0xpiucgJXxm4OVhuVv8fhvH 2UKT2/zI74UsgWqgUWPUPixhsQvQfQw34hz/x2MBFmEJydX/M4ceUkAlS+8AFV6njeFF LU+nNxHDVFerikXltMpkfNAa1sqEb1ImucgJgItCrese+IUdALejEyxTDkcf0SUsO0Fe yeYg== 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=9mupzvCgS/xIzZPP2Or6CXweNF6BFj867V7VzBIJkKU=; b=C1K5T6H2IGzh8ROn3UTNBh2GtvF44H1Xy39Z7znRDoxnn5BLSm9lNijUqcYMbaDcxh H903oPnkKv5D4u1cpHSpAFumnQtyeSX24dYLB1bNxSpB/QzZwgbJvs9Ozg6AbaCEZMIy bOSGezSsmi9dPx6cmF9gQMhm9mBX3YaCDKZjquK7DtQpgzeNcN4YqiVokVkeK5v0v+UV 5wBID21Q95kg2cAK01+k+TpvXg7vepwLtJF1FlASGQoBkSnaU/KG111JrLKh6OlxzBDI kUM1TIIOcH7BqQqsvuowBj0rJpJP858ydVn2QcpWGOgpFptA1IfDU4iQk8iSL4Mt6x9o 3sjA== X-Gm-Message-State: APjAAAUgQLsSS9VJ2EhDRIgvB6AOhroqvEiZ2M5OUuTIvwPnO5xbzCGi QwFzDQOpdJ3MZEGXGDHJb6A= X-Google-Smtp-Source: APXvYqzvD96xAc7HbuprGuFK7NUz/mRSFwg2fuG4DHnS0mO9BVMcIh7f49XiFEarkQQ6R7Cqdpip/Q== X-Received: by 2002:a7b:c0d8:: with SMTP id s24mr25690016wmh.30.1575892384246; Mon, 09 Dec 2019 03:53:04 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:03 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 01/14] t6120-describe: correct test repo history graph in comment Date: Mon, 9 Dec 2019 12:52:45 +0100 Message-Id: <20191209115258.9281-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:46 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: 11279221 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 8A82E13B6 for ; Mon, 9 Dec 2019 11:53:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 698022080D for ; Mon, 9 Dec 2019 11:53:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uBuVsG7O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727634AbfLILxI (ORCPT ); Mon, 9 Dec 2019 06:53:08 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42634 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbfLILxH (ORCPT ); Mon, 9 Dec 2019 06:53:07 -0500 Received: by mail-wr1-f65.google.com with SMTP id a15so15827197wrf.9 for ; Mon, 09 Dec 2019 03:53:05 -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=Q8NNLvrdN7Pb6LZo+9rN6z+GLFhV814LS67TSzQ/mco=; b=uBuVsG7O9jVODe6WC9wAyZcSWkuW4EYxeJKduAXuvQg/XqyklFKLwjNdqToF0ODwAp 2CYyZY8RjpfoacUWQVKw00529ArpCJ79m0joHtliEXmt3Z7uJntImGNnwWgq2Ua6sLpm 6f/xWwLWVpW3+0vzx7ba+7GjmwNsifvXaB5Zeh16jSj+rjs23AkOutZNqZSUDWWa9fmt 2tHK6A7dZ6EtjTMOT9GNR6JY1TovpS+yRzRxWIiImcPte2KCKsYkl3/4hsvoNQnfuvy5 lrNIF+wkRbwQWeRHExoXCXgVPnbkuBrwRohGXMHIDpQsnQtJIkGS1FNlYjrGkEk6bxNF 8TdA== 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=Q8NNLvrdN7Pb6LZo+9rN6z+GLFhV814LS67TSzQ/mco=; b=n5jB0PrBfzJZB3Bzo9wAAvcp2DcQSywBc7TBcjYwGL1wZe7/4PgVonrbaCEczn/Hpm S3Z2mgbD4HT/HCAe3KShZOmOpkU3X3vKTUEl35GSE6Mn4i9PERSXDEGVL8ohf2fZsGIA iddymQhRQr3QPJsE0ZcWMv9UVFZ48852K6kqbVXz0DOb968/HwTxnN/rUCNiqphOhsOT /qInP6S9/0VBz9+e1AtgOcuzkOoWn9zKjTngroYyB2ZFYHY1RCarqJi7uj2izL9yOfRn zJYIPQZ3STgFRtpU66kT+D+Luf3oKGz467ohbLG2xgsoSDOf9tJKoXwQM0djSHmUadT/ RcOQ== X-Gm-Message-State: APjAAAUDfTUhmaKWPHW6wd7zM6MPVMDaiL24Uosq42D0DQ7FmRl27WzN 5i5f7IeNWOKQJw5dxcm5K+Wky0Nk X-Google-Smtp-Source: APXvYqzgr19CSHKJkz1vDwNJrOSVN23bkiAAJVT2QF64t3YBI9htspIgaSFd8tQJny6k0VRcAFX/nQ== X-Received: by 2002:a5d:6652:: with SMTP id f18mr1803902wrw.246.1575892385404; Mon, 09 Dec 2019 03:53:05 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:04 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 02/14] t6120-describe: modernize the 'check_describe' helper Date: Mon, 9 Dec 2019 12:52:46 +0100 Message-Id: <20191209115258.9281-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 describe' 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 Mon Dec 9 11:52:47 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: 11279225 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 913D613B6 for ; Mon, 9 Dec 2019 11:53:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FA1D207FF for ; Mon, 9 Dec 2019 11:53:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pa+5Kqe6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727639AbfLILxK (ORCPT ); Mon, 9 Dec 2019 06:53:10 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36587 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfLILxI (ORCPT ); Mon, 9 Dec 2019 06:53:08 -0500 Received: by mail-wr1-f66.google.com with SMTP id z3so15885447wru.3 for ; Mon, 09 Dec 2019 03:53:07 -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=l4eaUWryvIegZRPbqmP4igzBURxzCXYI3SXQluzufq4=; b=Pa+5Kqe6IRZsvCddkg3eyaWfb4zVEddGVN1FEcCndoEvxfkeNAYvkfdOGX6XCo9wIv a5uThRSAqustbWmyGVSL6gbp8LZJ3HGDbFoJ4zqe/8KvUXTpItKpaPzCOeOBAQDJgf45 FyoO+jvjZ5nUSHMUw8hk9LsYbMz8YjGSynJaGOzUdVW0MTxxDbqg2HjbEWIadABwgSPg 4at5rRQsG2UL3mjM9+oVn+MzNmRque43LfpJG8Qwn1VBkijtIwe1ZtgzLCI+KpcaaCBY OfBjvLVTtuTffk4azsXf6tzOWoJl8bHW8CqgmFzhMjV86vHf54KoI2b25469HYrXCbL+ P2MA== 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=l4eaUWryvIegZRPbqmP4igzBURxzCXYI3SXQluzufq4=; b=UlmQbuNa2lztwupWiUtefLDUnQoVQnONkfJKd0aF4yHgrBulxzQgcASYiXX6KhLxhs KTWzJnnFeuVNSf5H3h5vvkiNcJkbzZFS1MWYW1HA/t80actSFq2uCG1gGAXRqKVOSZ7A +Sn1dc9On1vKNICJassB8z/YVsWaD2gcWpdv0mIPoHsu9v9wQg4Ta13wIYJDiJZtBD3c W97ec71EHF9SmxUsmiYrhJWmdDqW9RU4fH+HtpblLE/te16QalidlRWnhcxSKxV90VDs 4SCFrleRStAiK7bm8vpj2ezTwWdiA7o4WDWa+RMBDR/s3+KvZhAX7s7mx70tZZjg4+6r eN3w== X-Gm-Message-State: APjAAAWpRU4qadEDx5gdB/90OlwAsoMzYZnBg0Qj9nHrA6IM3KSiu5eZ 3oWyEO+c1KaYWwO6VgiCvbA= X-Google-Smtp-Source: APXvYqyEsQqddWlyzX1tQv9NO2DsOJKOy6httJ89cOmOI+X8LMBuASNOFStsvlUo2hIMH20YFcus3Q== X-Received: by 2002:a5d:480b:: with SMTP id l11mr1730344wrq.129.1575892386575; Mon, 09 Dec 2019 03:53:06 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:05 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 03/14] name-rev: use strbuf_strip_suffix() in get_rev_name() Date: Mon, 9 Dec 2019 12:52:47 +0100 Message-Id: <20191209115258.9281-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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. Signed-off-by: René Scharfe Signed-off-by: SZEDER Gábor --- 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 Mon Dec 9 11:52:48 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: 11279227 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 DD88B13B6 for ; Mon, 9 Dec 2019 11:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE11020828 for ; Mon, 9 Dec 2019 11:53:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N0fjLYgn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727640AbfLILxL (ORCPT ); Mon, 9 Dec 2019 06:53:11 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52845 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727637AbfLILxJ (ORCPT ); Mon, 9 Dec 2019 06:53:09 -0500 Received: by mail-wm1-f66.google.com with SMTP id p9so15138464wmc.2 for ; Mon, 09 Dec 2019 03:53:08 -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=WRCuS8uoGdooWawEks4A6ADDNXlbiIEL6gyZ7gENGQQ=; b=N0fjLYgniiHtCz+NxfGQmOP+VkBI/Zh4GZupKh61vBxIsV+MBGBcMbmAEOSmMHkE8I XjX+7Wp0iSUwemDbBC6/slfEGJPqQWWAvb+ZEmVTmolcHPQA4E8XHNfrtQJCJyC9seA5 HGeyaCslHk6Z9GZFOnp/LvpOidiuf5BP3RZmsepC7agvjjg4lfFBJZDOLyddeDcW3zXN QY6rOGFtH0ivCmlgTn38l3iFA9LCFoKfZEyKmQyY5M5GHYzsvUmMKZZQf3k4HYtu311k mF6nDPeC4fOcZqvK6KZBkUwDl3gSu8j0Rn8jHNiO3auXa+KuBqeioltQ+du52pkysRPG 5ItA== 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=WRCuS8uoGdooWawEks4A6ADDNXlbiIEL6gyZ7gENGQQ=; b=G71RvFqWMnnOIdepO9HGJZuW8OfjhflvzUF6cqII8d1VqQdQ0mo+2yOJRNziRJ/elx YZBsiW51MKdW70TNGBZtSpsKN1CX9wFxLg4zzGDJ8pm/Y7YR8L760yogT4BGvs62rp8Q sHfFvfuNZqvGYa29lxNM3EIPk127H1pfNsCEC509eRVW7VZV9SUP6QcPGGYs+IghMdnN ITYofjPd3sFrzMvbSEDgm5fybL30H8n4o4WFUvsbXEc7lgouWpNhUbHQWc2KU4Mkbzja Zqi36sKWfCK9KaEBBDO3WZI/pNq5+FFqefSK/y/vCmxbf3k1W18DNGBMkgjRcvztKLP/ GHdQ== X-Gm-Message-State: APjAAAUXzE7xGoH8UpnExNYdS04DqF5s+f41NKsdwluUJsBJz/XoN7Hv 43KFK/NL4zpO0AQQdcVl2FI= X-Google-Smtp-Source: APXvYqzrQuvjUCcl5+esy4ROfHXXsvNwBGn7R0R2ihrCTiyQL/OX2HeQUmXm2a7Unr1JyRAYTd3qNg== X-Received: by 2002:a1c:a70e:: with SMTP id q14mr24217037wme.142.1575892387640; Mon, 09 Dec 2019 03:53:07 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:07 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 04/14] name-rev: avoid unnecessary cast in name_ref() Date: Mon, 9 Dec 2019 12:52:48 +0100 Message-Id: <20191209115258.9281-5-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 @@ -272,7 +272,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo 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 Mon Dec 9 11:52:49 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: 11279229 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 14923930 for ; Mon, 9 Dec 2019 11:53:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E956F20866 for ; Mon, 9 Dec 2019 11:53:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b+++/GdJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727643AbfLILxM (ORCPT ); Mon, 9 Dec 2019 06:53:12 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36421 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbfLILxK (ORCPT ); Mon, 9 Dec 2019 06:53:10 -0500 Received: by mail-wm1-f65.google.com with SMTP id p17so14604210wma.1 for ; Mon, 09 Dec 2019 03:53:09 -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=ntQIdsWuGW1GM27W+NVe76XWcYgjKNaO6G8Cw8nRNoE=; b=b+++/GdJXCVeIky8LNE0rP0zlaFLClYMp4zi7Mz+ixxeC0zAhiEJgueeJU76A1EaoN yp25z7NtYfHfYdXWroIeQ55N0c9EyJYCwUxhSMVl4ei3v390saO8BQuOaBzf89y5A7vK TDa3TXsj0vE2ooUzWbjHy6g8e5VPBewONSpb7SApp2ALA30IWigMbXH+JwkyrZpsoTd3 xJgsuAQEGtU5/2EKN2iJglObw02E7e8qzcdUYv4MKC7EHx2rqgyEMhYnVVzp1XeBx8eV sENSipb13FHueL9YSriUWLy9kOceo4W+SzaqJonLup/q/5nn+bTT5pd74ZwtQN4amapw /7xA== 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=ntQIdsWuGW1GM27W+NVe76XWcYgjKNaO6G8Cw8nRNoE=; b=HsOfprUsOF17a2kHQirN1nkc2AbtKP3DhZS18xl6XQMGOgoHTF1zrTChFKhcXCBKw4 5KSB0v34KB/pcJGVIzarVXfoF03/1W6XmaPAnWUIXgDsBq97kv0FLceOMn8asVBIoVld M1vnFjDDWwJRtnWvQMWLmP9MGh7jbTfsnFCgv2ioAtKrAWHRSWcIAD0k3MOWszwOUA5R 4aqeeST2TXGx7uSfGKVQl2pMc4xa2mhGykz56K71F/caVfim+HybMbU1nizF3AGBSj+i m5N2xSntPWWDNx6PvDX2XNQsCPe2Ea62OPaBZOYKHI7fBOkswkM8T18Mgj5kpHzPRlTS RbJg== X-Gm-Message-State: APjAAAVO05iwlThC3kCyp0wxv9XlTrdzKOPHZn6KSf3MXbIoQbzNLbr+ u3vzuUN8r1/lYbhVgFd8otg= X-Google-Smtp-Source: APXvYqy8xsPByZKzQP7ZvL1fIc8RdJWxKwEYFj3tR/gVbXQZwgUuTXjvXLpTq1VyS8WjmycEs+zupQ== X-Received: by 2002:a05:600c:2254:: with SMTP id a20mr24656878wmm.97.1575892388660; Mon, 09 Dec 2019 03:53:08 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:08 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 05/14] name-rev: use sizeof(*ptr) instead of sizeof(type) in allocation Date: Mon, 9 Dec 2019 12:52:49 +0100 Message-Id: <20191209115258.9281-6-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:50 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: 11279233 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 09BD713B6 for ; Mon, 9 Dec 2019 11:53:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC121207FF for ; Mon, 9 Dec 2019 11:53:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="r3hzY9uj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbfLILxO (ORCPT ); Mon, 9 Dec 2019 06:53:14 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36424 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfLILxM (ORCPT ); Mon, 9 Dec 2019 06:53:12 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so14604287wma.1 for ; Mon, 09 Dec 2019 03:53:10 -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=4Pbe5KQ85ZLxENN2+z/4SBlB5jH4XSS0gS13sv4wgVU=; b=r3hzY9ujj7+UydULxq38KTphDSVmKN5gG9G3RsIxoU1SF+WlHmR8XrKukkpY6oLZTW elz6t/M4kl73uhzyaVmaHjEKCKrT7g4vSUx+wfM8PS5+ZzvQ5Mbhrvd6Ejx9g0nn2r6+ XcJQCgER9/SBzo2SmZYLzt1fNE9iRTfB2mWOMPlMsDuiR2QpLPkvuKyy47HDa4ZneE/w pAIJryyDmQBCG9xTYraZ8eISH050P7Ddb3fCcAs29Zlt3513MajjHIHbaUwL/cC4puqx ATivAHCe4Z9Vbis6xeZCeg5NsEBZnrBsdCmIsqBdaaloELeDNyyoAhb7Tc6BRYeyCL00 kPRQ== 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=4Pbe5KQ85ZLxENN2+z/4SBlB5jH4XSS0gS13sv4wgVU=; b=tMnnnDyt++VnEr8UjFIj/05WiRIaHSXar3hdttI3g+2sCJhBXKm0QDFh3NrACTFXlT a2L6jtWCE1bao8h6TynK+ulgojgLLkMDnFER1Zgw/PCGbFSkD7P3m2yRMzVIbFHCtDP+ TJ1wuymZHvIZMuox1+sxGBTFJydOJ1fPKVyk872taFWplT0hEdiLbuw/s1vFS9mGHn/H kxten+8k/povsXy7NLAQ4CGZ/a6HNQNjkNNkDhg++3eCYdHa/l7HuAwEvARStRqa5Txe ChBLr+JUEYqlHQK19CobM5LXK82w6oNfxy2kVFk9LZXDR7+NWGNtOgD0zTqE/fJIZjVo ozZQ== X-Gm-Message-State: APjAAAUhudMJ7ZEsnE3D+h3w/04lXXsCGbEaaXc0WUBTSVJiEvVxVaTt mbutiQG1M9GCcnX4wLZdIXg= X-Google-Smtp-Source: APXvYqwXt298g+8y5AIuNmZ6qMhISi6vn54zETt8NYZ9WCscuA9PkdJHUJA0Xfzqf3aPbzn72nvPEw== X-Received: by 2002:a1c:4483:: with SMTP id r125mr23841987wma.97.1575892389802; Mon, 09 Dec 2019 03:53:09 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:09 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 06/14] t6120: add a test to cover inner conditions in 'git name-rev's name_rev() Date: Mon, 9 Dec 2019 12:52:50 +0100 Message-Id: <20191209115258.9281-7-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:51 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: 11279231 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 756A313B6 for ; Mon, 9 Dec 2019 11:53:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5406E2080D for ; Mon, 9 Dec 2019 11:53:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DroHumxQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727646AbfLILxN (ORCPT ); Mon, 9 Dec 2019 06:53:13 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40395 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727629AbfLILxM (ORCPT ); Mon, 9 Dec 2019 06:53:12 -0500 Received: by mail-wr1-f65.google.com with SMTP id c14so15855918wrn.7 for ; Mon, 09 Dec 2019 03:53:11 -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=QrX7df9gsdQ60K203c9+tqg6YksYfzuqMXfI1+OFi+o=; b=DroHumxQjM+OcIw5h0oobHBnXWadLdmpBD2Knxj/ifCVrOaH+E00lhVhCgNtNz+LYY iMPVIb6Rk3oJyTHDwWX31X0mJHZPMrIqzCbFPtHrtH0VOrjNOMdY8vpowijGP09EkIhi jw0ykpahME7WZ0DVDPDeZ3fd2pl6Sp9jp6PCbeojUjUxOs/lunfHqomtoD1q4A6o9mkl Jpa5rQx2cKKWNaBFszIESpe50XX7G/t11g5zrY9LB4qyzMQIQ7Ruv6xzr57cHNu0+ORJ neCW5QJE9JhktKSmr1JzHubYrVPMe00RhEUCvqsg7Hv+NGdTsU0ssdPY4YA+b081Xuux glKQ== 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=QrX7df9gsdQ60K203c9+tqg6YksYfzuqMXfI1+OFi+o=; b=ti260no/PSOCObRB/TT9UXFg0RNt5YuZduXHRW8M5R/gYBc+LDkjGlYI7ggSeZpjo0 r8dTyH6C5JV40sQzOSX2whnoEmS9TSVlk0sHFmX3sZs138A59/yZ0OUeCqUN7adDtXBC WA8dBCJ29/oLS0wrawxHAKguKO7wD7osGDe0T80O/q1anyauWCvFD3iEWBqHiLeYXUlE ThHW1blfYq51WTmJ/OjW63kCMaWWNsO3dpLb3BKsim6YI1PsXzmxbbjEhfvAg/7tGVPF /GrtzZwZ6MizScf/D2pPL0L4LOZ72vhr0hnzVJX0pr8EGIJDDKl+R9yBQsS3Nrvua1PR 6vFQ== X-Gm-Message-State: APjAAAVourcSPVXptCOKg3xElIIW+cJz2DR1+Dx4XoaboQ1JnmZacs5K VnF1ZsWAuAPqznQAW38Ds/6ddVpI X-Google-Smtp-Source: APXvYqxpvoovbKoxwkQykhaQmuBZZP37vPVn2d3ekm8/JmxSfOeiVrcOyzNlQobyW3iEkaLvPz3lvA== X-Received: by 2002:a5d:6748:: with SMTP id l8mr1799023wrw.188.1575892391018; Mon, 09 Dec 2019 03:53:11 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:10 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 07/14] name-rev: extract creating/updating a 'struct name_rev' into a helper Date: Mon, 9 Dec 2019 12:52:51 +0100 Message-Id: <20191209115258.9281-8-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:52 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: 11279235 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 F22A3930 for ; Mon, 9 Dec 2019 11:53:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D07682080D for ; Mon, 9 Dec 2019 11:53:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iredq4DH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727663AbfLILxR (ORCPT ); Mon, 9 Dec 2019 06:53:17 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:47059 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbfLILxO (ORCPT ); Mon, 9 Dec 2019 06:53:14 -0500 Received: by mail-wr1-f66.google.com with SMTP id z7so15769687wrl.13 for ; Mon, 09 Dec 2019 03:53:12 -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=4fq45NdxYaon4kle3U5fa42nDQgIm2uBropBbY6Ewro=; b=iredq4DHqDUKb3EnfigyohSiixs+JJy/FrRPsPmyUkPSaFXa83FqFD9BkuM5BNZMrO 9UBahZ/St9goH+1Wn2gkKzDMFRWYn0ihqqqu5kDVwlMBIwoeeRo3Q29nHoa6GfTrjvc0 yEE9tJzS/C5TMCkU7V7TRo0vowjY7E04nLyE0cfL4no3LPt1qR+U4/hjhuzD4Q5+tq/L GQ0YmHlWE9Fq0D41qQfudk+Sn+vC9wDLr6ChJl+GcuJi++zDGoMXKNH5exbZuCM35ard aA1oAVx9KWPaWWagk1rnyx0m3dC5POlkmARsRmDXKaUXpJlT3CqYz9vmS0XtRn5EmRrl CIGw== 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=4fq45NdxYaon4kle3U5fa42nDQgIm2uBropBbY6Ewro=; b=oRrcAyzduc53b9+MbcaYJRZQFOwSnFY40gzq4aDIeLxlg6B4W39AP39F2ZbY2fmHfE yeFygpACC+bqTej8MnKZep8FKMxG/KIuVUthW35giSEL4GglCYgGcMUmkubpGhoQqc9h dyS8qNMPT3HGd39F5O5O7D03QcYCkh1OXKi5KeHRRC5IS1mRzcjXvJvcXm3eU9AVjPrG YcoZDiDesub1O6p0OpAq92iAirDpoCDjyatb3n/VnQaejhv+Kck+/w6etzfym6EU+vXU f1iaYL8aHAZucNR5rL3WhuWPr/xY21bJW5xui+O6hgeTOrIMiUNWFuOwlrsRxJVtsXr4 pvpA== X-Gm-Message-State: APjAAAWKU6ZgGtamUimRrl0NhjevS3NX0suiEM1bN2/M5ZkRkKR0fn38 VwaeTZSrwni7xkNdTHOXyYg= X-Google-Smtp-Source: APXvYqxW9A7+7z99LyY/xMMQXWVtgj2Ww9GP1vP1AYdP+dc220d65lg+tgahCE5OlQ4ozNwyITcskA== X-Received: by 2002:adf:dd46:: with SMTP id u6mr1760998wrm.13.1575892392091; Mon, 09 Dec 2019 03:53:12 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:11 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 08/14] name-rev: pull out deref handling from the recursion Date: Mon, 9 Dec 2019 12:52:52 +0100 Message-Id: <20191209115258.9281-9-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:53 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: 11279243 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 AD6AE930 for ; Mon, 9 Dec 2019 11:53:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BE77207FF for ; Mon, 9 Dec 2019 11:53:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l9tTEV8G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727653AbfLILxQ (ORCPT ); Mon, 9 Dec 2019 06:53:16 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39282 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727649AbfLILxP (ORCPT ); Mon, 9 Dec 2019 06:53:15 -0500 Received: by mail-wm1-f65.google.com with SMTP id s14so14592628wmh.4 for ; Mon, 09 Dec 2019 03:53:14 -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=U6oOWlxTlg4up0uHsTc+h8GvlFSt0/cOc0x63zl6BM4=; b=l9tTEV8G40Z6p6/E/LDnJqKEPehdwgaO/K11SJpagdtXr838402yTJpnwyLmG7mcnQ G2znq1XM7FG5H2KJXBhriEJHH8ILsWsehRU+iTNRYM/jiZWddJdRDZDttnEFmH07bhce qXUHirxkZGuqIICuq5BVernzkPySHA367iPoB7tsNLc8r/7eLICblDea5eDP80ULvEum OkKi9BLXamXSgUlVi1CmvFSy2Fsz7Cl/YlSv7zG9OrFZkBNJoLRsg+ZQs0h19IcjR8x/ EjGHpGIE+olLpZglSd1hLF0FR7yJkisHpGR4n+ZLWYPA8xp6AypCnLKD+tOXL2xIV3I3 DK3A== 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=U6oOWlxTlg4up0uHsTc+h8GvlFSt0/cOc0x63zl6BM4=; b=bqsFgAva1edRNbbAAAjbAhV1bOYC6B/CaX/Q6aZCnE11RCGHqkSUKq0SyjSudFJ3g/ sw17ULlwcrp83owdgms+X1HTT9J+5/wMsYD4I/+KmOLud1UgRqFPe4ZyKdXYZHaTh3dL LvVUBnCLIbmtuE2GXp3chDYcX82koQcPWGzKvCPor6qRcJUxAg27qx4K8EFVmF+960e3 wBRG/CdzqtTiCvTErSKjP3rTeYaeRKRuRvmV4Vz4Gb1B7fgSulfmS2Ed/jgOKIojxEwS 29DAX/VS0hc5QFJw95zQGYmkfe52rIumNavBVsWX6fEUh19gcmqcjIQSHyjoOEGPnAF+ GZsg== X-Gm-Message-State: APjAAAXIEYuRd4F7g6YO7jmOZEM+J7CK92A5xjUwfhzMgq+B9HHg9EKb S7nIH5IC0KG0Icf9tAX6rOo= X-Google-Smtp-Source: APXvYqwNrYmYuxYAS+3WvljN0fKA9ZAohqaZb/8I9+E7lG2RYRQdPuoAVrGx6yYw825GiKlpNKNNcw== X-Received: by 2002:a1c:7306:: with SMTP id d6mr24812741wmb.164.1575892393294; Mon, 09 Dec 2019 03:53:13 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:12 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 09/14] name-rev: restructure parsing commits and applying date cutoff Date: Mon, 9 Dec 2019 12:52:53 +0100 Message-Id: <20191209115258.9281-10-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:54 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: 11279241 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 01A0813B6 for ; Mon, 9 Dec 2019 11:53:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D4119207FF for ; Mon, 9 Dec 2019 11:53:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hIiZOAdC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727667AbfLILxS (ORCPT ); Mon, 9 Dec 2019 06:53:18 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34353 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfLILxQ (ORCPT ); Mon, 9 Dec 2019 06:53:16 -0500 Received: by mail-wm1-f68.google.com with SMTP id f4so15257487wmj.1 for ; Mon, 09 Dec 2019 03:53:15 -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=FbC/uT9GE3FJSp0WaMFk5f3MwjiD6eA2B0INBs3ezTU=; b=hIiZOAdC7I56/Q4He5ziQ36oGXCK5jNPRt/ki+VKSFdJ1XX2ZUtgnzHIMqQY+DpTcK GV/ZWb+qfKZyYKzzEX8jtrTXquxMFapagL4m48AdEYVXKdy6U9Hx8FlHQP4qvJXbKAPr FzxQZfu+5m81tu4k0dZ+iz7ZlgfjVHDaenlOzoiYrpFsXg4wXSCf7krXsTEcK75RXzLs kWSy/VmzIyYP3LATXdnmUrxsggsObF55QZzHe1WbGIBCTOqHjChO6WFyFHNEozZa/1CM bf7VtP8zauZmb7zn5nE1UkP+QdfY8gSLqtDxlKzf1b6Win8YtbmCVcC5s0IVC/RaI64v cB4g== 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=FbC/uT9GE3FJSp0WaMFk5f3MwjiD6eA2B0INBs3ezTU=; b=leVowneaGttm0Aqei8TozkXyvvnQCpGQ1GQWjrSOmJAX0qgef8ZEYwckedv49kCOir CCcBKUbL1oiRxEExpbOHrn7BxKedxnwVjDo1WP/44j5pkVeUHUMN4sjBKtBz02YHHXI/ 3ImeNE5OuyrD0VrNCGSMg3MCmXKaAE8EA86ZOyBcYE3W9itr2M08C88q16g5Dm5g2r1C 6BMyIU56r0TAGvKJWcb1Cbwj4n3wJM+A54MbPEigjJLatgtL4OFkzHdCLANlG7pupm5s 01CBfm85mMK8kSjR3PWPSwEUvTLyrA6j8ssMlncVbrr5lVZi7LoeSt/dXe7Sq1beUXv2 bkDQ== X-Gm-Message-State: APjAAAWeTRRcxedn6sfqcxoPU5/wj2sP6axmECDxsnzJiefklHEPP/wj P96dJKzw5B54W4AuxC6KrOM= X-Google-Smtp-Source: APXvYqwRUDkhbSru2jPcjZI4loT8Inyx7nkuVQ8h485qgRewc590lh8Nr6+E6aRFJFtk++fK7BpPkg== X-Received: by 2002:a05:600c:219a:: with SMTP id e26mr26225863wme.42.1575892394607; Mon, 09 Dec 2019 03:53:14 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:14 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 10/14] name-rev: restructure creating/updating 'struct rev_name' instances Date: Mon, 9 Dec 2019 12:52:54 +0100 Message-Id: <20191209115258.9281-11-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:55 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: 11279237 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 DC0A4930 for ; Mon, 9 Dec 2019 11:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA8252080D for ; Mon, 9 Dec 2019 11:53:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cHlAvQJo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727669AbfLILxT (ORCPT ); Mon, 9 Dec 2019 06:53:19 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38757 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727438AbfLILxR (ORCPT ); Mon, 9 Dec 2019 06:53:17 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so14598470wmi.3 for ; Mon, 09 Dec 2019 03:53:16 -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=iMJEqnTL4WSK2zA9sO26NTWdBZ8asZt1BiAJxEElZBY=; b=cHlAvQJotGBaLw9kdrSBlXHRAxjWLgxjVt0thlhlVr5fKjUflG1npk1XeJ2RRxFa3f +EOBR3KDmdKHRIh7k1Mm/fwi4f01YH09cjCzhoM3vIQ5yDEwc/lnmrmMX8IZiGrUHGbo 5UI39Cch8AwCKikGjH+FjH9/93Smb2F4krUVXBT0aPsusrIKqXHaM28lBVJvHGAKLL5F bsQKQ1E+pGuMMOCoVGv09YLAundnPw89LzD0LGXCZrI7+ZQw8PcUd7OdPQQI48pK2KeK LXmTPAyel6mdCdLewEKA/R4GwraLPocz1sMSRTnA+fxqMVpG99danmhb0bSNGUS994P3 p5RQ== 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=iMJEqnTL4WSK2zA9sO26NTWdBZ8asZt1BiAJxEElZBY=; b=duVpWtaACosqTSlz9LX3nV6sscDqDNHvgSLfGoQPcVeNUx15x22y1SMjZsSK9G+rxS sR5YFuE7VSR+pl1h9pVyV71/lLcmufKqAs8VR5uX25JY9PkwFzDZ6ovOlH0ZVZ9ghZtq bLvu9A0i9DULFWs1mGsQbfMmcUJnalRt3EKVVzGPyeVWdl79pbm7LMjK48bOXUqCod+j eKRokw9+HcwfAOmGH2FBeXGXGdn4STC/Sz+bKTjvWOiyKREbZi1nQZJ87trrW+NhjxCD Vf2dz0zJgpXifJq1Tgd1g/dXH+xIlILpmycuTbZWQ/MF7h6NVOjaNLbbqLdb5eoUDGvz 5DZw== X-Gm-Message-State: APjAAAVzm548jTFfc1Bd1E/0SEGXj+fO9AZAdJ8t29m0ojzj+9ObegkA BlPmU8rqAD1iYxLMv3PjA2M= X-Google-Smtp-Source: APXvYqzhHKxx0j4D9xPplZTzSalZ55GsDA2vmgsa+3k1YK0C6gdiJQhcvNiy3Sa2M/l6vNW1L6LcPA== X-Received: by 2002:a7b:cc6a:: with SMTP id n10mr25472976wmj.170.1575892395804; Mon, 09 Dec 2019 03:53:15 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:15 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 11/14] name-rev: drop name_rev()'s 'generation' and 'distance' parameters Date: Mon, 9 Dec 2019 12:52:55 +0100 Message-Id: <20191209115258.9281-12-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 Mon Dec 9 11:52:56 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: 11279239 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 D169C13B6 for ; Mon, 9 Dec 2019 11:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1223207FF for ; Mon, 9 Dec 2019 11:53:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V0RdxPpi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727678AbfLILxT (ORCPT ); Mon, 9 Dec 2019 06:53:19 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36435 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbfLILxS (ORCPT ); Mon, 9 Dec 2019 06:53:18 -0500 Received: by mail-wm1-f65.google.com with SMTP id p17so14604613wma.1 for ; Mon, 09 Dec 2019 03:53:17 -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=zOj7vpzDhBq5DQ1tXOq0lbHYgZrUg4SALkvy59BjkZs=; b=V0RdxPpiKZQ89TDnt4mbWszGxgtHMIcdvTrH4uERTJ6qv4FREE8ptSWkelVwpNOG9R st+hkmzoicaqvEnxo3MHgx27TR9UYM+Rw6vrIUFMag7Ig9jOmh2Iu6nY6QnE9J5R2AD1 Jea1wF5hxRCNsAR+NryIkJxqfsqGb1nhXNGOywFCdweHc8VF/s6aX1CsOfm7VnYKoKYM T8oJ4YN5VE0j8JwefA9HfcCeec/QwdUWhsMW+1/ThNbhDFg5rvkvRXinCA/Ni7xUvz6v 44vrt5E8J+Z6PZsHnzSJbRjAr/iabUqIUtbjmSNoc8DwlTcW/QFPPXpfKNEZ7IWDovzr rpVQ== 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=zOj7vpzDhBq5DQ1tXOq0lbHYgZrUg4SALkvy59BjkZs=; b=HwA89n/PlcQ/F8B6CpMYm2kAGfKs8MVszV3ZNUJBKpKbbsitHBNHolNfU1AAbGHava 9GAdC4d6Ka/pgPQuPCo3EDtcz+wJitW1IONJu8tu3UCDkLorSkr8i6CJYmG8BpQ7rcWn y0tAOZa4OSr1KAvK/VOcIjaza8ta14LS6gZZEwcPe4KawwJj4dQzTiMndCW6BSovB16A s7TRuqbs7kbmTtTbIFvi+jjuR/paHVDUcvN9S1bGadPiQtO1OrQAdOup2c9gueO/1rjr OFsKQTTJsN62IH4k1FrjEHfCReNTXKZ6ZMZCW8N3GPOWPDv0JzWp9w7Y3KbmIml+Eovv edIw== X-Gm-Message-State: APjAAAWM85Ld1k3TX3Uu3lIGsEQvAZkx2o9N/uTW2eTTe3zOuVNhL4Bx g996L4RsU7ox7CPoFWnC5E5iCfLz X-Google-Smtp-Source: APXvYqyV4tuvb/f1XBbhFtY4iChZxT5x91u50hbQBAVWVYFV4wNKD8f6HpqQBQtZKjGPgIhgZ+XtMg== X-Received: by 2002:a7b:c4cc:: with SMTP id g12mr25072189wmk.68.1575892396842; Mon, 09 Dec 2019 03:53:16 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:16 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 12/14] name-rev: use 'name->tip_name' instead of 'tip_name' Date: Mon, 9 Dec 2019 12:52:56 +0100 Message-Id: <20191209115258.9281-13-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 value of 'name_rev()'s 'tip_name' parameter from the 'struct rev_name' associated with the commit as well. So let's use 'name->tip_name' instead, which makes the patch eliminating the recursion of name_rev() a bit easier to follow. Note that at this point we could drop the 'tip_name' parameter as well, but that parameter will be necessary later, after the recursion is eliminated. Signed-off-by: SZEDER Gábor --- builtin/name-rev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index fc61d6fa71..6c1e6e9868 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -126,18 +126,21 @@ static void name_rev(struct commit *commit, if (parent_number > 1) { size_t len; - strip_suffix(tip_name, "^0", &len); + strip_suffix(name->tip_name, "^0", &len); if (name->generation > 0) - new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name, + new_name = xstrfmt("%.*s~%d^%d", + (int)len, + name->tip_name, name->generation, parent_number); else - new_name = xstrfmt("%.*s^%d", (int)len, tip_name, + new_name = xstrfmt("%.*s^%d", (int)len, + name->tip_name, parent_number); generation = 0; distance = name->distance + MERGE_TRAVERSAL_WEIGHT; } else { - new_name = tip_name; + new_name = name->tip_name; generation = name->generation + 1; distance = name->distance + 1; } From patchwork Mon Dec 9 11:52:57 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: 11279247 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 570071575 for ; Mon, 9 Dec 2019 11:53:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C9252080D for ; Mon, 9 Dec 2019 11:53:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fZPHPje5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbfLILxX (ORCPT ); Mon, 9 Dec 2019 06:53:23 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36603 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727668AbfLILxU (ORCPT ); Mon, 9 Dec 2019 06:53:20 -0500 Received: by mail-wr1-f67.google.com with SMTP id z3so15885998wru.3 for ; Mon, 09 Dec 2019 03:53:18 -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=KKap58d6zGDQ810DMkxdFRpP455mOwAiVfiW/L45Ahs=; b=fZPHPje5FchM2gf4Qhnuuu73MW3AWU1wFBUF7C40DwDsd7jeAM7i0Y+qLObPlm6aK3 iecXBJF/pIGKu0DBW30OEFcBIpdc/KZJRDiWjyXbO9OpvgSVRnuXL4B0Rihgg6/J3lXZ quv67R2PRlMUKQ64FJA5ZBVyb0dHA6S7cjSa9/2cA/32aodzZm1mMXF9KVb+PCB1QTzw mYsqqBdSymUhrniEaGLj2bWWbuDLYvxN+ikgUtku8auTPIlfrGkvxfMooijCyhQB/pk6 gpoVaG6AePe09ldHReY9dj6FxypdM7U3sgC0ifw+xBgnbGYrzrc6cd8ijMaF0G5VAH9K iV4g== 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=KKap58d6zGDQ810DMkxdFRpP455mOwAiVfiW/L45Ahs=; b=uGMAvj0w+FqamIY8yZaWfEGRWtY54R0AjVn73WnWa3tJjow9bSMH84Z82iKUleaeoY vMKvTId1WazoiHnDVYIYll9ClqA7v/lEfEhoe/EGgjdd455nBDfT/PR23AfHkhOpjDFc k1zBn5frDklmwg4DsP+FTi4yvxLxOYDVlEW6SsQVmYwVS6OY+bQBYdw15iIfbL10G13P KsxYF4J10gspF/jObjHKMD7HGLYb04ykZ383TcJoLef5grUrA77XVy+RKnD8+GFD8BTF f3ceT6FAxnxkbdAm6JMTOQDKNCB/1s7+MS7pkNTa7LVDxZGy+p6AltySQsa0xPmsGw9a hblg== X-Gm-Message-State: APjAAAUhsNb26bXABwWeuEzocaeu8GXh1dZl0TNRl0WgdskQJP7tzhH1 oJSnRzYuwRZXWzgHLfzbPOU= X-Google-Smtp-Source: APXvYqzHPU2BpFUJOTiqrOAreyWLD6mI+EprJPUtdtIQBFYve66D9V7A9Hw/NaiouCFSqJhRaR+Snw== X-Received: by 2002:adf:f58a:: with SMTP id f10mr1767879wro.105.1575892397890; Mon, 09 Dec 2019 03:53:17 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:17 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 13/14] name-rev: eliminate recursion in name_rev() Date: Mon, 9 Dec 2019 12:52:57 +0100 Message-Id: <20191209115258.9281-14-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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 | 102 +++++++++++++++++++++++++++----------------- t/t6120-describe.sh | 2 +- 2 files changed, 65 insertions(+), 39 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 6c1e6e9868..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,52 +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(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; + 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 Mon Dec 9 11:52:58 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: 11279245 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 E571013B6 for ; Mon, 9 Dec 2019 11:53:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C350F2077B for ; Mon, 9 Dec 2019 11:53:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mn0KZJJN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727681AbfLILxY (ORCPT ); Mon, 9 Dec 2019 06:53:24 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34853 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727603AbfLILxV (ORCPT ); Mon, 9 Dec 2019 06:53:21 -0500 Received: by mail-wm1-f66.google.com with SMTP id c20so13119883wmb.0 for ; Mon, 09 Dec 2019 03:53:19 -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=4mqg2+FA9ZvHSuvUO+QD6JNk/hSkJWff+fRlUvx2gXY=; b=mn0KZJJNHj/RT521PybHEowV39JdH6PM1y9tMpvA66rccXJmZrqZvdILxbwvM18PL7 z8M869DuyD3GsqypcT9s8SuFzFipYES32yGzhcqaWNxsa7/++YXVkDaqguyx85NDR8/y vrxU4Mu/6pVajkviDk6KDAS3yRbCifwJXpwG4FZy+MLwnGQ4e9HibxPxLuk/RyDg77I/ IvHcWFHw9zN9VAnEbeLkTblJLIS8ATThykcJERLWSNg/nUSUhwf3IuzcTFnOyOi79AUO k3OGapQcgWTmcv5rJEDM8GadoRbzLx8rLuy0Vksp6C1HM2ZExyvrr4JO8hQsMDZTP1Iv u0hw== 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=4mqg2+FA9ZvHSuvUO+QD6JNk/hSkJWff+fRlUvx2gXY=; b=JA5CGSnMuo6AJoX5K2Og9DUj0c34hwDv1k0CyfpIDUOeL3J40pGzAHmBkdUDkyjwiT +MFTJbtucbLcvQO96U+bL8V1hsF34DrxmmxVxfKWDEvqQCUNz2mEXYOMWGNrDOAU+Vz1 9mzNVRHp0UFJcx2frPaS7PxyFYrFhUGot15Bbqod0YcvwkwrB59zeQmkiPtfiM/n2Pks sJBQ+pqTU72PBl54qi055I7g5hXuHocxh6JP6LU4UakDj5SyT2j/9ZgPqhAKbqvIxjN1 JmCUtFWh6w1hhkKwNzfOKOmzwDK9YtnvIwU8P/DGFaAQ49snWTsX59GaMGFHjyEBWcUA KDLQ== X-Gm-Message-State: APjAAAU20mAeGXCMc99vY2GYsH0H78DTDCOlpq1T2ok/C9GOiOsa124J inXsjlZK429t1ZPsO75jfdI= X-Google-Smtp-Source: APXvYqzGkDvOF84m8qNViTOeqvHJF3eu6P2KsVFpfT6tvImwqKyoA7S7n8g70X5h2lu/O2KCSvBOKg== X-Received: by 2002:a1c:1dc4:: with SMTP id d187mr25029704wmd.46.1575892399119; Mon, 09 Dec 2019 03:53:19 -0800 (PST) Received: from localhost.localdomain (x4db55b9c.dyn.telefonica.de. [77.181.91.156]) by smtp.gmail.com with ESMTPSA id k8sm27239621wrl.3.2019.12.09.03.53.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 03:53:18 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Derrick Stolee , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jonathan Tan , git@vger.kernel.org, =?utf-8?q?SZE?= =?utf-8?q?DER_G=C3=A1bor?= Subject: [PATCH v3 14/14] name-rev: cleanup name_ref() Date: Mon, 9 Dec 2019 12:52:58 +0100 Message-Id: <20191209115258.9281-15-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.801.g241c134b8d In-Reply-To: <20191209115258.9281-1-szeder.dev@gmail.com> References: <20191112103821.30265-1-szeder.dev@gmail.com> <20191209115258.9281-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; }