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=-5.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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 14C0820193 for ; Mon, 8 Aug 2016 21:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752601AbcHHVD7 (ORCPT ); Mon, 8 Aug 2016 17:03:59 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34697 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752575AbcHHVD4 (ORCPT ); Mon, 8 Aug 2016 17:03:56 -0400 Received: by mail-wm0-f67.google.com with SMTP id q128so17864879wma.1 for ; Mon, 08 Aug 2016 14:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ebgcoVdRMxyYAiOJkHRGmuXAKrpih32OFQoagJcnm2g=; b=fOPW1dfSNSQ1hTNVa02CV+vvt139FHmtxzs87/p1rgHnH5M8dXgEKMYygh+2rsABy0 cY+oV60L1a3GnlqEhy+4stlJpT+/z816+11/0nJIeZjUesElG45pCk3RX/icRDqj21rr uK6A0FoYrmSjFvSYCf/3Q+th21Ix/5XBIpgDNsG7AUkVCG2Iszx9lHf640coxDN2fdQM bMAY0I+kOSGkGEyyntCEv1Y27pnOEgFzm52TaawksB9EGRg959iq3vLwzC/lgF2BtDx6 l/cZ8UsyCKkjdvMshclOHb8esL72VtcPxHcApYrPEIsHaZmCW+wS9o4MkQphxItca+M3 GGDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ebgcoVdRMxyYAiOJkHRGmuXAKrpih32OFQoagJcnm2g=; b=VGxJ8yvuIP2QqqW3kDlLKVTHuy4Fd6G7NKZPSy62IG27f3bHoRYXBqOvlm91iU1cla RaCbr4Pg3aNtYitb7j0wopoa+oaWFLFrgK+Vca/pA7YHF/pvsPlyhBnLK8gnwKlWEWId m/DqV6FXyKPTVVNs8DgiQntm7a1S1uqTNmflxyCGzOL1mev/7XQYnfybd7xzOFuOSH8J wOrdg1ffkBY7QW4w2gWHJs9E4EXMZfzqSfwuklK0lIt1g7C5899l8ABXoTssCK2YeoDc 9EWAT/XyfKyRBykAhqy1SMv4yA6mPES8SdHmoD3DRJsBOoeyek7Ehi1doAQcCLNRS0eV UHng== X-Gm-Message-State: AEkoousLtxEBQz6xcMnpv3OH8It/tA3wNHbTrqF/IzNClIPVksQQUrVSKAiVzEdSpgmgSg== X-Received: by 10.28.209.14 with SMTP id i14mr17248884wmg.35.1470690234613; Mon, 08 Aug 2016 14:03:54 -0700 (PDT) Received: from localhost.localdomain (cha92-h01-128-78-31-246.dsl.sta.abo.bbox.fr. [128.78.31.246]) by smtp.gmail.com with ESMTPSA id o2sm8539048wjo.3.2016.08.08.14.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Aug 2016 14:03:53 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= , Karsten Blees , Nguyen Thai Ngoc Duy , Stefan Beller , Eric Sunshine , Ramsay Jones , Johannes Sixt , =?UTF-8?q?Ren=C3=A9=20Scharfe?= , Christian Couder Subject: [PATCH v10 02/40] apply: move 'struct apply_state' to apply.h Date: Mon, 8 Aug 2016 23:02:59 +0200 Message-Id: <20160808210337.5038-3-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.9.2.614.g5428e0c In-Reply-To: <20160808210337.5038-1-chriscool@tuxfamily.org> References: <20160808210337.5038-1-chriscool@tuxfamily.org> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To libify `git apply` functionality we must make 'struct apply_state' usable outside "builtin/apply.c". Let's do that by creating a new "apply.h" and moving 'struct apply_state' there. Signed-off-by: Christian Couder --- apply.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ builtin/apply.c | 98 +----------------------------------------------------- 2 files changed, 101 insertions(+), 97 deletions(-) create mode 100644 apply.h diff --git a/apply.h b/apply.h new file mode 100644 index 0000000..7493a40 --- /dev/null +++ b/apply.h @@ -0,0 +1,100 @@ +#ifndef APPLY_H +#define APPLY_H + +enum apply_ws_error_action { + nowarn_ws_error, + warn_on_ws_error, + die_on_ws_error, + correct_ws_error +}; + +enum apply_ws_ignore { + ignore_ws_none, + ignore_ws_change +}; + +/* + * We need to keep track of how symlinks in the preimage are + * manipulated by the patches. A patch to add a/b/c where a/b + * is a symlink should not be allowed to affect the directory + * the symlink points at, but if the same patch removes a/b, + * it is perfectly fine, as the patch removes a/b to make room + * to create a directory a/b so that a/b/c can be created. + * + * See also "struct string_list symlink_changes" in "struct + * apply_state". + */ +#define APPLY_SYMLINK_GOES_AWAY 01 +#define APPLY_SYMLINK_IN_RESULT 02 + +struct apply_state { + const char *prefix; + int prefix_length; + + /* These are lock_file related */ + struct lock_file *lock_file; + int newfd; + + /* These control what gets looked at and modified */ + int apply; /* this is not a dry-run */ + int cached; /* apply to the index only */ + int check; /* preimage must match working tree, don't actually apply */ + int check_index; /* preimage must match the indexed version */ + int update_index; /* check_index && apply */ + + /* These control cosmetic aspect of the output */ + int diffstat; /* just show a diffstat, and don't actually apply */ + int numstat; /* just show a numeric diffstat, and don't actually apply */ + int summary; /* just report creation, deletion, etc, and don't actually apply */ + + /* These boolean parameters control how the apply is done */ + int allow_overlap; + int apply_in_reverse; + int apply_with_reject; + int apply_verbosely; + int no_add; + int threeway; + int unidiff_zero; + int unsafe_paths; + + /* Other non boolean parameters */ + const char *fake_ancestor; + const char *patch_input_file; + int line_termination; + struct strbuf root; + int p_value; + int p_value_known; + unsigned int p_context; + + /* Exclude and include path parameters */ + struct string_list limit_by_name; + int has_include; + + /* Various "current state" */ + int linenr; /* current line number */ + struct string_list symlink_changes; /* we have to track symlinks */ + + /* + * For "diff-stat" like behaviour, we keep track of the biggest change + * we've seen, and the longest filename. That allows us to do simple + * scaling. + */ + int max_change; + int max_len; + + /* + * Records filenames that have been touched, in order to handle + * the case where more than one patches touch the same file. + */ + struct string_list fn_table; + + /* These control whitespace errors */ + enum apply_ws_error_action ws_error_action; + enum apply_ws_ignore ws_ignore_action; + const char *whitespace_option; + int whitespace_error; + int squelch_whitespace_errors; + int applied_after_fixing_ws; +}; + +#endif diff --git a/builtin/apply.c b/builtin/apply.c index ab8f0bd..ed923ca 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -20,103 +20,7 @@ #include "xdiff-interface.h" #include "ll-merge.h" #include "rerere.h" - -enum apply_ws_error_action { - nowarn_ws_error, - warn_on_ws_error, - die_on_ws_error, - correct_ws_error -}; - - -enum apply_ws_ignore { - ignore_ws_none, - ignore_ws_change -}; - -/* - * We need to keep track of how symlinks in the preimage are - * manipulated by the patches. A patch to add a/b/c where a/b - * is a symlink should not be allowed to affect the directory - * the symlink points at, but if the same patch removes a/b, - * it is perfectly fine, as the patch removes a/b to make room - * to create a directory a/b so that a/b/c can be created. - * - * See also "struct string_list symlink_changes" in "struct - * apply_state". - */ -#define APPLY_SYMLINK_GOES_AWAY 01 -#define APPLY_SYMLINK_IN_RESULT 02 - -struct apply_state { - const char *prefix; - int prefix_length; - - /* These are lock_file related */ - struct lock_file *lock_file; - int newfd; - - /* These control what gets looked at and modified */ - int apply; /* this is not a dry-run */ - int cached; /* apply to the index only */ - int check; /* preimage must match working tree, don't actually apply */ - int check_index; /* preimage must match the indexed version */ - int update_index; /* check_index && apply */ - - /* These control cosmetic aspect of the output */ - int diffstat; /* just show a diffstat, and don't actually apply */ - int numstat; /* just show a numeric diffstat, and don't actually apply */ - int summary; /* just report creation, deletion, etc, and don't actually apply */ - - /* These boolean parameters control how the apply is done */ - int allow_overlap; - int apply_in_reverse; - int apply_with_reject; - int apply_verbosely; - int no_add; - int threeway; - int unidiff_zero; - int unsafe_paths; - - /* Other non boolean parameters */ - const char *fake_ancestor; - const char *patch_input_file; - int line_termination; - struct strbuf root; - int p_value; - int p_value_known; - unsigned int p_context; - - /* Exclude and include path parameters */ - struct string_list limit_by_name; - int has_include; - - /* Various "current state" */ - int linenr; /* current line number */ - struct string_list symlink_changes; /* we have to track symlinks */ - - /* - * For "diff-stat" like behaviour, we keep track of the biggest change - * we've seen, and the longest filename. That allows us to do simple - * scaling. - */ - int max_change; - int max_len; - - /* - * Records filenames that have been touched, in order to handle - * the case where more than one patches touch the same file. - */ - struct string_list fn_table; - - /* These control whitespace errors */ - enum apply_ws_error_action ws_error_action; - enum apply_ws_ignore ws_ignore_action; - const char *whitespace_option; - int whitespace_error; - int squelch_whitespace_errors; - int applied_after_fixing_ws; -}; +#include "apply.h" static const char * const apply_usage[] = { N_("git apply [] [...]"), -- 2.9.2.614.g4980f51