@@ -36,13 +36,6 @@ static int pathspec_file_nul;
36
36
static int include_sparse ;
37
37
static const char * pathspec_from_file ;
38
38
39
- struct update_callback_data {
40
- struct index_state * index ;
41
- int include_sparse ;
42
- int flags ;
43
- int add_errors ;
44
- };
45
-
46
39
static int chmod_pathspec (struct pathspec * pathspec , char flip , int show_only )
47
40
{
48
41
int i , ret = 0 ;
@@ -71,99 +64,6 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
71
64
return ret ;
72
65
}
73
66
74
- static int fix_unmerged_status (struct diff_filepair * p ,
75
- struct update_callback_data * data )
76
- {
77
- if (p -> status != DIFF_STATUS_UNMERGED )
78
- return p -> status ;
79
- if (!(data -> flags & ADD_CACHE_IGNORE_REMOVAL ) && !p -> two -> mode )
80
- /*
81
- * This is not an explicit add request, and the
82
- * path is missing from the working tree (deleted)
83
- */
84
- return DIFF_STATUS_DELETED ;
85
- else
86
- /*
87
- * Either an explicit add request, or path exists
88
- * in the working tree. An attempt to explicitly
89
- * add a path that does not exist in the working tree
90
- * will be caught as an error by the caller immediately.
91
- */
92
- return DIFF_STATUS_MODIFIED ;
93
- }
94
-
95
- static void update_callback (struct diff_queue_struct * q ,
96
- struct diff_options * opt UNUSED , void * cbdata )
97
- {
98
- int i ;
99
- struct update_callback_data * data = cbdata ;
100
-
101
- for (i = 0 ; i < q -> nr ; i ++ ) {
102
- struct diff_filepair * p = q -> queue [i ];
103
- const char * path = p -> one -> path ;
104
-
105
- if (!data -> include_sparse &&
106
- !path_in_sparse_checkout (path , data -> index ))
107
- continue ;
108
-
109
- switch (fix_unmerged_status (p , data )) {
110
- default :
111
- die (_ ("unexpected diff status %c" ), p -> status );
112
- case DIFF_STATUS_MODIFIED :
113
- case DIFF_STATUS_TYPE_CHANGED :
114
- if (add_file_to_index (data -> index , path , data -> flags )) {
115
- if (!(data -> flags & ADD_CACHE_IGNORE_ERRORS ))
116
- die (_ ("updating files failed" ));
117
- data -> add_errors ++ ;
118
- }
119
- break ;
120
- case DIFF_STATUS_DELETED :
121
- if (data -> flags & ADD_CACHE_IGNORE_REMOVAL )
122
- break ;
123
- if (!(data -> flags & ADD_CACHE_PRETEND ))
124
- remove_file_from_index (data -> index , path );
125
- if (data -> flags & (ADD_CACHE_PRETEND |ADD_CACHE_VERBOSE ))
126
- printf (_ ("remove '%s'\n" ), path );
127
- break ;
128
- }
129
- }
130
- }
131
-
132
- int add_files_to_cache (struct repository * repo , const char * prefix ,
133
- const struct pathspec * pathspec , int include_sparse ,
134
- int flags )
135
- {
136
- struct update_callback_data data ;
137
- struct rev_info rev ;
138
-
139
- memset (& data , 0 , sizeof (data ));
140
- data .index = repo -> index ;
141
- data .include_sparse = include_sparse ;
142
- data .flags = flags ;
143
-
144
- repo_init_revisions (repo , & rev , prefix );
145
- setup_revisions (0 , NULL , & rev , NULL );
146
- if (pathspec )
147
- copy_pathspec (& rev .prune_data , pathspec );
148
- rev .diffopt .output_format = DIFF_FORMAT_CALLBACK ;
149
- rev .diffopt .format_callback = update_callback ;
150
- rev .diffopt .format_callback_data = & data ;
151
- rev .diffopt .flags .override_submodule_config = 1 ;
152
- rev .max_count = 0 ; /* do not compare unmerged paths with stage #2 */
153
-
154
- /*
155
- * Use an ODB transaction to optimize adding multiple objects.
156
- * This function is invoked from commands other than 'add', which
157
- * may not have their own transaction active.
158
- */
159
- begin_odb_transaction ();
160
- run_diff_files (& rev , DIFF_RACY_IS_MODIFIED );
161
- end_odb_transaction ();
162
-
163
- release_revisions (& rev );
164
- return !!data .add_errors ;
165
- }
166
-
167
67
static int renormalize_tracked_files (const struct pathspec * pathspec , int flags )
168
68
{
169
69
int i , retval = 0 ;
0 commit comments