summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c135
1 files changed, 106 insertions, 29 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 8e2032f..11c37fb 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"));
}
/*
@@ -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)
@@ -1454,8 +1533,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);
@@ -1463,8 +1541,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),