462
return new;
463
}
464
465
-int add_file_to_index(struct index_state *istate, const char *path, int verbose)
465
+int add_to_index(struct index_state *istate, const char *path, struct stat *st, int verbose)
466
{
467
int size, namelen;
468
- struct stat st;
468
+ mode_t st_mode = st->st_mode;
469
struct cache_entry *ce, *alias;
470
unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_RACY_IS_DIRTY;
471
472
- if (lstat(path, &st))
473
- die("%s: unable to stat (%s)", path, strerror(errno));
474
-
475
- if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode))
472
+ if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
473
die("%s: can only add regular files, symbolic links or git-directories", path);
474
475
namelen = strlen(path);
479
- if (S_ISDIR(st.st_mode)) {
476
+ if (S_ISDIR(st_mode)) {
477
while (namelen && path[namelen-1] == '/')
478
namelen--;
479
}
481
ce = xcalloc(1, size);
482
memcpy(ce->name, path, namelen);
483
ce->ce_flags = namelen;
487
- fill_stat_cache_info(ce, &st);
484
+ fill_stat_cache_info(ce, st);
485
486
if (trust_executable_bit && has_symlinks)
490
- ce->ce_mode = create_ce_mode(st.st_mode);
487
+ ce->ce_mode = create_ce_mode(st_mode);
488
else {
489
/* If there is an existing entry, pick the mode bits and type
490
* from it, otherwise assume unexecutable regular file.
493
int pos = index_name_pos_also_unmerged(istate, path, namelen);
494
495
ent = (0 <= pos) ? istate->cache[pos] : NULL;
499
- ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
496
+ ce->ce_mode = ce_mode_from_stat(ent, st_mode);
497
}
498
499
alias = index_name_exists(istate, ce->name, ce_namelen(ce), ignore_case);
503
- if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, &st, ce_option)) {
500
+ if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
501
/* Nothing changed, really */
502
free(ce);
503
ce_mark_uptodate(alias);
504
alias->ce_flags |= CE_ADDED;
505
return 0;
506
}
510
- if (index_path(ce->sha1, path, &st, 1))
507
+ if (index_path(ce->sha1, path, st, 1))
508
die("unable to index file %s", path);
509
if (ignore_case && alias && different_name(ce, alias))
510
ce = create_alias_ce(ce, alias);
516
return 0;
517
}
518
519
+int add_file_to_index(struct index_state *istate, const char *path, int verbose)
520
+{
521
+ struct stat st;
522
+ if (lstat(path, &st))
523
+ die("%s: unable to stat (%s)", path, strerror(errno));
524
+ return add_to_index(istate, path, &st, verbose);
525
+}
526
+
527
struct cache_entry *make_cache_entry(unsigned int mode,
528
const unsigned char *sha1, const char *path, int stage,
529
int refresh)