From: Stefan Moch <stefanmoch@mail.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Simon Doodkin <helpmepro1@gmail.com>,
git@vger.kernel.org, Stefan Beller <sbeller@google.com>
Subject: Re: feature-request: git "cp" like there is git mv.
Date: Sun, 18 Mar 2018 21:09:08 +0100 [thread overview]
Message-ID: <20180318210908.3ed94777.stefanmoch@mail.de> (raw)
In-Reply-To: <xmqqinb87f70.fsf@gitster-ct.c.googlers.com>
* Junio C Hamano <gitster@pobox.com> [2018-02-07T11:49:39-0800]:
> Stefan Moch <stefanmoch@mail.de> writes:
>
> > * Jonathan Nieder <jrnieder@gmail.com> [2017-12-15T17:31:30-0800]:
> >> This sounds like a reasonable thing to add. See builtin/mv.c for
> >> how "git mv" works if you're looking for inspiration.
> >>
> >> cmd_mv in that file looks rather long, so I'd also be happy if
> >> someone interested refactors to break it into multiple
> >> self-contained pieces for easier reading (git mostly follows
> >> https://www.kernel.org/doc/html/latest/process/coding-style.html#functions).
> >
> > I looked at builtin/mv.c and have a rough idea how to split it
> > up to support both mv and cp commands.
> >
> > But first I noticed and removed a redundant check in cmd_mv,
> > also added a test case to check if mv --dry-run does not move
> > the file.
>
> I guess these two patches went unnoticed when posted at the end of
> last year. Reading them again, I think they are good changes.
Thanks.
Are such redundant checks in general a pattern worth searching
for and cleaning up globally? Or is this rather in the category
of cleaning up only when noticed?
> As a no-op clean-up of a127331c ("mv: allow moving nested
> submodules", 2016-04-19), the attached would also make sense, I
> would think.
>
> Thanks.
>
> builtin/mv.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/mv.c b/builtin/mv.c
> index 9662804d23..9cb07990fd 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -266,10 +266,11 @@ int cmd_mv(int argc, const char **argv, const
> char *prefix) const char *src = source[i], *dst = destination[i];
> enum update_mode mode = modes[i];
> int pos;
> - if (show_only || verbose)
> - printf(_("Renaming %s to %s\n"), src, dst);
> - if (show_only)
> + if (show_only) {
> + if (verbose)
> + printf(_("Renaming %s to %s\n"),
> src, dst); continue;
> + }
> if (mode != INDEX && rename(src, dst) < 0) {
> if (ignore_errors)
> continue;
>
As Stefan Beller already noted, this changes the printing
behavior:
<https://public-inbox.org/git/CAGZ79kbX4uhDpdp0kH=8+5tj_zLWZbtbMUb5WWtOeXWRQz8K3Q@mail.gmail.com/>
See also the output of
git mv -n
git mv -n -v
git mv -v
without your patch:
$ git mv -n 1 2
Checking rename of '1' to '2'
Renaming 1 to 2
$ git mv -n -v 1 2
Checking rename of '1' to '2'
Renaming 1 to 2
$ git mv -v 1 2
Renaming 1 to 2
and with your patch:
$ git mv -n 1 2
Checking rename of '1' to '2'
$ git mv -n -v 1 2
Checking rename of '1' to '2'
Renaming 1 to 2
$ git mv -v 1 2
Having different outputs of “git mv -n” and “git mv -n -v” seems
odd, but not necessarily wrong. However, “git mv -v” with no
output at all, does not what the documentation says:
-v, --verbose
Report the names of files as they are moved.
next prev parent reply other threads:[~2018-03-18 20:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-12 10:53 feature-request: git "cp" like there is git mv Simon Doodkin
2017-12-13 16:39 ` Johannes Schindelin
2017-12-13 17:21 ` Randall S. Becker
2017-12-16 1:31 ` Jonathan Nieder
2017-12-31 19:11 ` Stefan Moch
2017-12-31 19:11 ` [PATCH 1/2] Add test case for mv --dry-run to t7001-mv.sh Stefan Moch
2017-12-31 19:11 ` [PATCH 2/2] mv: remove unneeded 'if (!show_only)' Stefan Moch
2018-02-07 19:49 ` feature-request: git "cp" like there is git mv Junio C Hamano
2018-02-07 20:27 ` Stefan Beller
2018-03-18 20:09 ` Stefan Moch [this message]
2018-03-19 20:03 ` Junio C Hamano
2017-12-18 0:28 ` Igor Djordjevic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180318210908.3ed94777.stefanmoch@mail.de \
--to=stefanmoch@mail.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=helpmepro1@gmail.com \
--cc=jrnieder@gmail.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).