From patchwork Sat Jan 5 22:46:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 10749403 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 B86C091E for ; Sat, 5 Jan 2019 22:47:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A396C2871A for ; Sat, 5 Jan 2019 22:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90DD72880A; Sat, 5 Jan 2019 22:47:02 +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,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 0227B2871A for ; Sat, 5 Jan 2019 22:47:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726367AbfAEWq7 (ORCPT ); Sat, 5 Jan 2019 17:46:59 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:44035 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbfAEWq7 (ORCPT ); Sat, 5 Jan 2019 17:46:59 -0500 Received: by mail-lj1-f193.google.com with SMTP id k19-v6so35197482lji.11 for ; Sat, 05 Jan 2019 14:46:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:from:date:message-id:subject:to:cc; bh=e4gomOeXI6V04oR4HjVYf5xn1bX+xmNEU4zCwU/QQrc=; b=BWMbcNXYIlh5piTNP0dEqE88QA2GC/jF3wcbOK628KPqHM778Cp/UVLVgzzDtrE59n DvrYnIcwyZt9ByZRgKhYl51BGV2MGJ0li9VwOxv44vqgMcRzTIdPGNsWUjmDhzsmODbV NZQJugfUekEAsu+8geaMIou48FKXCZx5XUX38= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=e4gomOeXI6V04oR4HjVYf5xn1bX+xmNEU4zCwU/QQrc=; b=q8vd1Yl8CGYttId0A3Nk7hZsc282mo+p7VXa+RD8gePAlAPYB/oTqftnF6hJLBVNsJ 349RhFCeP6lbbRXo3NX2kvFzB+TgG6Brrj/avVlHjp1CGBrzQPe1PvwrmoV5H5fauqyb oQxXGiAXBhtRlzfCLnGMW3VhiMgDPgDshgblKr8ThmJv3URyTe+nBnS/lxhBJhVM+DF6 XXngicz3yPt1sWKmV39p6eyNa4oikP0pRWiHd8845dB5oedrsJBAwWbhmPMVrRS2D8uk wkTGMLdP+kSKL+W3LRTr1xdJH06Gt273UeFgef9RlaXvZdAOw27Mi/pIVEpbRw6V51Jg I2Sw== X-Gm-Message-State: AJcUuke2MMoZLxe8rBcoP/vfJ5bgvYPQgVkuGVx42nHYVphwOaN1r2Yi BSgFLlPdOYorSMmkRIVMuxoTAEyH5Ac= X-Google-Smtp-Source: AFSGD/WMe+YJ7X3/4bOnxT7LuSwIZNsdCHsUjkfWPpA17a0T8dmLB/jE98MbfvyB3rwx0a2cb/2xbQ== X-Received: by 2002:a2e:4442:: with SMTP id r63-v6mr31527135lja.79.1546728415682; Sat, 05 Jan 2019 14:46:55 -0800 (PST) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id f20-v6sm13015053ljk.33.2019.01.05.14.46.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Jan 2019 14:46:54 -0800 (PST) Received: by mail-lj1-f169.google.com with SMTP id c19-v6so35248008lja.5 for ; Sat, 05 Jan 2019 14:46:54 -0800 (PST) X-Received: by 2002:a2e:2416:: with SMTP id k22-v6mr8331822ljk.80.1546728414355; Sat, 05 Jan 2019 14:46:54 -0800 (PST) MIME-Version: 1.0 From: Linus Torvalds Date: Sat, 5 Jan 2019 14:46:37 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Make "git log --count" work like "git rev-list" To: Junio Hamano C Cc: Git List Mailing Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a ridiculous patch. And I understand entirely if nobody else cares, because I don't think anybody else has ever even noticed. It turns out that I still use "git rev-list" outside of some hard-core scripting for one silly reason: the linux-next statistics are all about non-merge commits, and so to do a rough comparison with linux-next, I do git rev-list --count --no-merges v4.20.. to get an approximate idea of how much I've merged compared to what is in linux-next. (See also http://neuling.org/linux-next-size.html for the graphical view of it all, even though it looks a bit odd right now because of how linux-next wasn't being updated over the holidats and right at the 4.19 release). Anyway, I've occasionally thought to myself that I should just fix "git log" to learn that too, so that I wouldn't have to type out "git rev-list". Because "git log" does actually take the "--count" argument, it just doesn't honor it. This is that patch. Linus From e3bc5387404bcefbd86081fbc82a93fc5c9efa99 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 5 Jan 2019 14:39:41 -0800 Subject: [PATCH] git log: honor the '--count' argument "git log" is really the human-facing useful command that long long ago used to scripted around "git rev-list". In fact, if you want to use the old scripting code, you can still approximate "git log" with something like git rev-list --pretty HEAD | less but you'd be silly to do that, since "git log" is clearly a much nicer interface and is what people should use. Except I find myself still occasionally using "git rev-list" simply because "git log" doesn't do one odd little quirk: commit counting. So if you want to count the number of non-merge commits since the last kernel version, you'd have to do something like git rev-list --count --no-merges v4.20.. because while "git log" actually silently _accepts_ the "--count" argument, it doesn't do anything about it. This little patch copies the rev-list code for counting to "git log". Signed-off-by: Linus Torvalds --- builtin/log.c | 11 +++++++++++ log-tree.c | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index e8e51068bd..62bef62f8a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -411,6 +411,17 @@ static int cmd_log_walk(struct rev_info *rev) if (close_file) fclose(rev->diffopt.file); + if (rev->count) { + if (rev->left_right && rev->cherry_mark) + printf("%d\t%d\t%d\n", rev->count_left, rev->count_right, rev->count_same); + else if (rev->left_right) + printf("%d\t%d\n", rev->count_left, rev->count_right); + else if (rev->cherry_mark) + printf("%d\t%d\n", rev->count_left + rev->count_right, rev->count_same); + else + printf("%d\n", rev->count_left + rev->count_right); + } + if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF && rev->diffopt.flags.check_failed) { return 02; diff --git a/log-tree.c b/log-tree.c index 10680c139e..49ff485320 100644 --- a/log-tree.c +++ b/log-tree.c @@ -913,6 +913,16 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) struct log_info log; int shown, close_file = opt->diffopt.close_file; + if (opt->count) { + if (commit->object.flags & PATCHSAME) + opt->count_same++; + else if (commit->object.flags & SYMMETRIC_LEFT) + opt->count_left++; + else + opt->count_right++; + return 1; + } + log.commit = commit; log.parent = NULL; opt->loginfo = &log; -- 2.20.1.101.g60ba6df0c4