Message ID | 20200608062356.40264-2-sunshine@sunshineco.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | worktree: tighten duplicate path detection | expand |
On 08/06 02:23, Eric Sunshine wrote: Hello Eric! > Although this change seems to increase the "sentence lego quotient", it > should be reasonably safe, as the reason for removal is a distinct > clause, not strictly related to the prefix. Moreover, the "worktrees" in > "Removing worktrees/%s:" is a path literal which ought not be localized, > so by factoring it out, we can more easily avoid exposing that path > fragment to translators. Could you explain the above paragraph just a bit more? The English is confusing me a bit.
On Mon, Jun 8, 2020 at 3:38 PM Shourya Shukla <shouryashukla.oo@gmail.com> wrote: > On 08/06 02:23, Eric Sunshine wrote: > > Although this change seems to increase the "sentence lego quotient", it > > should be reasonably safe, as the reason for removal is a distinct > > clause, not strictly related to the prefix. Moreover, the "worktrees" in > > "Removing worktrees/%s:" is a path literal which ought not be localized, > > so by factoring it out, we can more easily avoid exposing that path > > fragment to translators. > > Could you explain the above paragraph just a bit more? The English is > confusing me a bit. Which part is confusing you? The "sentence lego" bit or the bit about not wanting translators touching a path literal? Or something else? The path element bit is easy: A literal path, such as ".git/worktrees/foo" should not be translated to a user's local language. Sentence lego refers to the process of composing text from several pieces. Doing so can make it difficult for a translator to localize it to a particular language because the standalone pieces don't necessarily provide sufficient context for a proper translation. For instance, this example is from [1]: Translatable strings should be entire sentences. It is often not possible to translate single verbs or adjectives in a substitutable way. printf ("File %s is %s protected", filename, rw ? "write" : "read"); Most translators will not look at the source and will thus only see the string "File %s is %s protected", which is unintelligible. Change this to printf (rw ? "File %s is write protected" : "File %s is read protected", filename); This way the translator will not only understand the message, she will also be able to find the appropriate grammatical construction. A French translator for example translates "write protected" like "protected against writing". [1]: https://www.gnu.org/software/gettext/manual/html_node/Preparing-Strings.html
diff --git a/builtin/worktree.c b/builtin/worktree.c index d99db35668..9b15f19fc5 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -76,19 +76,19 @@ static int prune_worktree(const char *id, struct strbuf *reason) ssize_t read_result; if (!is_directory(git_path("worktrees/%s", id))) { - strbuf_addf(reason, _("Removing worktrees/%s: not a valid directory"), id); + strbuf_addstr(reason, _("not a valid directory")); return 1; } if (file_exists(git_path("worktrees/%s/locked", id))) return 0; if (stat(git_path("worktrees/%s/gitdir", id), &st)) { - strbuf_addf(reason, _("Removing worktrees/%s: gitdir file does not exist"), id); + strbuf_addstr(reason, _("gitdir file does not exist")); return 1; } fd = open(git_path("worktrees/%s/gitdir", id), O_RDONLY); if (fd < 0) { - strbuf_addf(reason, _("Removing worktrees/%s: unable to read gitdir file (%s)"), - id, strerror(errno)); + strbuf_addf(reason, _("unable to read gitdir file (%s)"), + strerror(errno)); return 1; } len = xsize_t(st.st_size); @@ -96,8 +96,8 @@ static int prune_worktree(const char *id, struct strbuf *reason) read_result = read_in_full(fd, path, len); if (read_result < 0) { - strbuf_addf(reason, _("Removing worktrees/%s: unable to read gitdir file (%s)"), - id, strerror(errno)); + strbuf_addf(reason, _("unable to read gitdir file (%s)"), + strerror(errno)); close(fd); free(path); return 1; @@ -106,15 +106,15 @@ static int prune_worktree(const char *id, struct strbuf *reason) if (read_result != len) { strbuf_addf(reason, - _("Removing worktrees/%s: short read (expected %"PRIuMAX" bytes, read %"PRIuMAX")"), - id, (uintmax_t)len, (uintmax_t)read_result); + _("short read (expected %"PRIuMAX" bytes, read %"PRIuMAX")"), + (uintmax_t)len, (uintmax_t)read_result); free(path); return 1; } while (len && (path[len - 1] == '\n' || path[len - 1] == '\r')) len--; if (!len) { - strbuf_addf(reason, _("Removing worktrees/%s: invalid gitdir file"), id); + strbuf_addstr(reason, _("invalid gitdir file")); free(path); return 1; } @@ -123,7 +123,7 @@ static int prune_worktree(const char *id, struct strbuf *reason) free(path); if (stat(git_path("worktrees/%s/index", id), &st) || st.st_mtime <= expire) { - strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id); + strbuf_addstr(reason, _("gitdir file points to non-existent location")); return 1; } else { return 0; @@ -147,7 +147,8 @@ static void prune_worktrees(void) if (!prune_worktree(d->d_name, &reason)) continue; if (show_only || verbose) - printf("%s\n", reason.buf); + printf_ln(_("Removing %s/%s: %s"), + "worktrees", d->d_name, reason.buf); if (show_only) continue; delete_git_dir(d->d_name);
For each worktree removed by "git worktree prune", it reports the reason for the removal. All reasons share the common prefix "Removing worktrees/%s:". As new removal reasons are added, this prefix needs to be duplicated, which is error-prone and potentially cumbersome. Therefore, factor out the common prefix. Although this change seems to increase the "sentence lego quotient", it should be reasonably safe, as the reason for removal is a distinct clause, not strictly related to the prefix. Moreover, the "worktrees" in "Removing worktrees/%s:" is a path literal which ought not be localized, so by factoring it out, we can more easily avoid exposing that path fragment to translators. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> --- builtin/worktree.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)