diff options
Diffstat (limited to 'unpack-trees.c')
-rw-r--r-- | unpack-trees.c | 160 |
1 files changed, 123 insertions, 37 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index 6e9f75549d..2a963f9a7f 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -58,40 +58,74 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, int i; const char **msgs = opts->msgs; const char *msg; - const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches"; - if (advice_commit_before_merge) - msg = "Your local changes to the following files would be overwritten by %s:\n%%s" - "Please, commit your changes or stash them before you can %s."; + if (!strcmp(cmd, "checkout")) + msg = advice_commit_before_merge + ? _("Your local changes to the following files would be overwritten by checkout:\n%%s" + "Please commit your changes or stash them before you switch branches.") + : _("Your local changes to the following files would be overwritten by checkout:\n%%s"); + else if (!strcmp(cmd, "merge")) + msg = advice_commit_before_merge + ? _("Your local changes to the following files would be overwritten by merge:\n%%s" + "Please commit your changes or stash them before you merge.") + : _("Your local changes to the following files would be overwritten by merge:\n%%s"); else - msg = "Your local changes to the following files would be overwritten by %s:\n%%s"; + msg = advice_commit_before_merge + ? _("Your local changes to the following files would be overwritten by %s:\n%%s" + "Please commit your changes or stash them before you %s.") + : _("Your local changes to the following files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] = - xstrfmt(msg, cmd, cmd2); + xstrfmt(msg, cmd, cmd); msgs[ERROR_NOT_UPTODATE_DIR] = - "Updating the following directories would lose untracked files in it:\n%s"; - - if (advice_commit_before_merge) - msg = "The following untracked working tree files would be %s by %s:\n%%s" - "Please move or remove them before you can %s."; + _("Updating the following directories would lose untracked files in it:\n%s"); + + if (!strcmp(cmd, "checkout")) + msg = advice_commit_before_merge + ? _("The following untracked working tree files would be removed by checkout:\n%%s" + "Please move or remove them before you switch branches.") + : _("The following untracked working tree files would be removed by checkout:\n%%s"); + else if (!strcmp(cmd, "merge")) + msg = advice_commit_before_merge + ? _("The following untracked working tree files would be removed by merge:\n%%s" + "Please move or remove them before you merge.") + : _("The following untracked working tree files would be removed by merge:\n%%s"); else - msg = "The following untracked working tree files would be %s by %s:\n%%s"; - - msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, "removed", cmd, cmd2); - msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, "overwritten", cmd, cmd2); + msg = advice_commit_before_merge + ? _("The following untracked working tree files would be removed by %s:\n%%s" + "Please move or remove them before you %s.") + : _("The following untracked working tree files would be removed by %s:\n%%s"); + msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, cmd, cmd); + + if (!strcmp(cmd, "checkout")) + msg = advice_commit_before_merge + ? _("The following untracked working tree files would be overwritten by checkout:\n%%s" + "Please move or remove them before you switch branches.") + : _("The following untracked working tree files would be overwritten by checkout:\n%%s"); + else if (!strcmp(cmd, "merge")) + msg = advice_commit_before_merge + ? _("The following untracked working tree files would be overwritten by merge:\n%%s" + "Please move or remove them before you merge.") + : _("The following untracked working tree files would be overwritten by merge:\n%%s"); + else + msg = advice_commit_before_merge + ? _("The following untracked working tree files would be overwritten by %s:\n%%s" + "Please move or remove them before you %s.") + : _("The following untracked working tree files would be overwritten by %s:\n%%s"); + msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, cmd, cmd); /* * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we * cannot easily display it as a list. */ - msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'. Cannot bind."; + msgs[ERROR_BIND_OVERLAP] = _("Entry '%s' overlaps with '%s'. Cannot bind."); msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] = - "Cannot update sparse checkout: the following entries are not up-to-date:\n%s"; + _("Cannot update sparse checkout: the following entries are not up-to-date:\n%s"); msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] = - "The following Working tree files would be overwritten by sparse checkout update:\n%s"; + _("The following working tree files would be overwritten by sparse checkout update:\n%s"); msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] = - "The following Working tree files would be removed by sparse checkout update:\n%s"; + _("The following working tree files would be removed by sparse checkout update:\n%s"); opts->show_all_errors = 1; /* rejected paths may not have a static buffer */ @@ -168,7 +202,7 @@ static void display_error_msgs(struct unpack_trees_options *o) string_list_clear(rejects, 0); } if (something_displayed) - fprintf(stderr, "Aborting\n"); + fprintf(stderr, _("Aborting\n")); } /* @@ -184,8 +218,8 @@ static void unlink_entry(const struct cache_entry *ce) schedule_dir_for_removal(ce->name, ce_namelen(ce)); } -static struct checkout state; -static int check_updates(struct unpack_trees_options *o) +static int check_updates(struct unpack_trees_options *o, + const struct checkout *state) { unsigned cnt = 0, total = 0; struct progress *progress = NULL; @@ -230,7 +264,7 @@ static int check_updates(struct unpack_trees_options *o) display_progress(progress, ++cnt); ce->ce_flags &= ~CE_UPDATE; if (o->update && !o->dry_run) { - errs |= checkout_entry(ce, &state, NULL); + errs |= checkout_entry(ce, state, NULL); } } } @@ -475,7 +509,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, for (i = 0; i < n; i++, dirmask >>= 1) { const unsigned char *sha1 = NULL; if (dirmask & 1) - sha1 = names[i].sha1; + sha1 = names[i].oid->hash; buf[i] = fill_tree_descriptor(t+i, sha1); } @@ -498,13 +532,14 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, * itself - the caller needs to do the final check for the cache * entry having more data at the end! */ -static int do_compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n) +static int do_compare_entry_piecewise(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n) { int len, pathlen, ce_len; const char *ce_name; if (info->prev) { - int cmp = do_compare_entry(ce, info->prev, &info->name); + int cmp = do_compare_entry_piecewise(ce, info->prev, + &info->name); if (cmp) return cmp; } @@ -522,6 +557,39 @@ static int do_compare_entry(const struct cache_entry *ce, const struct traverse_ return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode); } +static int do_compare_entry(const struct cache_entry *ce, + const struct traverse_info *info, + const struct name_entry *n) +{ + int len, pathlen, ce_len; + const char *ce_name; + int cmp; + + /* + * If we have not precomputed the traverse path, it is quicker + * to avoid doing so. But if we have precomputed it, + * it is quicker to use the precomputed version. + */ + if (!info->traverse_path) + return do_compare_entry_piecewise(ce, info, n); + + cmp = strncmp(ce->name, info->traverse_path, info->pathlen); + if (cmp) + return cmp; + + pathlen = info->pathlen; + ce_len = ce_namelen(ce); + + if (ce_len < pathlen) + return -1; + + ce_len -= pathlen; + ce_name = ce->name + pathlen; + + len = tree_entry_len(n); + return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode); +} + static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n) { int cmp = do_compare_entry(ce, info, n); @@ -557,7 +625,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con ce->ce_mode = create_ce_mode(n->mode); ce->ce_flags = create_ce_flags(stage); ce->ce_namelen = len; - hashcpy(ce->sha1, n->sha1); + hashcpy(ce->sha1, n->oid->hash); make_traverse_path(ce->name, info, n); return ce; @@ -661,8 +729,19 @@ static int find_cache_pos(struct traverse_info *info, ++o->cache_bottom; continue; } - if (!ce_in_traverse_path(ce, info)) + if (!ce_in_traverse_path(ce, info)) { + /* + * Check if we can skip future cache checks + * (because we're already past all possible + * entries in the traverse path). + */ + if (info->traverse_path) { + if (strncmp(ce->name, info->traverse_path, + info->pathlen) > 0) + break; + } continue; + } ce_name = ce->name + pfxlen; ce_slash = strchr(ce_name, '/'); if (ce_slash) @@ -1015,6 +1094,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options int i, ret; static struct cache_entry *dfc; struct exclude_list el; + struct checkout state; if (len > MAX_UNPACK_TREES) die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); @@ -1029,10 +1109,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (!core_apply_sparse_checkout || !o->update) o->skip_sparse_checkout = 1; if (!o->skip_sparse_checkout) { - if (add_excludes_from_file_to_list(git_path("info/sparse-checkout"), "", 0, &el, 0) < 0) + char *sparse = git_pathdup("info/sparse-checkout"); + if (add_excludes_from_file_to_list(sparse, "", 0, &el, 0) < 0) o->skip_sparse_checkout = 1; else o->el = ⪙ + free(sparse); } memset(&o->result, 0, sizeof(o->result)); @@ -1158,8 +1240,16 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } o->src_index = NULL; - ret = check_updates(o) ? (-2) : 0; + ret = check_updates(o, &state) ? (-2) : 0; if (o->dst_index) { + if (!ret) { + if (!o->result.cache_tree) + o->result.cache_tree = cache_tree(); + if (!cache_tree_fully_valid(o->result.cache_tree)) + cache_tree_update(&o->result, + WRITE_TREE_SILENT | + WRITE_TREE_REPAIR); + } discard_index(o->dst_index); *o->dst_index = o->result; } else { @@ -1340,9 +1430,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, * Then we need to make sure that we do not lose a locally * present file that is not ignored. */ - pathbuf = xmalloc(namelen + 2); - memcpy(pathbuf, ce->name, namelen); - strcpy(pathbuf+namelen, "/"); + pathbuf = xstrfmt("%.*s/", namelen, ce->name); memset(&d, 0, sizeof(d)); if (o->dir) @@ -1446,8 +1534,7 @@ static int verify_absent_1(const struct cache_entry *ce, path = xmemdupz(ce->name, len); if (lstat(path, &st)) - ret = error("cannot stat '%s': %s", path, - strerror(errno)); + ret = error_errno("cannot stat '%s'", path); else ret = check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st, error_type, o); @@ -1455,8 +1542,7 @@ static int verify_absent_1(const struct cache_entry *ce, return ret; } else if (lstat(ce->name, &st)) { if (errno != ENOENT) - return error("cannot stat '%s': %s", ce->name, - strerror(errno)); + return error_errno("cannot stat '%s'", ce->name); return 0; } else { return check_ok_to_remove(ce->name, ce_namelen(ce), |