From patchwork Fri Feb 8 19:51:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Peart X-Patchwork-Id: 10803693 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 0C15B14E1 for ; Fri, 8 Feb 2019 19:51:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE86D2EA05 for ; Fri, 8 Feb 2019 19:51:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E267E2EB8F; Fri, 8 Feb 2019 19:51:29 +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 7E89D2EA05 for ; Fri, 8 Feb 2019 19:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727191AbfBHTv2 (ORCPT ); Fri, 8 Feb 2019 14:51:28 -0500 Received: from mail-qk1-f180.google.com ([209.85.222.180]:41780 "EHLO mail-qk1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbfBHTv1 (ORCPT ); Fri, 8 Feb 2019 14:51:27 -0500 Received: by mail-qk1-f180.google.com with SMTP id u188so2848921qkh.8 for ; Fri, 08 Feb 2019 11:51:27 -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=xSP7r0M+OMChiAGBMUbLG8vwkfLldxuGlk1kMONcZBc=; b=BkHcY7obLoVBhKalGCSeGlOkxOoHhD7JhU+VQzPrIyMYtS35COW66FWjhhufM5Shmj KDiabn/uQGhAfbxRs91jOPzY8nn+3/6vTKcmEVCrICH+KMwr2VRYhJeybMOv3ReZoWPE VgMnYhSEhzKW4ZNweJcg3nvcc8CxwjLEu3KAxpnk1hO1L5eHqNziqIZfVkj+KMeAR9E/ A7cgX527CnckvhGa1upHUANKfsqZ01d2LX/xPXiKOEOJ1kpuK7Gb+dBL3KzE25y59dZG dLqZ5G+Q91pk1pB6jGEEpABSq7iMcLLsLxT6cmNnH3uT2o+NitZqAOj4dFwxw/l8e9QQ xYKQ== 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=xSP7r0M+OMChiAGBMUbLG8vwkfLldxuGlk1kMONcZBc=; b=hhqAjhQqSuW7IDzBdFCvsywqBYJzQ1Rwj+uro8EG7BOQg/TuVuEw6S37qxaaKYLT/B sliIWp/idZIEUuxwFfCQg6QaEAPi2QZ6a6toxCmecv38NJqOutBfq7oE4YKLA6HAvqKp eiXJ+CZdiDWSx6htSZF2UJfAh/LC0FkGezVq/yvoOkQrnBF2OysOF3Qw48jeT/CI3bU8 jH9m8HJAFfcONnWtRaDc4lx2U8Nps+rghm73s9M7U4khM6IA7HgrSZg3uP/e9/QYq9vc pvCik5who5veqxCTzEcKzxQeNtoSKebHJtbkB4jo4GYYlCVkDJ9cChsIS6ivy+OfnzjJ 6dpA== X-Gm-Message-State: AHQUAuY8J/J5u2l03NGv+qjrSFI7qNsqvPueMJ7DFZ2R/U9F+uRHssl9 BU0Duha6+Gg+MuOTeL14qCm5wykq9bw= X-Google-Smtp-Source: AHgI3Ibl/RvqNvaID/leGxWPsyE4Vb1WjzfvmGfGzxIscCgVNF29MIkrdKCZ9Cof/5ZSKND7pblTqQ== X-Received: by 2002:a37:6c05:: with SMTP id h5mr17380723qkc.175.1549655486126; Fri, 08 Feb 2019 11:51:26 -0800 (PST) Received: from localhost.localdomain (70-33-148-227.unassigned.ntelos.net. [70.33.148.227]) by smtp.gmail.com with ESMTPSA id 12sm8253054qka.83.2019.02.08.11.51.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Feb 2019 11:51:25 -0800 (PST) From: Ben Peart To: git@vger.kernel.org Cc: benpeart@microsoft.com, kewillf@microsoft.com Subject: [PATCH v1 1/3] read-cache: add post-indexchanged hook Date: Fri, 8 Feb 2019 14:51:13 -0500 Message-Id: <20190208195115.12156-2-peartben@gmail.com> X-Mailer: git-send-email 2.20.1.windows.1 In-Reply-To: <20190208195115.12156-1-peartben@gmail.com> References: <20190208195115.12156-1-peartben@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 From: Ben Peart Add a post-indexchanged hook that is invoked after the index is written in do_write_locked_index(). This hook is meant primarily for notification, and cannot affect the outcome of git commands that trigger the index write. Signed-off-by: Ben Peart --- builtin/reset.c | 1 + builtin/update-index.c | 2 ++ cache.h | 4 +++- read-cache.c | 14 ++++++++++++-- unpack-trees.c | 2 ++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/builtin/reset.c b/builtin/reset.c index 4d18a461fa..e173afcaac 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -380,6 +380,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; if (read_from_tree(&pathspec, &oid, intent_to_add)) return 1; + the_index.updated_skipworktree = 1; if (!quiet && get_git_work_tree()) { uint64_t t_begin, t_delta_in_ms; diff --git a/builtin/update-index.c b/builtin/update-index.c index 02ace602b9..cf731640fa 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1071,6 +1071,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (entries < 0) die("cache corrupted"); + the_index.updated_skipworktree = 1; + /* * Custom copy of parse_options() because we want to handle * filename arguments as they come. diff --git a/cache.h b/cache.h index 27fe635f62..46eb862d3e 100644 --- a/cache.h +++ b/cache.h @@ -338,7 +338,9 @@ struct index_state { struct cache_time timestamp; unsigned name_hash_initialized : 1, initialized : 1, - drop_cache_tree : 1; + drop_cache_tree : 1, + updated_workdir : 1, + updated_skipworktree : 1; struct hashmap name_hash; struct hashmap dir_hash; struct object_id oid; diff --git a/read-cache.c b/read-cache.c index 0e0c93edc9..0fcfa8a075 100644 --- a/read-cache.c +++ b/read-cache.c @@ -17,6 +17,7 @@ #include "commit.h" #include "blob.h" #include "resolve-undo.h" +#include "run-command.h" #include "strbuf.h" #include "varint.h" #include "split-index.h" @@ -2999,8 +3000,17 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l if (ret) return ret; if (flags & COMMIT_LOCK) - return commit_locked_index(lock); - return close_lock_file_gently(lock); + ret = commit_locked_index(lock); + else + ret = close_lock_file_gently(lock); + + run_hook_le(NULL, "post-indexchanged", + istate->updated_workdir ? "1" : "0", + istate->updated_skipworktree ? "1" : "0", NULL); + istate->updated_workdir = 0; + istate->updated_skipworktree = 0; + + return ret; } static int write_split_index(struct index_state *istate, diff --git a/unpack-trees.c b/unpack-trees.c index 3563daae1a..8665a4a7c0 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1637,6 +1637,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options WRITE_TREE_SILENT | WRITE_TREE_REPAIR); } + + o->result.updated_workdir = 1; discard_index(o->dst_index); *o->dst_index = o->result; } else {