From patchwork Wed Jun 26 23:50:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018553 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 D717F1398 for ; Wed, 26 Jun 2019 23:51:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6046289E9 for ; Wed, 26 Jun 2019 23:51:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9B0C28A03; Wed, 26 Jun 2019 23:51:00 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 969CB289E9 for ; Wed, 26 Jun 2019 23:50:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726537AbfFZXu6 (ORCPT ); Wed, 26 Jun 2019 19:50:58 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:38442 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXu6 (ORCPT ); Wed, 26 Jun 2019 19:50:58 -0400 Received: by mail-qk1-f201.google.com with SMTP id n190so384979qkd.5 for ; Wed, 26 Jun 2019 16:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sen6ZwQgv3aWuTbmAbGUnYrLEp4BCiEIQlsg2Gfb4qM=; b=PQBwy0CfLiyn5JA0lKCKQgpWLa5A5VZ9ZQmGDZBnzcWLFba06dcEyEj8/pgMNlT0EV GZz4drKTQ6eweATeNnjGR+IVdAC2kWkQ2KsnieaveCTF/shfiN0uABNOjMJtvHJLts7m cNAyT2bODneT7ItEAGeLZQHZ5nqd+ZjYZSBqV7bgxAZbd3SMpccwauxSc5PG6vaWY2Fy WfhZidqVdRnI68uWv8ltgtap91ac+klXL/QhJSWb/2vVkijarzLpzcha6Bisj1qj07iq zf6SyQAGSq/aI93geotM8EIGw98TMiO9uceygxGuyeizuxP4jmk3Wjtv3V4O5rlWJ8Ki Gaaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sen6ZwQgv3aWuTbmAbGUnYrLEp4BCiEIQlsg2Gfb4qM=; b=Z+NTqqfBlXXEvZtceSAg5zQZjCgSfH3yUqm/LKpb2sxfwujJVpZUYSaRUR2seKjojY MhokEbVW1EGIqd+RY10CMv+EGgooUzQLWib1glh+e1bj1Gpsz2qWPxbcyNb50Ok2H97u JozSXhd78vQXQ3B6Wqfh0EFY9OPvPBtRS53IbSCVe9u4rB3dSJU5HZFAIz871nCVMjVR gLThoaFKxvM2wrhVgsqNgDX+gTaadOX88y0RQ7CAH9crQ+3ldNSC1QJL+wFGyzHeP/66 7g4Rxfw16cztb+5+WGYc7ZTvFyyWlOnSD+zyjyMIcWt1NqxBYm8hG/yh04e1U+fJtbr6 OiCQ== X-Gm-Message-State: APjAAAX29B5sd1FUVCLH5wSqGd/63g5f/s8agYNqgmyM59GLuuitAvTC ZyN1LOa6/J9bUyU2Fzd5bLsjEd3j1k77eYmqcQ6XsQVzdah/GKf7H5jOxS+Stt61ruaNAX4UVYQ jBHt+pQfuGGME03gtEjrFI7YcFqV5sba0OXlx/d3vLlrWVP48Bqs/9g1PUQuCyeZU+CR4Vf51MA == X-Google-Smtp-Source: APXvYqwytdcU6y7z0C0FMxxC+hEtzEhQyQiaIuSsgQLyn2nPKHTxx69Vw7GTONOvktgl/ppAgGJq8H5O6yyAh1ZDTpY= X-Received: by 2002:aed:3bb5:: with SMTP id r50mr512754qte.89.1561593057089; Wed, 26 Jun 2019 16:50:57 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:20 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 01/13] walken: add infrastructure for revwalk demo From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Begin to add scaffolding for `git walken`, a toy command which we will teach to perform a number of revision walks, in order to demonstrate the mechanics of revision walking for developers new to the Git project. This commit is the beginning of an educational series which correspond to the tutorial in Documentation/MyFirstRevWalk.txt. Signed-off-by: Emily Shaffer Change-Id: I64297621919412f54701e111366e99c4ef0feae3 --- Makefile | 1 + builtin.h | 1 + builtin/walken.c | 13 +++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 builtin/walken.c diff --git a/Makefile b/Makefile index f58bf14c7b..5bac1dbf8d 100644 --- a/Makefile +++ b/Makefile @@ -1137,6 +1137,7 @@ BUILTIN_OBJS += builtin/var.o BUILTIN_OBJS += builtin/verify-commit.o BUILTIN_OBJS += builtin/verify-pack.o BUILTIN_OBJS += builtin/verify-tag.o +BUILTIN_OBJS += builtin/walken.o BUILTIN_OBJS += builtin/worktree.o BUILTIN_OBJS += builtin/write-tree.o diff --git a/builtin.h b/builtin.h index ec7e0954c4..c919736c36 100644 --- a/builtin.h +++ b/builtin.h @@ -242,6 +242,7 @@ int cmd_var(int argc, const char **argv, const char *prefix); int cmd_verify_commit(int argc, const char **argv, const char *prefix); int cmd_verify_tag(int argc, const char **argv, const char *prefix); int cmd_version(int argc, const char **argv, const char *prefix); +int cmd_walken(int argc, const char **argv, const char *prefix); int cmd_whatchanged(int argc, const char **argv, const char *prefix); int cmd_worktree(int argc, const char **argv, const char *prefix); int cmd_write_tree(int argc, const char **argv, const char *prefix); diff --git a/builtin/walken.c b/builtin/walken.c new file mode 100644 index 0000000000..d2772a0e8f --- /dev/null +++ b/builtin/walken.c @@ -0,0 +1,13 @@ +/* + * "git walken" + * + * Part of the "My First Revision Walk" tutorial. + */ + +#include "builtin.h" + +int cmd_walken(int argc, const char **argv, const char *prefix) +{ + trace_printf(_("cmd_walken incoming...\n")); + return 0; +} From patchwork Wed Jun 26 23:50:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018555 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 6A408112C for ; Wed, 26 Jun 2019 23:51:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B511289E9 for ; Wed, 26 Jun 2019 23:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F9E428A03; Wed, 26 Jun 2019 23:51: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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 EE71B289E9 for ; Wed, 26 Jun 2019 23:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726572AbfFZXvB (ORCPT ); Wed, 26 Jun 2019 19:51:01 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:52146 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvA (ORCPT ); Wed, 26 Jun 2019 19:51:00 -0400 Received: by mail-pf1-f201.google.com with SMTP id 145so261223pfv.18 for ; Wed, 26 Jun 2019 16:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=EpJK3nyRD/4VLb+i1cnUJMMJENYDbLDvzuMVALAaAd8=; b=JN6IUx+Qd23Tl1JLVmjtgptfkxdc21h8pxi9kChh6YPLKqYR7lm7SGguPakM0Sn1AH Gmm+AT9oiVS2u+PekQzZ3ESrSlA22ap78ix2J0E5zgv2dXloI1cFt2aFU9cqu3fyvvDv MQKNIqaPYv2dRUMDAOBo6BLWoLYLTIK35sn+MJtHPbZJEiKynVWTFZkHW4CQvOmcObaF 6dtCiQrpPl2ZZFs9qmEoI4tSnhbxlYiDIurVQK0prQEVQFNUWjN0XxfJzv9RIc1hO8XG 8rebFmOsh0ZZehzfqhKaHqM5ULDE3lrmmqt1yQc/mRWEyAa4fMzqncvAt7D3DSYpRQVs wopw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EpJK3nyRD/4VLb+i1cnUJMMJENYDbLDvzuMVALAaAd8=; b=qnGffyGJL67YxdlQbIyqdnLZ2WhfqiHbplj3JcaeMaG5dkqtmLWc0dvosOIxGKdI7u tHjHEgxVdAV+8plYOYnM8Kj8V7slzdLyymO6NMtd22iJQso/Ffzc4Lsl1S83NtL98Ok7 CRv9gtrR/L4pSdxSLLiZ62M/eOJ4w3Xm7jYmlaW+P1fgZBHPkxdPUP1H7306NCOZGSZY 4fRsqjydXMY2lvlH0uRaqkHxg0CVHSN40VG1bC2/1xS14crAZirMPzIQgjsMlm3jwIGC 4/uxRKgY+c3m/TF6YoYZHJVnzV2DFtFvryijmysQz2uKapUl4ePRPL7q4wJaUwIAoGyn q0Sg== X-Gm-Message-State: APjAAAX6oOmDmI7a9tUqRiehqOidLR1SVQZ9FmoZGhVKcJ8SdVmMF/fS 1qxPyw73EYsWFA2PNJ4o1iuZb9anvLbV6xxdwKQBGIL9hcKsAlXX0ayymGIzpK3j26GHZdn4MZN TWXQs3U1pJbhafvufUru/W/fOt2onQsa14q7IGx+yj4WXRGKYq/nGhd9CgK3/txqIIp2NeLDSWQ == X-Google-Smtp-Source: APXvYqyBmt0467q7Hh4lu3FAIDA2LOespYre5quETy7XUhDi5wrq7O/eQTng22oVPS8BNoLWoJTL7mIMr0usLjIwqZE= X-Received: by 2002:a65:648e:: with SMTP id e14mr608928pgv.317.1561593059582; Wed, 26 Jun 2019 16:50:59 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:21 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 02/13] walken: add usage to enable -h From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It's expected that Git commands support '-h' in order to provide a consistent user experience (and this expectation is enforced by the test suite). '-h' is captured by parse_options() by default; in order to support this flag, we add a short usage text to walken.c and invoke parse_options(). With this change, we can now add cmd_walken to the builtins set and expect tests to pass, so we'll do so - cmd_walken is now open for business. Signed-off-by: Emily Shaffer Change-Id: I2919dc1efadb82acb335617ea24371c84b03bbce --- builtin/walken.c | 25 +++++++++++++++++++++++++ git.c | 1 + 2 files changed, 26 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index d2772a0e8f..9eea51ff70 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -5,9 +5,34 @@ */ #include "builtin.h" +#include "parse-options.h" + +/* + * All builtins are expected to provide a usage to provide a consistent user + * experience. + */ +const char * const walken_usage[] = { + N_("git walken"), + NULL, +}; int cmd_walken(int argc, const char **argv, const char *prefix) { + struct option options[] = { + OPT_END() + }; + + /* + * parse_options() handles showing usage if incorrect options are + * provided, or if '-h' is passed. + */ + argc = parse_options(argc, argv, prefix, options, walken_usage, 0); + + /* + * This line is "human-readable" and we are writing a plumbing command, + * so we localize it and use the trace library to print only when + * the GIT_TRACE environment variable is set. + */ trace_printf(_("cmd_walken incoming...\n")); return 0; } diff --git a/git.c b/git.c index c2eec470c9..2a7fb9714f 100644 --- a/git.c +++ b/git.c @@ -601,6 +601,7 @@ static struct cmd_struct commands[] = { { "verify-pack", cmd_verify_pack }, { "verify-tag", cmd_verify_tag, RUN_SETUP }, { "version", cmd_version }, + { "walken", cmd_walken, RUN_SETUP }, { "whatchanged", cmd_whatchanged, RUN_SETUP }, { "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT }, { "write-tree", cmd_write_tree, RUN_SETUP }, From patchwork Wed Jun 26 23:50:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018557 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 BA7DA1398 for ; Wed, 26 Jun 2019 23:51:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC5DC28A01 for ; Wed, 26 Jun 2019 23:51:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0BD8289E9; Wed, 26 Jun 2019 23:51:04 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 537CE289E9 for ; Wed, 26 Jun 2019 23:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726603AbfFZXvD (ORCPT ); Wed, 26 Jun 2019 19:51:03 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:56651 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvD (ORCPT ); Wed, 26 Jun 2019 19:51:03 -0400 Received: by mail-pf1-f201.google.com with SMTP id x10so258431pfa.23 for ; Wed, 26 Jun 2019 16:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xZPo7IbblC2mxy8Nz3bkmiWr8q70ZXXBBoHRw1UpBd8=; b=aFOYsPa23lB/UcQ7WnHkzjEIxFe9Q61rdMy6usCLGrbrhgI2OHPARyM2JnITN4Isky KLzgL9/1bZEzVSM7+m1ozk9jjD1QVtfTIZ9sAOyT/0U7zgrf+qKWAlBt1VNmC5s4loMJ JVzfO0o495VJ3JuZw2M11KtX73ghFSyYLNmVZvY4RuvxWDp4rN4jwgJtQuTTgtlmVY99 TWo+hIwcH26XZeof3XNgpXsSmgYK9WIFyGGakYJqdrf3d8Vx4wZOzJzr3L0zjUYAU4FZ 5N3RSpQOv8c2WQ7yRulohHXDDOwqjcDykbnKaddIoJXHNEvCuRnuD1HaaiN5TI0631WW Bllw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xZPo7IbblC2mxy8Nz3bkmiWr8q70ZXXBBoHRw1UpBd8=; b=B4SEtnmJWZYU8RRSZNEP06DQ/Epa8sXBNemNMsyuvndk42lM+7/BT6iuMNAnwTKMmZ H6S9R0G6OMy/xXX1JKen39bRDIvbSN4rrpJ2oD8K/L6r7Sx14O6IGtpoBOPgZ74e8xRF JMjFEd+l/M/X61TDGE5XOJwLlyzXpegheCfDi++oLZM/8mi45Pr2Nks+hPivkHAfDXHl DUNCm2e0y3lJqJGLiQtW7pLRJCKViulrC/3iKKSFPVGTs1coiAxlPxvgrvxlzUdG69lj 1dKoyQChnr4wt6aIcSUPIz59dPMyA2L+3HmRi8tiJNW6FFmR1l1kpcxiaNyJprpFp86o pbdQ== X-Gm-Message-State: APjAAAV44PPL7JlHchYA1IxUdRY0ouy61LajzI6VS+IHO4INJADP4i4p uX4n7kbFjAFRjyreta9vr+RjzEshp0Ib+iLZ60mnFSTi40yop4UN1VkuLlBkFiG/4dd6HL2lQ+r s4h/Hi7X4VhjXxVNOxyIUS1AwmS0SN+yKXlIpKD74lb6xlKlkUJX2SBjwcdJYjLxpKeabiJnC8Q == X-Google-Smtp-Source: APXvYqxjUMmvM+41whtkpqSNDqPG3sagBS0goj3u581wqGGuKthmmbfp6/RpOhbJyOSGEsLVcLdD5bIt0WG74I08gfk= X-Received: by 2002:a65:4945:: with SMTP id q5mr634929pgs.9.1561593062121; Wed, 26 Jun 2019 16:51:02 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:22 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 03/13] walken: add placeholder to initialize defaults From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Eventually, we will want a good place to initialize default variables for use during our revision walk(s) in `git walken`. For now, there's nothing to do here, but let's add the scaffolding so that it's easy to tell where to put the setup later on. Signed-off-by: Emily Shaffer --- builtin/walken.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index 9eea51ff70..daae4f811a 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -16,6 +16,19 @@ const char * const walken_usage[] = { NULL, }; +/* + * Within init_walken_defaults() we can call into other useful defaults to set + * in the global scope or on the_repository. It's okay to borrow from other + * functions which are doing something relatively similar to yours. + */ +static void init_walken_defaults(void) +{ + /* + * We don't actually need the same components `git log` does; leave this + * empty for now. + */ +} + int cmd_walken(int argc, const char **argv, const char *prefix) { struct option options[] = { @@ -28,6 +41,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix) */ argc = parse_options(argc, argv, prefix, options, walken_usage, 0); + init_walken_defaults(); + /* * This line is "human-readable" and we are writing a plumbing command, * so we localize it and use the trace library to print only when From patchwork Wed Jun 26 23:50:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018559 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 47C731398 for ; Wed, 26 Jun 2019 23:51:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3966A289E9 for ; Wed, 26 Jun 2019 23:51:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DEE528A03; Wed, 26 Jun 2019 23:51:08 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 1A5BE289E9 for ; Wed, 26 Jun 2019 23:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726614AbfFZXvG (ORCPT ); Wed, 26 Jun 2019 19:51:06 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:43547 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvF (ORCPT ); Wed, 26 Jun 2019 19:51:05 -0400 Received: by mail-qt1-f202.google.com with SMTP id z16so507166qto.10 for ; Wed, 26 Jun 2019 16:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dWEVljm4oXRwl6Ea51BtQfB+u+x6RAceFHPjatbjBs0=; b=MIc0krv7jRRAGCNBRn6wyRDCcQQap4f6RzoYS8jh0vmv7X6YfK6jafXoQJBdigAwO5 OCkbOpYZxhEaF5GlxzxqN+gJFXVpsVOpqrWTUJLrT9XnZS65HaCYX1Y2IYY23t1erDFa wWhlkMNeXWwg3vIM6BtN8L5WevUP2T2VHieJcvijU8wHM3ZRmiVAKho7nA9m2DOxd+jm 6pOAx2VWnokZ++Rx99A4itCx0tm9BEnu4K/8GZtRCyauscAM472v874562CeBYTbiEp4 OSW8Qfu+b1jgPMz+hVO9ZhKiM1CsdpsbBgPGvOakcux44OvvcqoM85Eu4L6D5Efui7R3 q7nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dWEVljm4oXRwl6Ea51BtQfB+u+x6RAceFHPjatbjBs0=; b=IcluHivyVRALItxsH+Pa9OKRkqdpzqxkZHXk7cGDyzIw3nXEUAIZYc7WGpfQ76wj/l /7GVLTAyRS3Eg06dAtCIBZN4tggFp+C1EXuG7k7eEfZ5+MDHt68TX5Ipa13GodAFh2iP gqB07ylBjLgjAcwJYXfLi2rjUQT1zK0QCf5KH5vZ53TK9pKLbFQl6CmDfg/28sEyQTRb f91KhVe+IrLOo/dVsYzfNWGWLNE/Ns6+GKn6o4z/9/AYg/I5H7nw/VP7xsiX0gerHnyT zC38chTfHb7IDZIcoC2EMLOIprMzxhsI1a9M2py2lwBYEMBuRitXYixHDfeBAhQ16fDz iT0w== X-Gm-Message-State: APjAAAVN3K3WqoPAieyUrm6UVfQ7tbIKjT+ID1O06fn9JgfposeJhH/U EruGvv8Mfp7rESMY57XCjwA3IaKmBShPNtSW8UsA9ZTTjzmv9pgu06EGpvMTmtimh66pSqGzcfY dWAxuO2SYpFnmttZkLZIDPyZsadEffMVPGirHG3Tk9A05Ly0KBMg2Lu17EGH1a+/N2aER0DpNWg == X-Google-Smtp-Source: APXvYqyICc4x+O+j4iOZaAp5lq9LMScDYV+28Ey3Umsk5qg5ROTy+HL1BsFiMEYZ/afMDY2O5+gUWUr7bMFednpg6TI= X-Received: by 2002:ac8:26dc:: with SMTP id 28mr564576qtp.88.1561593064848; Wed, 26 Jun 2019 16:51:04 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:23 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 04/13] walken: add handler to git_config From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For now, we have no configuration options we want to set up for ourselves, but in the future we may need to. At the very least, we should invoke git_default_config() for each config option; we will do so inside of a skeleton config callback so that we know where to add configuration handling later on when we need it. Signed-off-by: Emily Shaffer --- builtin/walken.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/builtin/walken.c b/builtin/walken.c index daae4f811a..2474a0d7b2 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -5,6 +5,7 @@ */ #include "builtin.h" +#include "config.h" #include "parse-options.h" /* @@ -24,11 +25,36 @@ const char * const walken_usage[] = { static void init_walken_defaults(void) { /* - * We don't actually need the same components `git log` does; leave this - * empty for now. + * We don't use any other components or have settings to initialize, so + * leave this empty. */ } +/* + * This method will be called back by git_config(). It is used to gather values + * from the configuration files available to Git. + * + * Each time git_config() finds a configuration file entry, it calls this + * callback. Then, this function should compare it to entries which concern us, + * and make settings changes as necessary. + * + * If we are called with a config setting we care about, we should use one of + * the helpers which exist in config.h to pull out the value for ourselves, i.e. + * git_config_string(...) or git_config_bool(...). + * + * If we don't match anything, we should pass it along to another stakeholder + * who may otherwise care - in log's case, grep, gpg, and diff-ui. For our case, + * we'll ignore everybody else. + */ +static int git_walken_config(const char *var, const char *value, void *cb) +{ + /* + * For now, we don't have any custom configuration, so fall back on the + * default config. + */ + return git_default_config(var, value, cb); +} + int cmd_walken(int argc, const char **argv, const char *prefix) { struct option options[] = { @@ -43,6 +69,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix) init_walken_defaults(); + git_config(git_walken_config, NULL); + /* * This line is "human-readable" and we are writing a plumbing command, * so we localize it and use the trace library to print only when From patchwork Wed Jun 26 23:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018561 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 28254112C for ; Wed, 26 Jun 2019 23:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19692289E9 for ; Wed, 26 Jun 2019 23:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DF7C28A03; Wed, 26 Jun 2019 23:51:10 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 9C62D289E9 for ; Wed, 26 Jun 2019 23:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726633AbfFZXvI (ORCPT ); Wed, 26 Jun 2019 19:51:08 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:47837 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvI (ORCPT ); Wed, 26 Jun 2019 19:51:08 -0400 Received: by mail-qt1-f201.google.com with SMTP id s9so496551qtn.14 for ; Wed, 26 Jun 2019 16:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=e3c+xhemaCfuUw/R0zRC2kKv1su/aN127wWoDjPGEo0=; b=lP/owuCImy4lOX0XAdXDZ9T5TX6fUUiKUjDQg3C1VYNgz8I5RoRmhrW2jx9iHZLeMB LrG3OljGkFeaXxsl90klOY1QXxAS+Frt0xE0HAWYxlSnh+V4PZh8WADICuu2YtlUox70 J8bbPZYovOhjowiXeb/PdQC0A9587LzqYsRcZmTyRJBAd9YZ0NZoyVwsycZ18j0QMflv D+d2Jv6/dEQGHeqGR3egDiTZI1tvq3unntHbCirV6WIl+0VhglNz6f3VLGf154bH7nXh bPymBhB7HysUrXOMdXrrjC1XwFeFQRA7KRjXO/wUGNjBXDaJy0IgItVK9VNOWwzuJ7Xo h30g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=e3c+xhemaCfuUw/R0zRC2kKv1su/aN127wWoDjPGEo0=; b=K9Lx6LF+paQumuUKQKJb+4RZo8R295YpN//bFZeO0Wy1MWn5IAiUGR0Rvx/llk+J8x pF88mF5yP4IhIQHWD16TFgbnjOYS562aVRXlJ64mxGScn78HW6Hdc1UFm5uf1VJIUJL7 GBXJ6DEupll5eg7kZ7Ot/Pwb79BEGqzDT+2Y5NWTAO4oPVx8fqmeEDW92+fpvr/o4ui9 K9Vqfmr7iUs8WRU9I2gx66TqNgycEPnu8Whroil8HC9VSjJ6b7OaadTmG2hFshs/jj41 kNQteeFMTEIeHN6+kXrpwE80L3/uf6dLiJ9DYffikTJj3h7YgE9ceQalzaAs/g9zAJM7 f/cQ== X-Gm-Message-State: APjAAAV2iCR5gu/UFIdfOr/UP2BSXBGf8Devb7JD37bm2tF4Vs3mqG8U fFxfUP7U1Hbnp47BRI0Hru9euhrhdOI2bQRCR72Tyuu+vL74MXaXI2xGhzLZevBNEJ8J0LaHwru SzLpfoCyBc9eXJLfQ/TPPZCk2mQBpS8xGbcaIC6YRaJvREJIIUi6x6jh+9S5Wf2AntiZ2H7ON6A == X-Google-Smtp-Source: APXvYqztD7TWrbrsb9MgRCrsariHawcMTGLRXmIy0Xl6+5YYbeKxUume9O7Crdn3PWP5WSi7TAqCRkOK5m/cZNB6R/s= X-Received: by 2002:a37:a988:: with SMTP id s130mr721096qke.390.1561593067284; Wed, 26 Jun 2019 16:51:07 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:24 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-6-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 05/13] walken: configure rev_info and prepare for walk From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP `struct rev_info` is what's used by the struct itself. `repo_init_revisions()` initializes the struct; then we need to set it up for the walk we want to perform, which is done in `final_rev_info_setup()`. The most important step here is adding the first object we want to walk to the pending array. Here, we take the easy road and use `add_head_to_pending()`; there is also a way to do it with `setup_revision_opt()` and `setup_revisions()` which we demonstrate but do not use. If we were to forget this step, the walk would do nothing - the pending queue would be checked, determined to be empty, and the walk would terminate immediately. Signed-off-by: Emily Shaffer Change-Id: I76754b740227cf17a449f3f536dbbe37031e6f9a --- builtin/walken.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index 2474a0d7b2..c463eca843 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -5,6 +5,7 @@ */ #include "builtin.h" +#include "revision.h" #include "config.h" #include "parse-options.h" @@ -30,6 +31,40 @@ static void init_walken_defaults(void) */ } +/* + * cmd_log calls a second set of init after the repo_init_revisions call. We'll + * mirror those settings in post_repo_init_init. + */ +static void final_rev_info_setup(int argc, const char **argv, const char *prefix, + struct rev_info *rev) +{ + /* + * Optional: + * setup_revision_opt is used to pass options to the setup_revisions() + * call. It's got some special items for submodules and other types of + * optimizations, but for now, we'll just point it to HEAD and call it + * good. First we should make sure to reset it. This is useful for more + * complicated stuff but a decent shortcut for the first pass is + * add_head_to_pending(). + */ + + /* + * struct setup_revision_opt opt; + + * memset(&opt, 0, sizeof(opt)); + * opt.def = "HEAD"; + * opt.revarg_opt = REVARG_COMMITTISH; + * setup_revisions(argc, argv, rev, &opt); + */ + + /* Let's force oneline format. */ + get_commit_format("oneline", rev); + rev->verbose_header = 1; + + /* add the HEAD to pending so we can start */ + add_head_to_pending(rev); +} + /* * This method will be called back by git_config(). It is used to gather values * from the configuration files available to Git. @@ -61,6 +96,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix) OPT_END() }; + struct rev_info rev; + /* * parse_options() handles showing usage if incorrect options are * provided, or if '-h' is passed. @@ -71,6 +108,19 @@ int cmd_walken(int argc, const char **argv, const char *prefix) git_config(git_walken_config, NULL); + /* + * Time to set up the walk. repo_init_revisions sets up rev_info with + * the defaults, but then you need to make some configuration settings + * to make it do what's special about your walk. + */ + repo_init_revisions(the_repository, &rev, prefix); + + /* + * Before we do the walk, we need to set a starting point by giving it + * something to go in `pending` - that happens in here + */ + final_rev_info_setup(argc, argv, prefix, &rev); + /* * This line is "human-readable" and we are writing a plumbing command, * so we localize it and use the trace library to print only when From patchwork Wed Jun 26 23:50:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018563 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 700451580 for ; Wed, 26 Jun 2019 23:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61F56289E9 for ; Wed, 26 Jun 2019 23:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C0B28A03; Wed, 26 Jun 2019 23:51:12 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 E7E9B289E9 for ; Wed, 26 Jun 2019 23:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726655AbfFZXvL (ORCPT ); Wed, 26 Jun 2019 19:51:11 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:43040 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvK (ORCPT ); Wed, 26 Jun 2019 19:51:10 -0400 Received: by mail-pl1-f201.google.com with SMTP id t2so288747plo.10 for ; Wed, 26 Jun 2019 16:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4TaIo5JITih+BTUObpSO0GNEJ6wW9gJ5AjFC0810znE=; b=cmqbjkfAc4T3BLMpZ7ESvDhyEvjxuJ1gIcZcS6V0lZLUfKLq/LscIytjWLI7TY1Bcu 0Wz9VrHYYP3irzqkM/5ib/9vUXqTeerJF2Xx+Zrfn1biMMB+SrjKtYIIwu9mc+iOYwIn I5r/FAM390wxqaLShRM+F+mjTPh1Zgf3/UtFPkmgcV7SkYbgaehLVm4b9pSfO34MZTXJ TG/af34RFndzQrIwQvSgKZKP12b0ZzttcjgoAHuzEHwqf1rqclpDd5fqGVi/el314Paz y4GUKfooJ1gTjLrxUp6ctDI5eGq73tuiegtSWk9+/Pj2fT5TAHX4Wt3FdBDHT3tnapQD X36w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4TaIo5JITih+BTUObpSO0GNEJ6wW9gJ5AjFC0810znE=; b=SYubNDKrmqIJwPBFSUMAw2TGehBVEY8UObEDqyXGFClk0HZq0ka8jWNvY3D4q4lMRH OyBUgqvgZtq+HEKUjcSEjtltpenl3OAZ7lWZ1YXwgSQDac/dcDxm3zOhmA2iHNhdI8lm FTlN5wAPFgmbHVM/LnZvFtlYpGGBse0kwEpxT6C/poGslClk82nXpgttRboySpPeQFcu ETkbZpvnBsKOcNVs80e1IoqFMe7xbkFv6soagirvXNoaKKAhzSo7LDetcG+ueE+F4Uzp p3Bzyqp+8j3Jv9FIr1nfwhe+3oeN8DXEGxrWT6gXdxis9RNzCZZgbajSlH0rh5ZAZAOi D3FA== X-Gm-Message-State: APjAAAUMqiNtbFIlk+XKE0lJnD7NO1Fhj/gMPk8pjTMb1GLvzZaZuQLI gcNJ3YWiDEtChlZyXT6hxz+ETHC4gvY2Hft/XwkOS9H97Tzd07nfYJiP0Mh19wf0+em1/tFOOXf e/U6kV6HtcEBVUX4I07YETYJ1yOJkR4isaKvuJa5LOa/8JX9qHjh/5nwE3nAaR7ReIv2XYmO3vA == X-Google-Smtp-Source: APXvYqwkZ0Gq2HDC1h6ZJU29BZOqJJNeSN+OsX8ucI15ZJs540TGQQuidDSLNNxFmQu9gfCQ3xx6My17NTIKqaquSAA= X-Received: by 2002:a65:530c:: with SMTP id m12mr598151pgq.363.1561593069772; Wed, 26 Jun 2019 16:51:09 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:25 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-7-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 06/13] walken: perform our basic revision walk From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the final steps needed and implement the walk loop itself. We add a method walken_commit_walk() which performs the final setup to revision.c and then iterates over commits from get_revision(). This basic walk only prints the subject line of each commit in the history. It is nearly equivalent to `git log --oneline`. Signed-off-by: Emily Shaffer Change-Id: If6dc5f3c9d14df077b99e42806cf790c96191582 --- builtin/walken.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index c463eca843..335dcb6b21 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -6,8 +6,11 @@ #include "builtin.h" #include "revision.h" +#include "commit.h" #include "config.h" #include "parse-options.h" +#include "pretty.h" +#include "line-log.h" /* * All builtins are expected to provide a usage to provide a consistent user @@ -90,6 +93,41 @@ static int git_walken_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } +/* + * walken_commit_walk() is invoked by cmd_walken() after initialization. It + * does the commit walk only. + */ +static void walken_commit_walk(struct rev_info *rev) +{ + struct commit *commit; + struct strbuf prettybuf = STRBUF_INIT; + + /* + * prepare_revision_walk() gets the final steps ready for a revision + * walk. We check the return value for errors. + */ + if (prepare_revision_walk(rev)) { + die(_("revision walk setup failed")); + } + + /* + * Now we can start the real commit walk. get_revision grabs the next + * revision based on the contents of rev. + */ + rev->diffopt.close_file = 0; + while ((commit = get_revision(rev))) { + if (!commit) + continue; + strbuf_reset(&prettybuf); + pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf); + /* + * We expect this part of the output to be machine-parseable - + * one commit message per line - so we must not localize it. + */ + puts(prettybuf.buf); + } +} + int cmd_walken(int argc, const char **argv, const char *prefix) { struct option options[] = { @@ -115,12 +153,17 @@ int cmd_walken(int argc, const char **argv, const char *prefix) */ repo_init_revisions(the_repository, &rev, prefix); + /* We can set our traversal flags here. */ + rev.always_show_header = 1; + /* * Before we do the walk, we need to set a starting point by giving it * something to go in `pending` - that happens in here */ final_rev_info_setup(argc, argv, prefix, &rev); + walken_commit_walk(&rev); + /* * This line is "human-readable" and we are writing a plumbing command, * so we localize it and use the trace library to print only when From patchwork Wed Jun 26 23:50:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018565 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 19ED7112C for ; Wed, 26 Jun 2019 23:51:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A0D9289E9 for ; Wed, 26 Jun 2019 23:51:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2B4228A05; Wed, 26 Jun 2019 23:51:14 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 9A713289E9 for ; Wed, 26 Jun 2019 23:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbfFZXvN (ORCPT ); Wed, 26 Jun 2019 19:51:13 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:37016 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvN (ORCPT ); Wed, 26 Jun 2019 19:51:13 -0400 Received: by mail-pg1-f201.google.com with SMTP id e16so206503pga.4 for ; Wed, 26 Jun 2019 16:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=nyiPkoZ6sPMQUqADlP4e3n5AVmwefyeDNcV2SY+k2Eg=; b=pck/+SGgndoArsLEzclKeBuA33xERNCtazq6F/qZM8zmWwFxQwxN0HTwnkjw27Gror me5NmXPZpVcC2drtrB6fpYjeVC3DjQJW8w+WzmTGTHGKGfs7Nbr5+FsLyKkwvK+uiHrF olLMhMobr9UywtP8/u6P3uQzBteZmYiWwPslA7nK4YVGHMHKMDpOXnXQyveKexYXsEQC eB5dVxHePK9DGTZBNJiR8EQ3rrgSJwRSIBWAzvm1idX72p2kbx2/F3/zB3rZyblVLjO4 nZbLjI/Vw0NPuwgB7F4NcpPC2Euf2P+H4T+zso1O5OGWx5RJR5sDB/xlCEVu3mpm2PnC UT2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nyiPkoZ6sPMQUqADlP4e3n5AVmwefyeDNcV2SY+k2Eg=; b=tR+aeAzBpz79XRkcWeTrFl976KuAltgvmS3kHWlQ/6tAVhIXh89H3jniBMV3ohcWBU z26u7Ghcrp6RXnEc6irnQUKvmON3AONG0cnQ3HuOXWoc8IiTcfhqa3ycxGdsDRye4EgF NqHeWklfSpJBImhd9T9PLMsJGfAWCsz7fnbxtZeoRlp87j5JC8cNt51+xvMurOHB4Bui U7o06ITqug6+nISu2wopAnLcStg5MgFYDHFeLRXD44ToZmu3mP3DEOBvp/pezxot/pzq /k1huI5Dr68Y3rAd/dQboAh/zfMqUmQfSWZPF2/L8o72Y6c2Goe+gc9Id7CIzGy7oTCO 3xZA== X-Gm-Message-State: APjAAAVN3DGka27qOidb3yrNq+igKGkTgchMGmjCZ30c9l82LmMOy57S Uvz6QH6HXokdRSDRacY23XY6twqNNbIdx7kbb3al/2hiCJa1KtvMMNRYJTlsHpyC5iMfoOMrpMZ FUIMaeVUNeJmNcNrfvv4t2A3CpDPF31RLOJwcdXxH9VYY0m2nzEd63WynQrBBJyvLYYqtR0Zb3A == X-Google-Smtp-Source: APXvYqzO8ku6mz0527nK0ssKEn5ZD+E3wSnpm0wOXYWKSQipsH7/nRL8smureSAPXZ2dW9X8jyTRQOicWEseMFEs8V4= X-Received: by 2002:a65:448b:: with SMTP id l11mr640926pgq.74.1561593072454; Wed, 26 Jun 2019 16:51:12 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:26 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-8-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 07/13] walken: filter for authors from gmail address From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to demonstrate how to create grep filters for revision walks, filter the walk performed by cmd_walken() to print only commits which are authored by someone with a gmail address. This commit demonstrates how to append a grep pattern to a rev_info.grep_filter, to teach new contributors how to create their own more generalized grep filters during revision walks. Signed-off-by: Emily Shaffer --- builtin/walken.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/walken.c b/builtin/walken.c index 335dcb6b21..da2d197914 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "pretty.h" #include "line-log.h" +#include "grep.h" /* * All builtins are expected to provide a usage to provide a consistent user @@ -28,10 +29,8 @@ const char * const walken_usage[] = { */ static void init_walken_defaults(void) { - /* - * We don't use any other components or have settings to initialize, so - * leave this empty. - */ + /* Needed by our grep filter. */ + init_grep_defaults(the_repository); } /* @@ -60,6 +59,10 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix * setup_revisions(argc, argv, rev, &opt); */ + /* Add a grep pattern to the author line in the header. */ + append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail"); + compile_grep_patterns(&rev->grep_filter); + /* Let's force oneline format. */ get_commit_format("oneline", rev); rev->verbose_header = 1; @@ -86,10 +89,7 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix */ static int git_walken_config(const char *var, const char *value, void *cb) { - /* - * For now, we don't have any custom configuration, so fall back on the - * default config. - */ + grep_config(var, value, cb); return git_default_config(var, value, cb); } From patchwork Wed Jun 26 23:50:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018567 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 87A6B1580 for ; Wed, 26 Jun 2019 23:51:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79A2D289E9 for ; Wed, 26 Jun 2019 23:51:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DE6D28A03; Wed, 26 Jun 2019 23:51:17 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 26E78289E9 for ; Wed, 26 Jun 2019 23:51:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbfFZXvQ (ORCPT ); Wed, 26 Jun 2019 19:51:16 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:35713 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvQ (ORCPT ); Wed, 26 Jun 2019 19:51:16 -0400 Received: by mail-pf1-f202.google.com with SMTP id r142so281489pfc.2 for ; Wed, 26 Jun 2019 16:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dbeAs++P6lgwcZBiAdad7ATS/JYm4HxYSeUjqc8FQlg=; b=m+xNeUzkAsv16anNVWEY2/no6OBtVic407fK+s/tpm6HbDIEJcGTsID0RcuBhS2Gk2 7jgYykfDK1nAjbw0TpPhBdrVfffsImG7UxD87fc5sO3XuMghijAkSkl2w8jdcO1nucve PSof4EHHNrShLUOCslR7ptu+JlnoubkuICLNjHs2K2E/zb644ke3D8xdshNCuk1Z0gWT 9WDDtKX+SANmhXVcAIs/KPvC4Yae3ja6z3S8a8AXir8bm0jgr/j+xpS2UNZNSczaVBmV L6rOmz5yg2o/nODcs2mFh04UjZIT85/jW1nHIykKi6a6K/8J1pdL6cBfNJyIZWQqTsBx F0EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dbeAs++P6lgwcZBiAdad7ATS/JYm4HxYSeUjqc8FQlg=; b=aoFr9p1Hsx/OVNlEqC528GAXEKsWu9/IxMcMqCDYV/UkrjJA+HKmpLrGbpcfLL5NJ+ PnjaOH88miR5rJGaw9UEm2xIXcWDzB/9/gcYMfrwA98UB96aS72vRw7zw7mNTOsz7/HD P4ATbOKp1eJq5VeUi6Xq7cVIwsWJjF0TQgVxu+sSKfGSX6gcFZW3hg7Es5TbsgeliIr0 qDU4pJ6RzEg6jNiLtEU6+Fm2B3PROJJfdy0XUnT5J1tjhhEVmLH/bY6V5blLuu2cAWXL PBNzAHegNoyfY7PuNYAyrzRt0RmK/0bL7aY8t+vAyuCqfLteNjtTI/LbsLJ8BbOhUCXs Ictg== X-Gm-Message-State: APjAAAXd2TyLZwhijm7bEHYv+i4M3pUY6QUkujuEQkO4275HYI1hK5ss Fiqu9qPx6Mre/k3ThRYey7bTtUY6Zdr4VXFgjyr3H2thzHiEsCre3SxTWFGf+xkIMOM7XUNonCT dL3/eWmce3/MgVqdKXhwRH4ekvwor0hfgfxUOLRvP2MVyJtbp0Wx9GrrDIMPE45qQbdm8xqp//A == X-Google-Smtp-Source: APXvYqwZTX/T7VzHdFVr89lTSRYkefk8o0NKYz3jYRTSXwjXVkv6p5NEbzOgMpN6+vIQjmXmNP6wjlWB0s1no8Y8BKA= X-Received: by 2002:a63:9a51:: with SMTP id e17mr651376pgo.212.1561593074843; Wed, 26 Jun 2019 16:51:14 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:27 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-9-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 08/13] walken: demonstrate various topographical sorts From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Order the revision walk by author or commit dates, to demonstrate how to apply topo_sort to a revision walk. While following the tutorial, new contributors are guided to run a walk with each sort and compare the results. Signed-off-by: Emily Shaffer Change-Id: I7ce2f3e8a77c42001293637ae209087afec4ce2c --- builtin/walken.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index da2d197914..6cc451324a 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -69,6 +69,13 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix /* add the HEAD to pending so we can start */ add_head_to_pending(rev); + + /* Let's play with the sort order. */ + rev->topo_order = 1; + + /* Toggle between these and observe the difference. */ + rev->sort_order = REV_SORT_BY_COMMIT_DATE; + /* rev->sort_order = REV_SORT_BY_AUTHOR_DATE; */ } /* From patchwork Wed Jun 26 23:50:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018569 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 34EB41580 for ; Wed, 26 Jun 2019 23:51:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26DD6289E9 for ; Wed, 26 Jun 2019 23:51:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B55928A03; Wed, 26 Jun 2019 23:51:20 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 B938B289E9 for ; Wed, 26 Jun 2019 23:51:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbfFZXvS (ORCPT ); Wed, 26 Jun 2019 19:51:18 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:39483 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvS (ORCPT ); Wed, 26 Jun 2019 19:51:18 -0400 Received: by mail-pl1-f201.google.com with SMTP id r7so295265plo.6 for ; Wed, 26 Jun 2019 16:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WGAwoi10ZwQ3gkHiE4e9AGONWrkjxHpg22xP0Yx7mSM=; b=eABcZxN0FBLL1V1mds1ZBI1xjPagCZVYvQtelt/EQlXFWGV2UXOepwYCFT/ahEeTpt 0o2bRd04y+lPovKzusgQ0l8L7XbOqWgitsFXdxHgtNB9P7qU6Vff+ZokWkqg+i4uwx5X xbsRp/6JRJtQ46J7j+5jfNOMsEgYMWJOzAgav3M18zyXQUUap0oG51d+D0LqXjezH4Dy aQcZoc1QL2kfIgw4jDCGLpV7bIGnII7NgssT5LmXpKvXUpLt8u37ml2GbZfocO7HHQks YWNNHBUa1pqw3PfGvLtiV+h/n/22MtLqITwcRN4ujTVYgi5xdimi+ErNvYv9fHTYVM2H F9ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WGAwoi10ZwQ3gkHiE4e9AGONWrkjxHpg22xP0Yx7mSM=; b=Qe1GnAezq5UknFMwrh3rnhVLlmlqcMXFR+dK7c6Wp6KtVFfMvCd2pTz1V+yaGrCq6+ zE16YEofW737BQ/95dnY8UORDW0/creT8YUPNdmGjEyVx2OjyvgzMh8zRT+Rcs4Y4ZiX zjbFxS92xqtJNlIiVUkZx3+6dy7youHlvoAySHmFyGYLJ0AtIRVpqqKTtbp6RtOPtAio iDcblWor9mH2SB/w4rbrFwdoznnDcNyiIyIoNlapTQfjnMfONQGv/vqcFaDY95K/5JyV zkAJc5pdjSae+wxL2JEbOHCgVhfvb80NmqXj53dFmV+Sd5A+UHhvul4y03XngX4fxly2 Ok8Q== X-Gm-Message-State: APjAAAUc39eNLE0lprrIqLoIMCXQgtpcSwHqrSBySRIcHvcVJAV94qqf I3FvlIqmkk/JDxEhoLOwb55f/9KGoq1Gw7MW15iv5NJDW3WmxQ3oso2+hdyyc/Ty4QjXzXRuMcH 41xQ1p9PQgVNgsGGC5sCZIilf6E+Zsv+DRGyfa8QkvZQwrrXWX74P3YqUYVUjhElPSD3owdRifw == X-Google-Smtp-Source: APXvYqy3ifXsiw9O9/fLYJIbsHxp6CNJCRlg1WGf07tyXcN2WKCt4loV1x6r3ENMi+6mjFDa+Xdgr2h9drqF+TwUBI0= X-Received: by 2002:a63:5d61:: with SMTP id o33mr649945pgm.114.1561593077486; Wed, 26 Jun 2019 16:51:17 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:28 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-10-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 09/13] walken: demonstrate reversing a revision walk list From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The final installment in the tutorial about sorting revision walk outputs. This commit reverses the commit list, so that we see newer commits last (handy since we aren't using a pager). It's important to note that rev->reverse needs to be set after add_head_to_pending() or before setup_revisions(). (This is mentioned in the accompanying tutorial.) Signed-off-by: Emily Shaffer --- builtin/walken.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index 6cc451324a..958923c172 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -69,6 +69,9 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix /* add the HEAD to pending so we can start */ add_head_to_pending(rev); + + /* Reverse the order */ + rev->reverse = 1; /* Let's play with the sort order. */ rev->topo_order = 1; From patchwork Wed Jun 26 23:50:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018571 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 648841580 for ; Wed, 26 Jun 2019 23:51:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55F8C28A01 for ; Wed, 26 Jun 2019 23:51:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A7AF28A05; Wed, 26 Jun 2019 23:51:23 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 CC03F28A01 for ; Wed, 26 Jun 2019 23:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbfFZXvW (ORCPT ); Wed, 26 Jun 2019 19:51:22 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:49335 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvV (ORCPT ); Wed, 26 Jun 2019 19:51:21 -0400 Received: by mail-qk1-f201.google.com with SMTP id c4so353222qkd.16 for ; Wed, 26 Jun 2019 16:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=hIrjpvXEVCqGrgTCRs/osqnLry6hQVdAGYSiOqihXwc=; b=LkDL2NFgmANqhjRXOHRM5tNxD6RyhrQMayt5Ggz7tv1NW57vfRd92oR1zxCT6ryaTN NbqUmkA0Hdby2XvRVIcEIPy7cI6Y54DNDN59cccPca7Frbl3qqMpboiXab5ghnfa6OcG qhOaZWp2fKKqlaU2PWLAnk6VO4wXQwNy+t3+/C+ynQXTMijWlrUT5T0rABdxEc5IA5gM updmOug9LaqLZtTm3LaY0FVHmvFPzHnCuvb49wHU3QbdMm38g7kib3X3DQf5NjBj/rsb 1GbtEthbarscUcJ1IuovAVGpRGijS4QywZoZHFXN4AMy1aPfEoTF8LOg0Cka3kLgfDHd fYnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hIrjpvXEVCqGrgTCRs/osqnLry6hQVdAGYSiOqihXwc=; b=eNEYLmqVpc7i+7xvhQAzP2tavALh9aP1OTHiEqsH4DsQyelcB9+y3NUfvq2rv2+srP jnXRmoPwyK5WaKGLlKFqRyWLSjkD26esoLJxrg38EioiOZNogmDi0NnW11RwdyOGLHor /38kGyFpkJpWuTyRTofJIaoFp9Y0jsSFVxctyzjTKTcTWbSI0Pxj9fNiDqLleJHPquxL Z8hQ1xQdzWlyBwONEFkSZBVdPfRxV7oz/gnZ8+GrlnzFjwlfRf65VcS8BSTSwVbh97VS 2Dshqcl1pv5GUN0fdvXcMeQhESsoJFpy0kS5+35YANIJZkeTbmlrKKJXmhObuvaGfpZF 7xaQ== X-Gm-Message-State: APjAAAX3Pjjpf147WAEs2/T5Cj+lBPgdbtTE65XPk0m8qGLdxUlv+J8W gc5hu2rwmc0wAXImAThK6KGsKnnjw/gk3Q1kE5sSa8/JaxGNlVcAxkiZPdSvF/H4rgdDwbvbg8c pFo07CzM9YSLpM1/xB7RY8s+Oo7rFJnfiFyhQuTrpzFD+2foQFueaRxHO+8+3NUwe9G/xc0WdIA == X-Google-Smtp-Source: APXvYqxmwev56qfmr+Q/Rb83JpRyLcEcZVrbGP50bx0PIk+M8VZtaFYlCRgfAs0k9Gxrn2A0ye6p7lOLMdEIZAKW2JA= X-Received: by 2002:a37:a9c9:: with SMTP id s192mr640158qke.335.1561593080335; Wed, 26 Jun 2019 16:51:20 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:29 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-11-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 10/13] walken: add unfiltered object walk from HEAD From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide a demonstration of a revision walk which traverses all types of object, not just commits. This type of revision walk is used for operations such as creating packfiles and performing fetches or clones, so it's useful to teach new developers how it works. For starters, only demonstrate the unfiltered version, as this will make the tutorial easier to follow. This commit is part of a tutorial on revision walking. Signed-off-by: Emily Shaffer Change-Id: If3b11652ba011b28d29b1c3984dac4a3f80a5f53 --- builtin/walken.c | 88 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/builtin/walken.c b/builtin/walken.c index 958923c172..42b23ba1ec 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -11,6 +11,7 @@ #include "parse-options.h" #include "pretty.h" #include "line-log.h" +#include "list-objects.h" #include "grep.h" /* @@ -22,6 +23,11 @@ const char * const walken_usage[] = { NULL, }; +static int commit_count; +static int tag_count; +static int blob_count; +static int tree_count; + /* * Within init_walken_defaults() we can call into other useful defaults to set * in the global scope or on the_repository. It's okay to borrow from other @@ -103,6 +109,65 @@ static int git_walken_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } +static void walken_show_commit(struct commit *cmt, void *buf) +{ + commit_count++; +} + +static void walken_show_object(struct object *obj, const char *str, void *buf) +{ + switch (obj->type) { + case OBJ_TREE: + tree_count++; + break; + case OBJ_BLOB: + blob_count++; + break; + case OBJ_TAG: + tag_count++; + break; + case OBJ_COMMIT: + die(_("unexpectedly encountered a commit in " + "walken_show_object\n")); + commit_count++; + break; + default: + die(_("unexpected object type %s\n"), type_name(obj->type)); + break; + } +} + +/* + * walken_object_walk() is invoked by cmd_walken() after initialization. It does + * a walk of all object types. + */ +static void walken_object_walk(struct rev_info *rev) +{ + rev->tree_objects = 1; + rev->blob_objects = 1; + rev->tag_objects = 1; + rev->tree_blobs_in_commit_order = 1; + rev->exclude_promisor_objects = 1; + + if (prepare_revision_walk(rev)) + die(_("revision walk setup failed")); + + commit_count = 0; + tag_count = 0; + blob_count = 0; + tree_count = 0; + + traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL); + + /* + * This print statement is designed to be script-parseable. Script + * authors will rely on the output not to change, so we will not + * localize this string. It will go to stdout directly. + */ + printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count, + blob_count, tag_count, tree_count); +} + /* * walken_commit_walk() is invoked by cmd_walken() after initialization. It * does the commit walk only. @@ -113,15 +178,15 @@ static void walken_commit_walk(struct rev_info *rev) struct strbuf prettybuf = STRBUF_INIT; /* - * prepare_revision_walk() gets the final steps ready for a revision + * prepare_revision_walk() gets the final steps ready for a revision * walk. We check the return value for errors. - */ + */ if (prepare_revision_walk(rev)) { die(_("revision walk setup failed")); } /* - * Now we can start the real commit walk. get_revision grabs the next + * Now we can start the real commit walk. get_revision grabs the next * revision based on the contents of rev. */ rev->diffopt.close_file = 0; @@ -166,13 +231,18 @@ int cmd_walken(int argc, const char **argv, const char *prefix) /* We can set our traversal flags here. */ rev.always_show_header = 1; - /* - * Before we do the walk, we need to set a starting point by giving it - * something to go in `pending` - that happens in here - */ - final_rev_info_setup(argc, argv, prefix, &rev); - walken_commit_walk(&rev); + if (1) { + add_head_to_pending(&rev); + walken_object_walk(&rev); + } else { + /* + * Before we do the walk, we need to set a starting point by giving it + * something to go in `pending` - that happens in here + */ + final_rev_info_setup(argc, argv, prefix, &rev); + walken_commit_walk(&rev); + } /* * This line is "human-readable" and we are writing a plumbing command, From patchwork Wed Jun 26 23:50:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018573 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 6A90C1580 for ; Wed, 26 Jun 2019 23:51:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58A1428A01 for ; Wed, 26 Jun 2019 23:51:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A514289E9; Wed, 26 Jun 2019 23:51:25 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 E7BF7289E9 for ; Wed, 26 Jun 2019 23:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726686AbfFZXvY (ORCPT ); Wed, 26 Jun 2019 19:51:24 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:34923 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXvX (ORCPT ); Wed, 26 Jun 2019 19:51:23 -0400 Received: by mail-pl1-f202.google.com with SMTP id bb9so300579plb.2 for ; Wed, 26 Jun 2019 16:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=cKWKp3L3U9lIrobE75FJbHgfNhnw0ZLswX0FAfyEbqc=; b=ebXr3DMRZZS3mXDilw7I69JP8O07fgjI29E8EPDtEp6zpWAqmSbrbvHaWE3+sXwYtb /BdrI27SQUvgY4KT21Gto4clJOd/mUQ77Y97rBoAKuz/vASSwJfLf+RA1EVMNrOIXmTC L/KdkAwTQIupaGG0Da0PjQmswEyEYIFGg1ZO0bEeB56JWx9EvHkBK1Orebw3fl5VvUgk 1zAfCEMEQd0z4ZGv+bLZ3wb9SH5pFgdIdYW4E6gf4hmHQ9vXSl8nbWftO5+mdhZ4AhFi J4/thvJdsMfaCa3Vhui1BuKajthqc2VnEcIok1bCRgR3zuMv42hPmj4boFZN7k7NjYoJ zPvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cKWKp3L3U9lIrobE75FJbHgfNhnw0ZLswX0FAfyEbqc=; b=HtEJX8POLAvoczzbX3opFqPuUsXw9/3jwPFQULaFOZUJq/L3GStlMHF+R8mkkMnVOo czgtqhGE/cw2OjBmX5WCir0f9ux0wpSuXltuFhB2D5Jk1H1ega6fVNQJblzDwLs9qAG4 PBjvfuIUnUd7TflzUuzS3kw5IhzGLZkhoL4+0PgyHYaUDGroIT0aoMmo9nW9F1cqNOn1 Op0r9HCbhYOXUH0F67cLetZMXcm4IlqBKUv4ffyEODzHjbeTaZjEadbYGd9xZR/3k7ro qKogwgfdDEtuMl8NGT3vAWFeYD/IZl4JKbl/KqjRTrGAqFDZUYRB/91Oxr5RzfNjP0PC flLg== X-Gm-Message-State: APjAAAUctyDYKVHvQDBfUKFFfAO8v3vz8Reaoep6OzKsGEYOSWppKjCt sLB+tliBZ7FwuDahw8zWqh1WfC1LVQfUIpUt51BdLGf5pO1krvtNQKGrKA3hP1rw/LX9OslAO3i 5nZbWJZLpp8PZ+ovUQt7ToMZ+NLDUIF3tcZ4svCizPvToDrkH/15enNi6kN65aVmLqGFxB4jMdw == X-Google-Smtp-Source: APXvYqzHoGRRLvr8fHhp1Q/E30J2E8OtNYpATIv0i148sN7meGD9NvcrS1LcnoAWvzVbHZLqzKmXTJ35xFRXG4GjkUY= X-Received: by 2002:a65:534b:: with SMTP id w11mr653042pgr.210.1561593082753; Wed, 26 Jun 2019 16:51:22 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:30 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-12-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 11/13] walken: add filtered object walk From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Demonstrate how filter specs can be used when performing a revision walk of all object types. In this case, tree depth is used. Contributors who are following the revision walking tutorial will be encouraged to run the revision walk with and without the filter in order to compare the number of objects seen in each case. Signed-off-by: Emily Shaffer Change-Id: I6d22ba153c1afbc780c261c47f1fa03ea478b5ed --- builtin/walken.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/builtin/walken.c b/builtin/walken.c index 42b23ba1ec..a744d042d8 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -12,6 +12,7 @@ #include "pretty.h" #include "line-log.h" #include "list-objects.h" +#include "list-objects-filter-options.h" #include "grep.h" /* @@ -143,6 +144,10 @@ static void walken_show_object(struct object *obj, const char *str, void *buf) */ static void walken_object_walk(struct rev_info *rev) { + struct list_objects_filter_options filter_options = {}; + + printf("walken_object_walk beginning...\n"); + rev->tree_objects = 1; rev->blob_objects = 1; rev->tag_objects = 1; @@ -157,7 +162,24 @@ static void walken_object_walk(struct rev_info *rev) blob_count = 0; tree_count = 0; - traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL); + if (1) { + /* Unfiltered: */ + trace_printf(_("Unfiltered object walk.\n")); + traverse_commit_list(rev, walken_show_commit, + walken_show_object, NULL); + } else { + trace_printf(_("Filtered object walk with filterspec " + "'tree:1'.\n")); + /* + * We can parse a tree depth of 1 to demonstrate the kind of + * filtering that could occur during various operations (see + * `git help rev-list` and read the entry on `--filter`). + */ + parse_list_objects_filter(&filter_options, "tree:1"); + + traverse_commit_list_filtered(&filter_options, rev, + walken_show_commit, walken_show_object, NULL, NULL); + } /* * This print statement is designed to be script-parseable. Script From patchwork Wed Jun 26 23:50:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018575 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 283DD1580 for ; Wed, 26 Jun 2019 23:51:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19718289E9 for ; Wed, 26 Jun 2019 23:51:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DB5428A03; Wed, 26 Jun 2019 23:51:28 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 AD56F289E9 for ; Wed, 26 Jun 2019 23:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbfFZXv0 (ORCPT ); Wed, 26 Jun 2019 19:51:26 -0400 Received: from mail-qt1-f201.google.com ([209.85.160.201]:52001 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXv0 (ORCPT ); Wed, 26 Jun 2019 19:51:26 -0400 Received: by mail-qt1-f201.google.com with SMTP id x1so485178qtj.18 for ; Wed, 26 Jun 2019 16:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=PLh8swemc+bh8jpE+XjDaF1VxeJH+RzuBnEXRJuK0rw=; b=ujf6ursYTko9XLdynGoFYESk/cW0vRPukRZQLR0vYPcRhMYN7b6Ga0gTB20kuKOpU/ ZILKiI5u1Q/GnxBHRqAMXe5JiLo4RmrVfAl3SD3YNx4hrjtogt8ZYUiK/WB+7uJzbcAH A7r7FF32pnhcw43EH/+QqS0agPjaNdAjxwZIOsuwsmUnAfcdKdlja36PM3HBtaJM4VOL FSX8CjXfogfA5MwJWs6uqhWG/g3rdMF0qWn27UQtlz2jK52XZLj9wqLB6QsMe3JzsIBh ONUec40cIQt06DjFappl7ouUU39naIu4ZdnffslOp1udAcmRg0NuvqA6JnovZxCCrS0/ EQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PLh8swemc+bh8jpE+XjDaF1VxeJH+RzuBnEXRJuK0rw=; b=m+55l7suugvMfUiLtlaxVZtm9tOWu6Tw2EXdfiHt0fvbTKULD/Yfc2gzR0ijD8R2tr oUtYw5H7+2E35FNhvi+q7xiGXczXMdHjZwlaMW8RlPZB0EGxLFaQXODnae72yd7sCWcp riW0YV/26h03dquhzy2dY2NA65E5JF3fiMvSowR1AcqMoaj1Q5EpZXI+fFYliK/noKHB haBBzae+zGzeRJlNUhKlQ5DXsmeRFuuTiigjuePWkJlsSMn+7n1oYV+JTfUADyN667Ph TLTCZo1E+EDxsH0CTtSVcU/vj9OwYsyvQDP5UR952g4zw1ZwymACeHxkwG6Fv+Z8EG/2 FsUg== X-Gm-Message-State: APjAAAWumMQWHcN2/dlmlZS4NZJJi2f4vdb4Qhw0YRrFApX8r8/Uwcw+ pNzgjxNY5GAuJtA1dLSH87zV+SM7ffIbPOF2ymU3lVbxT2eVPqbwVUi2DFm701MQIAw2LYnNSkN CjA7V9skeG3vr+sCA91aMilZK4JnAewxnMZOtCSi5zML8Y2opbJboq686VM6kK1i+CPcH4y6amQ == X-Google-Smtp-Source: APXvYqxhQDgVF3wlTHTDaJUz6w+GW7p0GTVIjhSvro+cJtSHLa7CGxjCofBfs+gV4mnzmlkNPC+mPTq9gWUx/rubElw= X-Received: by 2002:a05:620a:5a:: with SMTP id t26mr615204qkt.201.1561593085438; Wed, 26 Jun 2019 16:51:25 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:31 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-13-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 12/13] walken: count omitted objects From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It may be illuminating to see which objects were not included within a given filter. This also demonstrates, since filter-spec "tree:1" is used, that the 'omitted' list contains all objects which are omitted, not just the first objects which were omitted - that is, it continues to dereference omitted trees and commits. This is part of a tutorial on performing revision walks. Signed-off-by: Emily Shaffer --- builtin/walken.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/builtin/walken.c b/builtin/walken.c index a744d042d8..dc59ff5009 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -45,7 +45,7 @@ static void init_walken_defaults(void) * mirror those settings in post_repo_init_init. */ static void final_rev_info_setup(int argc, const char **argv, const char *prefix, - struct rev_info *rev) + struct rev_info *rev) { /* * Optional: @@ -145,6 +145,11 @@ static void walken_show_object(struct object *obj, const char *str, void *buf) static void walken_object_walk(struct rev_info *rev) { struct list_objects_filter_options filter_options = {}; + struct oidset omitted; + struct oidset_iter oit; + struct object_id *oid = NULL; + int omitted_count = 0; + oidset_init(&omitted, 0); printf("walken_object_walk beginning...\n"); @@ -181,13 +186,19 @@ static void walken_object_walk(struct rev_info *rev) walken_show_commit, walken_show_object, NULL, NULL); } + /* Count the omitted objects. */ + oidset_iter_init(&omitted, &oit); + + while ((oid = oidset_iter_next(&oit))) + omitted_count++; + /* * This print statement is designed to be script-parseable. Script * authors will rely on the output not to change, so we will not * localize this string. It will go to stdout directly. */ - printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count, - blob_count, tag_count, tree_count); + printf("commits %d\n blobs %d\n tags %d\n trees %d omitted %d\n", + commit_count, blob_count, tag_count, tree_count, omitted_count); } /* From patchwork Wed Jun 26 23:50:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 11018577 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 73295112C for ; Wed, 26 Jun 2019 23:51:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 639F0289E9 for ; Wed, 26 Jun 2019 23:51:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57EA128A03; Wed, 26 Jun 2019 23:51:30 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 038CE289E9 for ; Wed, 26 Jun 2019 23:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbfFZXv3 (ORCPT ); Wed, 26 Jun 2019 19:51:29 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:55223 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfFZXv2 (ORCPT ); Wed, 26 Jun 2019 19:51:28 -0400 Received: by mail-pg1-f202.google.com with SMTP id t2so185478pgs.21 for ; Wed, 26 Jun 2019 16:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=CzbVNOD2j5bMf9GFKvZflE6/nywHKbyh3joXpDHdDOM=; b=Tfb8G06f7SIh5omUaMKVSQTTBrr651oHxDzD9i9mkQIPwuMSkPKINggGEDdW6HluRD 8Lbrphnx8Eg/BRMHybJujxM9+q10CCIZikNdRPEHlnY6hWPZWISbjOVMa56HzvZvFGGe Sk+JUbxssABRC0dPAUqhdU83jMVnB2vL3RR8BzEed/FjE/yP9KZooTrnQ65dKD6W3Fir wfaENOES6n3rZK2ZbAne1dMs2RFiHDwtMYjZYVkYZRrgTL/4Gst7rSb148Rpm0x89189 aXzp4mE3URrpUsX3892lBV+nmfTkyKS2VH1EhOeuGy29Xcy+ey+PuVre3YvbGkRXsb2e V/JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CzbVNOD2j5bMf9GFKvZflE6/nywHKbyh3joXpDHdDOM=; b=k71KsPXSv198pt5Vti0qnj5LKRX4Ovm5mDUubjUlJ2gSbgYigJ0tk+3dqzL/B6iTeJ tuzY4pIIJvI+/2YrS/EPbEusvAZLCFXiy4I3dG1SaAShZ9F7c1AyWjabizBVVjioJ0nN jYA53A9YNvTs/yyR15EZaUnQ4qr8QALmPb8TUucntXs3SanhlCweg8DWaQB8JKbaS9eT l7/8OER+fqYq+lPAcQ9dlAI0+hCqa4CzpFPoYOBS4DPzfzy6uGgc2zddJtIO/COSFyHb bjqH3ITEJ8GlTpafRnG8OuSN41oBbw0YgAO8iPI4TPjTTMLZZzQEiIuOglicIL0IXJDD tsNQ== X-Gm-Message-State: APjAAAXsf2vRUSk5rcyOW9rIaZ9g+OapHNNUUtbHI413bk99Ri4LUtRY Fmq7d+Xv+PfQsy3tnTTTSKKUyCFsxoAjhQ9qLOC7mBL6HiQWdcXq52kjMhx8jSIFjfNmpmUJEE+ bF8dWem8ZYdT+WvOLMNwJOwww0q6Qk+fVVN/Nqw+80H3KwTK8Vd6znWlGm2UkdNYaV5XYr5TLgA == X-Google-Smtp-Source: APXvYqy7FFnZ4QtqW8oz+JlUZUHvvAvgPfVrMdKGhjLZywod1OTLIevWBE/L906pzaYUKS6dtlQb0JjsoT10LDOm6zo= X-Received: by 2002:a65:5347:: with SMTP id w7mr587077pgr.375.1561593087792; Wed, 26 Jun 2019 16:51:27 -0700 (PDT) Date: Wed, 26 Jun 2019 16:50:32 -0700 In-Reply-To: <20190626235032.177551-1-emilyshaffer@google.com> Message-Id: <20190626235032.177551-14-emilyshaffer@google.com> Mime-Version: 1.0 References: <20190626235032.177551-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH v2 13/13] walken: reverse the object walk order From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Demonstrate that just like commit walks, object walks can have their order reversed. Additionally, add verbose logging of objects encountered in order to let contributors prove to themselves that the walk has actually been reversed. With this commit, `git walken` becomes extremely chatty - it's recommended to pipe the output through `head` or `tail` or to redirect it into a file. Signed-off-by: Emily Shaffer Change-Id: I91883b209a61ae4d87855878291e487fe36220c4 --- builtin/walken.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/walken.c b/builtin/walken.c index dc59ff5009..37b02887a5 100644 --- a/builtin/walken.c +++ b/builtin/walken.c @@ -112,11 +112,13 @@ static int git_walken_config(const char *var, const char *value, void *cb) static void walken_show_commit(struct commit *cmt, void *buf) { + printf("commit: %s\n", oid_to_hex(&cmt->object.oid)); commit_count++; } static void walken_show_object(struct object *obj, const char *str, void *buf) { + printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid)); switch (obj->type) { case OBJ_TREE: tree_count++; @@ -158,6 +160,7 @@ static void walken_object_walk(struct rev_info *rev) rev->tag_objects = 1; rev->tree_blobs_in_commit_order = 1; rev->exclude_promisor_objects = 1; + rev->reverse = 1; if (prepare_revision_walk(rev)) die(_("revision walk setup failed"));