From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 47D291F404 for ; Mon, 11 Dec 2017 14:13:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753104AbdLKONw (ORCPT ); Mon, 11 Dec 2017 09:13:52 -0500 Received: from smtp-out-3.talktalk.net ([62.24.135.67]:7040 "EHLO smtp-out-3.talktalk.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753018AbdLKONr (ORCPT ); Mon, 11 Dec 2017 09:13:47 -0500 Received: from lindisfarne.localdomain ([92.22.30.250]) by smtp.talktalk.net with SMTP id OOpteDPs4CbAZOOq2eBivl; Mon, 11 Dec 2017 14:13:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=talktalk.net; s=cmr1711; t=1513001627; bh=8hrm3Ag0jKETq3OagO3vWCzazNKWnYWPenSdzuWnnfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=OMet2J08CXpX5yCXzHxLuf+PtcAneNTkpeMbcM+YsA7rFhjOfG+nH7Bm/29ihbZZy LAFyeAzlUzEfpffUgsSyvaiwdFmvB3gDKdZEyeyFkRCQJtM4zx9KS+bf5Br+gonf4D UIdnfGL9nbaPJdt0rHBTB4WFLBw8w9/jASWJMbVc= X-Originating-IP: [92.22.30.250] X-Spam: 0 X-OAuthority: v=2.2 cv=JvuBlIwC c=1 sm=1 tr=0 a=hCO86xb6nvxPok+3LE1svw==:117 a=hCO86xb6nvxPok+3LE1svw==:17 a=evINK-nbAAAA:8 a=swPmyTYr8vmIW86sC0sA:9 a=paSYzrFEh-WyBHKX:21 a=DzFob3GGma4QAaSY:21 a=RfR_gqz1fSpA9VikTjo0:22 From: Phillip Wood To: Git Mailing List Cc: Johannes Schindelin , Junio C Hamano , Ramsay Jones , Adam Dinwoodie , Stefan Beller , Phillip Wood Subject: [PATCH v5 4/9] commit: move post-rewrite code to libgit Date: Mon, 11 Dec 2017 14:13:25 +0000 Message-Id: <20171211141330.23566-5-phillip.wood@talktalk.net> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171211141330.23566-1-phillip.wood@talktalk.net> References: <20170925101041.18344-1-phillip.wood@talktalk.net> <20171211141330.23566-1-phillip.wood@talktalk.net> Reply-To: Phillip Wood X-CMAE-Envelope: MS4wfCOX2IO/S2ZIhDmBWeV7qA0J2H/kpLKDVanop7AemI5Ep5YQpWDdd8sGlClzebRFhe81anAtVH5eAAVMgyUA1XX28jJm+keIUvysUR3SW+HJJRptI/uc 7apVDlkqTbXXlHun0PhbiYL0ZdQZoWSx8CXlZbnXP4HX8gVLy5w6fnh23cnyusyo8T83W4jLnipghLH5qNYv0ycV4LZj/Pr9//WguckC+nNzs8oRIgRw8stg 2/iOybZ/6LIMMXSOOb6pC9FroIRBugfIDU/7NMsbJwkkZw0cTVb/Znncl5vRksbMNjJppctEtchCd47gVrMgBISZEw9WrDImR2YE00KC+CCvIluZKvCZTsEY JN2AJhYWQ7ggtBn/3aKXVfRcZMt2GX8EHOi0KobhfeT1TGkknI8= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood Move run_rewrite_hook() from bulitin/commit.c to sequencer.c so it can be shared with other commands and add a new function commit_post_rewrite() based on the code in builtin/commit.c that encapsulates rewriting notes and running the post-rewrite hook. Once the sequencer learns how to create commits without forking 'git commit' these functions will be used when squashing commits. Signed-off-by: Phillip Wood --- Notes: changes since v1: - reword commit message to explain why the code is being moved builtin/commit.c | 42 +----------------------------------------- sequencer.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ sequencer.h | 2 ++ 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 340cc2988ebdb92ef222b677ee12c94fa53aa1ff..d376d282cda95d491f2fcbee5063709d02aed77a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -31,9 +31,7 @@ #include "gpg-interface.h" #include "column.h" #include "sequencer.h" -#include "notes-utils.h" #include "mailmap.h" -#include "sigchain.h" static const char * const builtin_commit_usage[] = { N_("git commit [] [--] ..."), @@ -1497,37 +1495,6 @@ static int git_commit_config(const char *k, const char *v, void *cb) return git_status_config(k, v, s); } -static int run_rewrite_hook(const struct object_id *oldoid, - const struct object_id *newoid) -{ - struct child_process proc = CHILD_PROCESS_INIT; - const char *argv[3]; - int code; - struct strbuf sb = STRBUF_INIT; - - argv[0] = find_hook("post-rewrite"); - if (!argv[0]) - return 0; - - argv[1] = "amend"; - argv[2] = NULL; - - proc.argv = argv; - proc.in = -1; - proc.stdout_to_stderr = 1; - - code = start_command(&proc); - if (code) - return code; - strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid)); - sigchain_push(SIGPIPE, SIG_IGN); - write_in_full(proc.in, sb.buf, sb.len); - close(proc.in); - strbuf_release(&sb); - sigchain_pop(SIGPIPE); - return finish_command(&proc); -} - int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) { struct argv_array hook_env = ARGV_ARRAY_INIT; @@ -1758,14 +1725,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) rerere(0); run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { - struct notes_rewrite_cfg *cfg; - cfg = init_copy_notes_for_rewrite("amend"); - if (cfg) { - /* we are amending, so current_head is not NULL */ - copy_note_for_rewrite(cfg, ¤t_head->object.oid, &oid); - finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); - } - run_rewrite_hook(¤t_head->object.oid, &oid); + commit_post_rewrite(current_head, &oid); } if (!quiet) print_summary(prefix, &oid, !current_head); diff --git a/sequencer.c b/sequencer.c index 5fe6ef3512566622f0423a09cbffe1adf1e65957..132319be0dbc15ed34f87af769235a4c6f3c6159 100644 --- a/sequencer.c +++ b/sequencer.c @@ -21,6 +21,8 @@ #include "log-tree.h" #include "wt-status.h" #include "hashmap.h" +#include "notes-utils.h" +#include "sigchain.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -790,6 +792,51 @@ int update_head_with_reflog(const struct commit *old_head, return ret; } +static int run_rewrite_hook(const struct object_id *oldoid, + const struct object_id *newoid) +{ + struct child_process proc = CHILD_PROCESS_INIT; + const char *argv[3]; + int code; + struct strbuf sb = STRBUF_INIT; + + argv[0] = find_hook("post-rewrite"); + if (!argv[0]) + return 0; + + argv[1] = "amend"; + argv[2] = NULL; + + proc.argv = argv; + proc.in = -1; + proc.stdout_to_stderr = 1; + + code = start_command(&proc); + if (code) + return code; + strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid)); + sigchain_push(SIGPIPE, SIG_IGN); + write_in_full(proc.in, sb.buf, sb.len); + close(proc.in); + strbuf_release(&sb); + sigchain_pop(SIGPIPE); + return finish_command(&proc); +} + +void commit_post_rewrite(const struct commit *old_head, + const struct object_id *new_head) +{ + struct notes_rewrite_cfg *cfg; + + cfg = init_copy_notes_for_rewrite("amend"); + if (cfg) { + /* we are amending, so old_head is not NULL */ + copy_note_for_rewrite(cfg, &old_head->object.oid, new_head); + finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); + } + run_rewrite_hook(&old_head->object.oid, new_head); +} + static int is_original_commit_empty(struct commit *commit) { const struct object_id *ptree_oid; diff --git a/sequencer.h b/sequencer.h index 3757a7aecb5a7795d7b9b45964f3328ee852e14b..e97fb288498bf524e43db4217087cb66682fad52 100644 --- a/sequencer.h +++ b/sequencer.h @@ -72,4 +72,6 @@ int update_head_with_reflog(const struct commit *old_head, const struct object_id *new_head, const char *action, const struct strbuf *msg, struct strbuf *err); +void commit_post_rewrite(const struct commit *current_head, + const struct object_id *new_head); #endif -- 2.15.1