git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: feature-request: git "cp" like there is git mv.

From
Stefan Beller <sbeller@google.com>
Date
Feb 7, 2018, 20:27 UTC
Message-ID
<CAGZ79kbX4uhDpdp0kH=8+5tj_zLWZbtbMUb5WWtOeXWRQz8K3Q@mail.gmail.com>
In-Reply-To
<xmqqinb87f70.fsf@gitster-ct.c.googlers.com>
On Wed, Feb 7, 2018 at 11:49 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 46 quoted lines
> 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.
>
> 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;
> +               }
This is actually changing behavior to
    if (show_only && verbose)
        print(...)
    if show_only
        continue

The second part is already there as is, only the printing behavior actually changes.

So I might be missing the obvious here for the claim of no-op?
Looking up further we have (line 177):
    if (show_only)
        printf(_("Checking rename of '%s' to '%s'\n"), src, dst);
which prints regardless of verbosity.
Previous: Junio C HamanoNext: Stefan Moch
Message 9 of 12 in “feature-request: git "cp" like there is git mv.”
  1. Simon DoodkinDec 12, 2017
  2. Johannes SchindelinDec 13, 2017
  3. Randall S. BeckerDec 13, 2017
  4. Jonathan NiederDec 16, 2017
  5. Stefan MochDec 31, 2017
  6. 1/2 Add test case for mv --dry-run to t7001-mv.shStefan Moch, Dec 31, 2017
  7. 2/2 mv: remove unneeded 'if (!show_only)'Stefan Moch, Dec 31, 2017
  8. Junio C HamanoFeb 7, 2018
  9. Stefan BellerFeb 7, 2018
  10. Stefan MochMar 18, 2018
  11. Junio C HamanoMar 19, 2018
  12. Igor DjordjevicDec 18, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.