From patchwork Fri Mar 1 17:50:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10835781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A7FE13B5 for ; Fri, 1 Mar 2019 17:50:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECBF930054 for ; Fri, 1 Mar 2019 17:50:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EADD23006F; Fri, 1 Mar 2019 17:50:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F4C230054 for ; Fri, 1 Mar 2019 17:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389456AbfCARul (ORCPT ); Fri, 1 Mar 2019 12:50:41 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40771 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726195AbfCARul (ORCPT ); Fri, 1 Mar 2019 12:50:41 -0500 Received: by mail-wm1-f65.google.com with SMTP id g20so12245470wmh.5 for ; Fri, 01 Mar 2019 09:50: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=gDOHl0/6kUuGmp3187+2GHragFUtmdHA4Tw5glzaRS8=; b=vD0OdiUUJbY4Va8jpXyHv79gvmCBhe1nfGyDVpEPx0N35KbLQf+akHzet+TXnloJcn FgRaDe5yB2iq1s7Dqwu8yjRCCsNwMe0w0eHwyF5Xi+JD0cV0aMpP7lXjTV9hAHzqb9LW +V2gAHgUDM14AHvKFhx4TLPcZ5nNy2jr8OYCz1FC+iXAlG8TNtnHs8xj6SeEiUCqBwRg cB+wcPXN0yEK0r+WIJ92JFzQRNg3xIQzxdtNfjaP43VpQfvW3jhD+HDWV0s7+Hjej0lB lnqX2FV9Hnn6dgP10dYpXmrw570YaX17XMes6OlVQgSclSKEh+sxWPaDG2X/yclkk+J5 wW3w== 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=gDOHl0/6kUuGmp3187+2GHragFUtmdHA4Tw5glzaRS8=; b=c/nvwEj7oqgJhdD6RQjpmzB8iA0NlWXe7wL5F+8devDTpXVo//P1oHEzYAdBpS61oK /YtWjQPAx3b8xaQszMy22LNsLCZzmtyXNVOMirz/bqD5jIHgcqnWT+Pi8AR40FyGG8Xm VNVUhNfVaf74+tiEZSVm5aHwciAkNXP5uuzdsmT/AaV+qpc4WUVNrqZFMr12a3xqEtjj CWRP5xG27ei5VUuoF2BHLdfHORkOJcjkwalTrmpTjxierZDgmWt10sMtsPj974qT+Ul0 cJUjl9MnshoPwlPtZR0Ba+Y4th0OW7ysQqjpn9pPTfK+dIhwyg+z4C2MKlFC9yHg0tdy aPrA== X-Gm-Message-State: AHQUAuYHwS/V4fBIkElh9N1hoH67NoN71YOC2uj5yC1USrIVWkIs2C/D 5qO/lDJObsseq5ykaDVSn0Cqhrdp X-Google-Smtp-Source: AHgI3IZ3FOCHl1Wr0JTN1F5vSTiyfFIEZQhVgx+RYyUqtKL29uWOZ0fm1Co8AkkKn7hl3MeUA4lBjQ== X-Received: by 2002:a05:600c:2115:: with SMTP id u21mr4195194wml.70.1551462638820; Fri, 01 Mar 2019 09:50:38 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-112-206.w86-199.abo.wanadoo.fr. [86.199.35.206]) by smtp.googlemail.com with ESMTPSA id o8sm11672247wma.1.2019.03.01.09.50.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 09:50:38 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Alban Gruin Subject: [RFC PATCH 1/4] name-rev: improve name_rev() memory usage Date: Fri, 1 Mar 2019 18:50:21 +0100 Message-Id: <20190301175024.17337-2-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190301175024.17337-1-alban.gruin@gmail.com> References: <20190301175024.17337-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP name_rev() is a recursive function. For each commit, it allocates the name of its parents, and call itself. A parent may not use a name for multiple reasons, but in any case, the name will not be released. On a repository with a lot of branches, tags, remotes, and commits, it can use more than 2GB of RAM. To improve the situation, name_rev() now returns a boolean to its caller indicating if it can release the name. The caller may free the name if the commit is too old, or if the new name is not better than the current name. There a condition that will always be false here when name_rev() calls itself for the first parent, but it will become useful when name_rev() will stop to name commits that are not mentionned in the stdin buffer. If the current commit should not be named, its parents may have to be, but they may not. In this case, name_rev() will tell to its caller that the current commit and its first parent has not used the name, and that it can be released. However, if the current commit has been named but not its parent, or the reverse, the name will not be released. Signed-off-by: Alban Gruin --- builtin/name-rev.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index f1cb45c227..0719a9388d 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -77,7 +77,7 @@ static int is_better_name(struct rev_name *name, return 0; } -static void name_rev(struct commit *commit, +static int name_rev(struct commit *commit, const char *tip_name, timestamp_t taggerdate, int generation, int distance, int from_tag, int deref) @@ -86,11 +86,12 @@ static void name_rev(struct commit *commit, struct commit_list *parents; int parent_number = 1; char *to_free = NULL; + int free_alloc = 1; parse_commit(commit); if (commit->date < cutoff) - return; + return 1; if (deref) { tip_name = to_free = xstrfmt("%s^0", tip_name); @@ -111,9 +112,10 @@ static void name_rev(struct commit *commit, name->generation = generation; name->distance = distance; name->from_tag = from_tag; + free_alloc = 0; } else { free(to_free); - return; + return 1; } for (parents = commit->parents; @@ -131,15 +133,18 @@ 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, - distance + MERGE_TRAVERSAL_WEIGHT, - from_tag, 0); + if (name_rev(parents->item, new_name, taggerdate, 0, + distance + MERGE_TRAVERSAL_WEIGHT, + from_tag, 0)) + free(new_name); } else { - name_rev(parents->item, tip_name, taggerdate, - generation + 1, distance + 1, - from_tag, 0); + free_alloc &= name_rev(parents->item, tip_name, taggerdate, + generation + 1, distance + 1, + from_tag, 0); } } + + return free_alloc; } static int subpath_matches(const char *path, const char *filter) From patchwork Fri Mar 1 17:50:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10835785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87D101515 for ; Fri, 1 Mar 2019 17:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F823003A for ; Fri, 1 Mar 2019 17:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 745CF3005F; Fri, 1 Mar 2019 17:50:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 109AB2FFCA for ; Fri, 1 Mar 2019 17:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389544AbfCARuo (ORCPT ); Fri, 1 Mar 2019 12:50:44 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33690 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388466AbfCARum (ORCPT ); Fri, 1 Mar 2019 12:50:42 -0500 Received: by mail-wm1-f66.google.com with SMTP id c13so9339643wmb.0 for ; Fri, 01 Mar 2019 09:50: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=vK92IY4EcXeD2VZW3m6ilFyPCJQrxzPLz4K5M53xwT4=; b=ZC242BLcYKgtW8EvOtz/o/v+MZHjc3G87e6WASPAZWfilKXuFjw7Wx/WGhvFc3nXfj Vr24Vp/yYi5x3NMbW8a/XfLtCK3uwmR67m6awFJr3NzdnFBHMw/DfwbEV8ZGYfWylGom HrUXd0l6AZTCKj0Dr3hqCHFydRZYD5XyRlCZP2eYmi1yEvgvdTbmlR5NKA96NTPQiI7w rR6/HlNfSUuxH8yIvTyEGRHyUAP1bu0FEfdFdSxjriVuWaSZLVWr7gZ27ienmxwko+VT NzqZyc1DyaL2hf0RaBk30ONHkC20LfwFZ1P97Ab04O0uiQxrVE7Ou3TLx+KAeCd6xqrG Qaqg== 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=vK92IY4EcXeD2VZW3m6ilFyPCJQrxzPLz4K5M53xwT4=; b=ZFcCXfzL4VUqmTU0Z5o3SsiRVx7kHxNTj2oWk7c9pOPZ/trlJ1SJ/scB9wEBjdVYmm RYkF1VE2lN0TswG4qN3tVW4WELrmMyy4B23arYDqfHXbIZNpVWXPCQyqM+5vwznYf9Nf VlkW/3R4NpD5pBU5NVyyVUsRN1onEpxVGgL5Y5jSghHUi/f5WVO2EQIr8LM/Z6ZKXAQH QXfj9vPVKj8GEQ5smI1Zo5XoS5WsaKkfMQ01KIKUFWKCSDpy2Ks2zW6ZrBaMkRpo78NC GhOvT5jMiwSKCTRh7e2BhCNch6kYgR8qh0ubfLhMGssLt0cG5+hPKDIuk9RO4dO3RTDC DT4A== X-Gm-Message-State: AHQUAubBzUTSxqRxndxQ0AzmR3uWq12dNEDgpT4rMhmaeTUj2qxP8XVU i+x9W01WjleI18q3iYscEZ7zauEm X-Google-Smtp-Source: APXvYqzJxIBRvcoVe+EJRHcrCaybDRQzMn6D/3hpZBPR3o5LDb9iY2qvzn9/PsrviAkBpQ51S+Ling== X-Received: by 2002:a1c:9d94:: with SMTP id g142mr3996999wme.125.1551462640239; Fri, 01 Mar 2019 09:50:40 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-112-206.w86-199.abo.wanadoo.fr. [86.199.35.206]) by smtp.googlemail.com with ESMTPSA id o8sm11672247wma.1.2019.03.01.09.50.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 09:50:39 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Alban Gruin Subject: [RFC PATCH 2/4] commit-list: add a function to check if a commit is in a list Date: Fri, 1 Mar 2019 18:50:22 +0100 Message-Id: <20190301175024.17337-3-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190301175024.17337-1-alban.gruin@gmail.com> References: <20190301175024.17337-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To avoid naming some commits, name_rev() will need to check if a commit is part of a commit list. Signed-off-by: Alban Gruin --- commit.c | 12 ++++++++++++ commit.h | 1 + 2 files changed, 13 insertions(+) diff --git a/commit.c b/commit.c index a5333c7ac6..fcb3e9245f 100644 --- a/commit.c +++ b/commit.c @@ -524,6 +524,18 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list * return new_list; } +int commit_list_contains(const struct commit_list *l, struct commit *commit) +{ + const struct commit_list *item; + + for (item = l; item != NULL; item = item->next) { + if (oideq(&item->item->object.oid, &commit->object.oid)) + return 1; + } + + return 0; +} + unsigned commit_list_count(const struct commit_list *l) { unsigned c = 0; diff --git a/commit.h b/commit.h index 42728c2906..c9df613b0e 100644 --- a/commit.h +++ b/commit.h @@ -165,6 +165,7 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list); struct commit_list **commit_list_append(struct commit *commit, struct commit_list **next); +int commit_list_contains(const struct commit_list *l, struct commit *commit); unsigned commit_list_count(const struct commit_list *l); struct commit_list *commit_list_insert_by_date(struct commit *item, struct commit_list **list); From patchwork Fri Mar 1 17:50:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10835783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 271AE13B5 for ; Fri, 1 Mar 2019 17:50:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1707130057 for ; Fri, 1 Mar 2019 17:50:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 152483006E; Fri, 1 Mar 2019 17:50:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 942C330057 for ; Fri, 1 Mar 2019 17:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389546AbfCARuo (ORCPT ); Fri, 1 Mar 2019 12:50:44 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34198 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726195AbfCARun (ORCPT ); Fri, 1 Mar 2019 12:50:43 -0500 Received: by mail-wr1-f68.google.com with SMTP id f14so26816116wrg.1 for ; Fri, 01 Mar 2019 09:50: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=Cr30SaUaC/WnlTNamd7dxiUXhnMVGmG9Br79AwTUbgA=; b=hIa/c6VeQ/0QjXHqQgdZcPK61XdLIjJV9/Q10bDKQ4iOpuQMcBGWYiPdlsLjqyr+VF XNOucSRm1BfzVt7njNxvXpiaPnuWgW4t2bsiUnNtKSDgy/QypLt9mFd4SxyLqDL21YcA Wu0cf+wVKX/iOlD5o/O2RmpItrH4Iz3AAlHXw8mLpnZspc48pU8XKpu3iOMtHaIHCO93 0leSr4yZcKBPVDJ2OpCcnXpY7fKR5T4u67qzW6mVI1wZNJxh6VcY1JsIvGTSl2yWfP+A T5rvWodkW6CyQemxja43j1oyZvaY9mINZvNWgaNMb/WMJp/gB+bytI7/eDwPNlO+Qqmb SuvQ== 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=Cr30SaUaC/WnlTNamd7dxiUXhnMVGmG9Br79AwTUbgA=; b=F7HmUMEWHAF1nAuShtgWxNFOBgOVH1N2Ci+SyEl01X94hP/eK05fJx8YBj6y2+A41a /trjTBHj5QEzMI1x+WkAoHoFQhhAw1hnnI6yTnp379VHwcs9t7sWKJ28mQla5zbWK1UD lLeqF0qlyReBkpFsD7CXg1eeY60mYhvGq6EWTcO227YGQs7QwubUmsfJWGkqRmPCPByc WnR5LRPOM/HFUOHWdZwmjjOQrMv2Vs9HD3pIrhNjOSMHMyJKMhvFzapW9uX0/9jJD59V 2G6cKPKbSAHmLpH8ajZPMjZEBsKajFU0+zPJlw8ZNyJdXgjIXFGjSn3H2Of/jnaVKuuZ T30w== X-Gm-Message-State: APjAAAXCKFM5Kpqx9kKcDzfRXX71dX8meLr5Y+EaPqMIxOQyM+zuFl/r Yfa/DtuFXSuXdunn/eIOIKAZ11yx X-Google-Smtp-Source: APXvYqzHyrO1nGNVACvhvGczZMJt2wDYYurWGZhXXb1z/KgaEoc3ZRtryl0oN4eAPE2JO9N+1HJQnA== X-Received: by 2002:a05:6000:1287:: with SMTP id f7mr4490070wrx.203.1551462641801; Fri, 01 Mar 2019 09:50:41 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-112-206.w86-199.abo.wanadoo.fr. [86.199.35.206]) by smtp.googlemail.com with ESMTPSA id o8sm11672247wma.1.2019.03.01.09.50.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 09:50:41 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Alban Gruin Subject: [RFC PATCH 3/4] name-rev: check if a commit should be named before naming it Date: Fri, 1 Mar 2019 18:50:23 +0100 Message-Id: <20190301175024.17337-4-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190301175024.17337-1-alban.gruin@gmail.com> References: <20190301175024.17337-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Until now, name_rev() named every commit it found, even it the name would ultimately be unused. This makes name_rev() take a commit_list and check if the commit it wants to name is part of the list. If it is, the commit is named, and name_rev() signals to its caller that the name should not be freed. If it is not, the commit is left unnamed. In this case, the name can still be used by the first descendant of this commit (or one of its descendants). Signed-off-by: Alban Gruin --- builtin/name-rev.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 0719a9388d..2f89ed50a1 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -80,7 +80,7 @@ static int is_better_name(struct rev_name *name, static int name_rev(struct commit *commit, const char *tip_name, timestamp_t taggerdate, int generation, int distance, int from_tag, - int deref) + int deref, struct commit_list *commits) { struct rev_name *name = get_commit_rev_name(commit); struct commit_list *parents; @@ -107,12 +107,18 @@ static int name_rev(struct commit *commit, } else if (is_better_name(name, tip_name, taggerdate, generation, distance, from_tag)) { copy_data: - name->tip_name = tip_name; + if (commit_list_contains(commits, commit) || + commit_list_count(commits) == 0) { + name->tip_name = tip_name; + free_alloc = 0; + } else { + name->tip_name = NULL; + } + name->taggerdate = taggerdate; name->generation = generation; name->distance = distance; name->from_tag = from_tag; - free_alloc = 0; } else { free(to_free); return 1; @@ -135,12 +141,12 @@ static int name_rev(struct commit *commit, if (name_rev(parents->item, new_name, taggerdate, 0, distance + MERGE_TRAVERSAL_WEIGHT, - from_tag, 0)) + from_tag, 0, commits)) free(new_name); } else { free_alloc &= name_rev(parents->item, tip_name, taggerdate, generation + 1, distance + 1, - from_tag, 0); + from_tag, 0, commits); } } @@ -279,7 +285,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo taggerdate = ((struct commit *)o)->date; path = name_ref_abbrev(path, can_abbreviate_output); name_rev(commit, xstrdup(path), taggerdate, 0, 0, - from_tag, deref); + from_tag, deref, NULL); } return 0; } From patchwork Fri Mar 1 17:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10835787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BD601515 for ; Fri, 1 Mar 2019 17:50:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A66A30069 for ; Fri, 1 Mar 2019 17:50:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78D733006A; Fri, 1 Mar 2019 17:50:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90BB030070 for ; Fri, 1 Mar 2019 17:50:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389548AbfCARuq (ORCPT ); Fri, 1 Mar 2019 12:50:46 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40249 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389525AbfCARup (ORCPT ); Fri, 1 Mar 2019 12:50:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id q1so26823667wrp.7 for ; Fri, 01 Mar 2019 09:50: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=uD2/GGmxvDd8L/mIQPckKtUmJpahwkmq1sK8JXYTvJQ=; b=KKA82mA7aZWz+/nAAKv6P1v3/GVk7asY0kXIjzgS/u2VY1H0YED89vf5LTZevk0mCq M2Ldhm63+Q9c6ky1mA3LaFnqfyWPyP2yhLq+DT+ds+qjChDU8zhMYLP+iPtozCc6h67P jwdX+A/Atbibj/NCDfJDpNnJ2Tizm64rrTNdWXzLdZipZayNAC+lHNKrUVi75C4TGnEm 1C4PGgTd2+eZAKNONtXDcl6fVpuLMt0vpy0zA5VSF3K3G6GfxmrydxuHrtkKGRbebuPM MEe8jepMLBeZiJLvcpsDeUVEBLMmXocdhNCdZekosq0Djjt1WVtLtjfj4aLfNLWkee8Y sK1w== 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=uD2/GGmxvDd8L/mIQPckKtUmJpahwkmq1sK8JXYTvJQ=; b=deFRwjvAocrSxT+hc6PUiJ3F53TEiuZDc3qvfDOp/G6YsAfGLNkBkjoHX6XiMxUcwP GH0myQk/iQYN+QExwlrl064KHHRDjPoJcFhBxF+w5hcqkIhE+ecVRVuqarmzCKBF+llf 84xANQT/4f+KkT4mVpOdQtOLRla3SmzocJmB4VO+uhxIKncvApx9Bstg17EKGtDmq8Jj 8fy2nnrlO6iczeSYp3Su2DKXTX0/PE1/29g7UJX6qwSNzYHeKhoKZL/s/AFyKe/MxWKN 1NfUHX1cREOha70B2Lcz5535hcUsGWtXISHMZ9r4wj+aAu+WZ/OGyktmeMLLWAlOOt7K LRVg== X-Gm-Message-State: APjAAAVyFXVimxPp22kVC9I/R5mBjeo3moSiuDPW9zH9+dc6sZFDJW0Y bAMbaD7aHaorKZBTv6sAL8EVjamK X-Google-Smtp-Source: APXvYqx80UGaY8dBEJcFTVIs4XHHl3bMVRL6L+lz7K2cSjlCkwCiUZWRxmhvvj2pAjU8QU+MiKddiw== X-Received: by 2002:a5d:6983:: with SMTP id g3mr4422346wru.286.1551462643334; Fri, 01 Mar 2019 09:50:43 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-112-206.w86-199.abo.wanadoo.fr. [86.199.35.206]) by smtp.googlemail.com with ESMTPSA id o8sm11672247wma.1.2019.03.01.09.50.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 09:50:42 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Alban Gruin Subject: [RFC PATCH 4/4] =?utf-8?q?name-rev=3A_avoid_naming_from_a_ref_if_it?= =?utf-8?q?=E2=80=99s_not_a_descendant_of_any_commit?= Date: Fri, 1 Mar 2019 18:50:24 +0100 Message-Id: <20190301175024.17337-5-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190301175024.17337-1-alban.gruin@gmail.com> References: <20190301175024.17337-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A ref may not be the descendant of all of the commits mentionned in stdin. In this case, we want to avoid naming its parents. To do this, find_commits_in_strbuf() is created. It returns a raw list of all the commits that have been found in the input buffer. ishex() is converted to an inlined function. Then, we add a raw list of commits in the name_ref_data structure, and call find_commits_in_strbuf() before for_each_ref() if the user wants name-ref to process stdin. Then, for each ref, we check if the reachable subset of this commit list is empty or not. If it is, we do not call name_rev(), so we don’t name its parents. The code dealing with stdin after calling for_each_ref() is no longer needed as we already read it. name_rev_line() is renamed name_rev_buf() to reflect its new role better. Signed-off-by: Alban Gruin --- builtin/name-rev.c | 91 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 15 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 2f89ed50a1..f5860f5625 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -8,6 +8,7 @@ #include "parse-options.h" #include "sha1-lookup.h" #include "commit-slab.h" +#include "commit-reach.h" #define CUTOFF_DATE_SLOP 86400 /* one day */ @@ -183,6 +184,8 @@ struct name_ref_data { int name_only; struct string_list ref_filters; struct string_list exclude_filters; + struct commit **commits; + int commits_nr; }; static struct tip_table { @@ -279,13 +282,21 @@ 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; + struct commit_list *reachable_commits = NULL; int from_tag = starts_with(path, "refs/tags/"); - if (taggerdate == TIME_MAX) - taggerdate = ((struct commit *)o)->date; - path = name_ref_abbrev(path, can_abbreviate_output); - name_rev(commit, xstrdup(path), taggerdate, 0, 0, - from_tag, deref, NULL); + reachable_commits = get_reachable_subset(&commit, 1, + data->commits, data->commits_nr, 0); + + if (commit_list_count(reachable_commits) > 0 || data->commits_nr == 0) { + if (taggerdate == TIME_MAX) + taggerdate = ((struct commit *)o)->date; + path = name_ref_abbrev(path, can_abbreviate_output); + name_rev(commit, xstrdup(path), taggerdate, 0, 0, + from_tag, deref, reachable_commits); + } + + free_commit_list(reachable_commits); } return 0; } @@ -369,13 +380,53 @@ static char const * const name_rev_usage[] = { NULL }; -static void name_rev_line(char *p, struct name_ref_data *data) +static inline int ishex(char p) +{ + return isdigit(p) || (p >= 'a' && p <= 'f'); +} + +static struct commit **find_commits_in_strbuf(struct strbuf *buf, int *count) +{ + int forty = 0; + char *p; + struct commit **commits = NULL; + + *count = 0; + + for (p = buf->buf; *p; p++) { + if (!ishex(*p)) + forty = 0; + else if (++forty == GIT_SHA1_HEXSZ && + !ishex(*(p+1))) { + struct object_id oid; + char c = *(p+1); + + *(p+1) = 0; + if (!get_oid(p - (GIT_SHA1_HEXSZ -1), &oid)) { + struct object *o = + parse_object(the_repository, &oid); + + if (o && o->type == OBJ_COMMIT) { + struct commit *c = (struct commit *) o; + + REALLOC_ARRAY(commits, (*count) + 1); + commits[(*count)++] = c; + set_commit_rev_name(c, NULL); + } + } + *(p+1) = c; + } + } + + return commits; +} + +static void name_rev_buf(char *p, struct name_ref_data *data) { struct strbuf buf = STRBUF_INIT; int forty = 0; char *p_start; for (p_start = p; *p; p++) { -#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f')) if (!ishex(*p)) forty = 0; else if (++forty == GIT_SHA1_HEXSZ && @@ -419,7 +470,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) { struct object_array revs = OBJECT_ARRAY_INIT; int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0; - struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP }; + struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP, NULL, 0 }; struct option opts[] = { OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")), OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")), @@ -496,20 +547,27 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) if (cutoff) cutoff = cutoff - CUTOFF_DATE_SLOP; - for_each_ref(name_ref, &data); if (transform_stdin) { - char buffer[2048]; + struct strbuf buf = STRBUF_INIT; - while (!feof(stdin)) { - char *p = fgets(buffer, sizeof(buffer), stdin); - if (!p) - break; - name_rev_line(p, &data); + strbuf_read(&buf, STDIN_FILENO, 0); + data.commits = find_commits_in_strbuf(&buf, &data.commits_nr); + + if (data.commits_nr > 0) { + for_each_ref(name_ref, &data); + name_rev_buf(buf.buf, &data); + } else { + fwrite(buf.buf, buf.len, 1, stdout); } + + free(data.commits); + strbuf_release(&buf); } else if (all) { int i, max; + for_each_ref(name_ref, &data); + max = get_max_object_index(); for (i = 0; i < max; i++) { struct object *obj = get_indexed_object(i); @@ -520,6 +578,9 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) } } else { int i; + + for_each_ref(name_ref, &data); + for (i = 0; i < revs.nr; i++) show_name(revs.objects[i].item, revs.objects[i].name, always, allow_undefined, data.name_only);