apply: move 'struct apply_state' to apply.h
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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Aug 8, 2016 at 23:02 UTC
71501a71d0431ade410afa618adf55806e1f5f11
2 files changed
+101
-97
apply.h
new
+100
@@ -0,0 +1,100 @@
1
+#ifndef APPLY_H
2
+#define APPLY_H
3
+
4
+enum apply_ws_error_action {
5
+ nowarn_ws_error,
6
+ warn_on_ws_error,
7
+ die_on_ws_error,
8
+ correct_ws_error
9
+};
10
+
11
+enum apply_ws_ignore {
12
+ ignore_ws_none,
13
+ ignore_ws_change
14
+};
15
+
16
+/*
17
+ * We need to keep track of how symlinks in the preimage are
18
+ * manipulated by the patches. A patch to add a/b/c where a/b
19
+ * is a symlink should not be allowed to affect the directory
20
+ * the symlink points at, but if the same patch removes a/b,
21
+ * it is perfectly fine, as the patch removes a/b to make room
22
+ * to create a directory a/b so that a/b/c can be created.
23
+ *
24
+ * See also "struct string_list symlink_changes" in "struct
25
+ * apply_state".
26
+ */
27
+#define APPLY_SYMLINK_GOES_AWAY 01
28
+#define APPLY_SYMLINK_IN_RESULT 02
29
+
30
+struct apply_state {
31
+ const char *prefix;
32
+ int prefix_length;
33
+
34
+ /* These are lock_file related */
35
+ struct lock_file *lock_file;
36
+ int newfd;
37
+
38
+ /* These control what gets looked at and modified */
39
+ int apply; /* this is not a dry-run */
40
+ int cached; /* apply to the index only */
41
+ int check; /* preimage must match working tree, don't actually apply */
42
+ int check_index; /* preimage must match the indexed version */
43
+ int update_index; /* check_index && apply */
44
+
45
+ /* These control cosmetic aspect of the output */
46
+ int diffstat; /* just show a diffstat, and don't actually apply */
47
+ int numstat; /* just show a numeric diffstat, and don't actually apply */
48
+ int summary; /* just report creation, deletion, etc, and don't actually apply */
49
+
50
+ /* These boolean parameters control how the apply is done */
51
+ int allow_overlap;
52
+ int apply_in_reverse;
53
+ int apply_with_reject;
54
+ int apply_verbosely;
55
+ int no_add;
56
+ int threeway;
57
+ int unidiff_zero;
58
+ int unsafe_paths;
59
+
60
+ /* Other non boolean parameters */
61
+ const char *fake_ancestor;
62
+ const char *patch_input_file;
63
+ int line_termination;
64
+ struct strbuf root;
65
+ int p_value;
66
+ int p_value_known;
67
+ unsigned int p_context;
68
+
69
+ /* Exclude and include path parameters */
70
+ struct string_list limit_by_name;
71
+ int has_include;
72
+
73
+ /* Various "current state" */
74
+ int linenr; /* current line number */
75
+ struct string_list symlink_changes; /* we have to track symlinks */
76
+
77
+ /*
78
+ * For "diff-stat" like behaviour, we keep track of the biggest change
79
+ * we've seen, and the longest filename. That allows us to do simple
80
+ * scaling.
81
+ */
82
+ int max_change;
83
+ int max_len;
84
+
85
+ /*
86
+ * Records filenames that have been touched, in order to handle
87
+ * the case where more than one patches touch the same file.
88
+ */
89
+ struct string_list fn_table;
90
+
91
+ /* These control whitespace errors */
92
+ enum apply_ws_error_action ws_error_action;
93
+ enum apply_ws_ignore ws_ignore_action;
94
+ const char *whitespace_option;
95
+ int whitespace_error;
96
+ int squelch_whitespace_errors;
97
+ int applied_after_fixing_ws;
98
+};
99
+
100
+#endif
builtin/apply.c
+1
-97
@@ -20,103 +20,7 @@
20
#include "xdiff-interface.h"
21
#include "ll-merge.h"
22
#include "rerere.h"
23
-
24
-enum apply_ws_error_action {
25
- nowarn_ws_error,
26
- warn_on_ws_error,
27
- die_on_ws_error,
28
- correct_ws_error
29
-};
30
-
31
-
32
-enum apply_ws_ignore {
33
- ignore_ws_none,
34
- ignore_ws_change
35
-};
36
-
37
-/*
38
- * We need to keep track of how symlinks in the preimage are
39
- * manipulated by the patches. A patch to add a/b/c where a/b
40
- * is a symlink should not be allowed to affect the directory
41
- * the symlink points at, but if the same patch removes a/b,
42
- * it is perfectly fine, as the patch removes a/b to make room
43
- * to create a directory a/b so that a/b/c can be created.
44
- *
45
- * See also "struct string_list symlink_changes" in "struct
46
- * apply_state".
47
- */
48
-#define APPLY_SYMLINK_GOES_AWAY 01
49
-#define APPLY_SYMLINK_IN_RESULT 02
50
-
51
-struct apply_state {
52
- const char *prefix;
53
- int prefix_length;
54
-
55
- /* These are lock_file related */
56
- struct lock_file *lock_file;
57
- int newfd;
58
-
59
- /* These control what gets looked at and modified */
60
- int apply; /* this is not a dry-run */
61
- int cached; /* apply to the index only */
62
- int check; /* preimage must match working tree, don't actually apply */
63
- int check_index; /* preimage must match the indexed version */
64
- int update_index; /* check_index && apply */
65
-
66
- /* These control cosmetic aspect of the output */
67
- int diffstat; /* just show a diffstat, and don't actually apply */
68
- int numstat; /* just show a numeric diffstat, and don't actually apply */
69
- int summary; /* just report creation, deletion, etc, and don't actually apply */
70
-
71
- /* These boolean parameters control how the apply is done */
72
- int allow_overlap;
73
- int apply_in_reverse;
74
- int apply_with_reject;
75
- int apply_verbosely;
76
- int no_add;
77
- int threeway;
78
- int unidiff_zero;
79
- int unsafe_paths;
80
-
81
- /* Other non boolean parameters */
82
- const char *fake_ancestor;
83
- const char *patch_input_file;
84
- int line_termination;
85
- struct strbuf root;
86
- int p_value;
87
- int p_value_known;
88
- unsigned int p_context;
89
-
90
- /* Exclude and include path parameters */
91
- struct string_list limit_by_name;
92
- int has_include;
93
-
94
- /* Various "current state" */
95
- int linenr; /* current line number */
96
- struct string_list symlink_changes; /* we have to track symlinks */
97
-
98
- /*
99
- * For "diff-stat" like behaviour, we keep track of the biggest change
100
- * we've seen, and the longest filename. That allows us to do simple
101
- * scaling.
102
- */
103
- int max_change;
104
- int max_len;
105
-
106
- /*
107
- * Records filenames that have been touched, in order to handle
108
- * the case where more than one patches touch the same file.
109
- */
110
- struct string_list fn_table;
111
-
112
- /* These control whitespace errors */
113
- enum apply_ws_error_action ws_error_action;
114
- enum apply_ws_ignore ws_ignore_action;
115
- const char *whitespace_option;
116
- int whitespace_error;
117
- int squelch_whitespace_errors;
118
- int applied_after_fixing_ws;
119
-};
23
+#include "apply.h"
24
25
static const char * const apply_usage[] = {
26
N_("git apply [<options>] [<patch>...]"),