18
static int allow_add;
19
static int allow_remove;
20
static int allow_replace;
21
-static int allow_unmerged; /* --refresh needing merge is not error */
22
-static int not_new; /* --refresh not having working tree files is not error */
23
-static int quiet; /* --refresh needing update is not error */
21
static int info_only;
22
static int force_remove;
23
static int verbose;
25
#define MARK_VALID 1
26
#define UNMARK_VALID 2
27
31
-
32
-/* Three functions to allow overloaded pointer return; see linux/err.h */
33
-static inline void *ERR_PTR(long error)
34
-{
35
- return (void *) error;
36
-}
37
-
38
-static inline long PTR_ERR(const void *ptr)
39
-{
40
- return (long) ptr;
41
-}
42
-
43
-static inline long IS_ERR(const void *ptr)
44
-{
45
- return (unsigned long)ptr > (unsigned long)-1000L;
46
-}
47
-
28
static void report(const char *fmt, ...)
29
{
30
va_list vp;
120
return 0;
121
}
122
143
-/*
144
- * "refresh" does not calculate a new sha1 file or bring the
145
- * cache up-to-date for mode/content changes. But what it
146
- * _does_ do is to "re-match" the stat information of a file
147
- * with the cache, so that you can refresh the cache for a
148
- * file that hasn't been changed but where the stat entry is
149
- * out of date.
150
- *
151
- * For example, you'd want to do this after doing a "git-read-tree",
152
- * to link up the stat cache details with the proper files.
153
- */
154
-static struct cache_entry *refresh_entry(struct cache_entry *ce, int really)
155
-{
156
- struct stat st;
157
- struct cache_entry *updated;
158
- int changed, size;
159
-
160
- if (lstat(ce->name, &st) < 0)
161
- return ERR_PTR(-errno);
162
-
163
- changed = ce_match_stat(ce, &st, really);
164
- if (!changed) {
165
- if (really && assume_unchanged &&
166
- !(ce->ce_flags & htons(CE_VALID)))
167
- ; /* mark this one VALID again */
168
- else
169
- return NULL;
170
- }
171
-
172
- if (ce_modified(ce, &st, really))
173
- return ERR_PTR(-EINVAL);
174
-
175
- size = ce_size(ce);
176
- updated = xmalloc(size);
177
- memcpy(updated, ce, size);
178
- fill_stat_cache_info(updated, &st);
179
-
180
- /* In this case, if really is not set, we should leave
181
- * CE_VALID bit alone. Otherwise, paths marked with
182
- * --no-assume-unchanged (i.e. things to be edited) will
183
- * reacquire CE_VALID bit automatically, which is not
184
- * really what we want.
185
- */
186
- if (!really && assume_unchanged && !(ce->ce_flags & htons(CE_VALID)))
187
- updated->ce_flags &= ~htons(CE_VALID);
188
-
189
- return updated;
190
-}
191
-
192
-static int refresh_cache(int really)
193
-{
194
- int i;
195
- int has_errors = 0;
196
-
197
- for (i = 0; i < active_nr; i++) {
198
- struct cache_entry *ce, *new;
199
- ce = active_cache[i];
200
- if (ce_stage(ce)) {
201
- while ((i < active_nr) &&
202
- ! strcmp(active_cache[i]->name, ce->name))
203
- i++;
204
- i--;
205
- if (allow_unmerged)
206
- continue;
207
- printf("%s: needs merge\n", ce->name);
208
- has_errors = 1;
209
- continue;
210
- }
211
-
212
- new = refresh_entry(ce, really);
213
- if (!new)
214
- continue;
215
- if (IS_ERR(new)) {
216
- if (not_new && PTR_ERR(new) == -ENOENT)
217
- continue;
218
- if (really && PTR_ERR(new) == -EINVAL) {
219
- /* If we are doing --really-refresh that
220
- * means the index is not valid anymore.
221
- */
222
- ce->ce_flags &= ~htons(CE_VALID);
223
- active_cache_changed = 1;
224
- }
225
- if (quiet)
226
- continue;
227
- printf("%s: needs update\n", ce->name);
228
- has_errors = 1;
229
- continue;
230
- }
231
- active_cache_changed = 1;
232
- /* You can NOT just free active_cache[i] here, since it
233
- * might not be necessarily malloc()ed but can also come
234
- * from mmap(). */
235
- active_cache[i] = new;
236
- }
237
- return has_errors;
238
-}
239
-
123
/*
124
* We fundamentally don't like some paths: we don't want
125
* dot or dot-dot anywhere, and for obvious reasons don't
536
const char *prefix = setup_git_directory();
537
int prefix_length = prefix ? strlen(prefix) : 0;
538
char set_executable_bit = 0;
539
+ unsigned int refresh_flags = 0;
540
541
git_config(git_default_config);
542
557
continue;
558
}
559
if (!strcmp(path, "-q")) {
676
- quiet = 1;
560
+ refresh_flags |= REFRESH_QUIET;
561
continue;
562
}
563
if (!strcmp(path, "--add")) {
573
continue;
574
}
575
if (!strcmp(path, "--unmerged")) {
692
- allow_unmerged = 1;
576
+ refresh_flags |= REFRESH_UNMERGED;
577
continue;
578
}
579
if (!strcmp(path, "--refresh")) {
696
- has_errors |= refresh_cache(0);
580
+ has_errors |= refresh_cache(refresh_flags);
581
continue;
582
}
583
if (!strcmp(path, "--really-refresh")) {
700
- has_errors |= refresh_cache(1);
584
+ has_errors |= refresh_cache(REFRESH_REALLY | refresh_flags);
585
continue;
586
}
587
if (!strcmp(path, "--cacheinfo")) {
654
goto finish;
655
}
656
if (!strcmp(path, "--ignore-missing")) {
773
- not_new = 1;
657
+ refresh_flags |= REFRESH_IGNORE_MISSING;
658
continue;
659
}
660
if (!strcmp(path, "--verbose")) {