From: Junio C Hamano <gitster@pobox.com>
To: Ciaran McCreesh <ciaran.mccreesh@googlemail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH,RFC] Implement 'git rm --if-missing'
Date: Wed, 16 Jul 2008 11:48:42 -0700 [thread overview]
Message-ID: <7vtzepr7g5.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1216231250-21141-1-git-send-email-ciaran.mccreesh@googlemail.com> (Ciaran McCreesh's message of "Wed, 16 Jul 2008 19:00:50 +0100")
Ciaran McCreesh <ciaran.mccreesh@googlemail.com> writes:
> git rm --if-missing will only remove files if they've already been removed from
> disk.
This probably is a borderline with feaping creaturism. What's the use of
it in a real workflow that you need this for?
"git add -u" may be too broad in that it also adds anything modified, but
so is --if-missing too broad in that it removes anything removed, and if
you are going to limit by giving pathspecs _anyway_, then...
Old timers might just do:
git diff --name-only --diff-filter=D |
git update-index --remove --stdin
;-)
> diff --git a/builtin-rm.c b/builtin-rm.c
> index 22c9bd1..4b89705 100644
> --- a/builtin-rm.c
> +++ b/builtin-rm.c
> @@ -125,7 +125,7 @@ static int check_local_mod(unsigned char *head, int index_only)
> static struct lock_file lock_file;
>
> static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
> -static int ignore_unmatch = 0;
> +static int ignore_unmatch = 0, if_missing = 0;
Not your fault in entirety, but we should drop these " = 0"
initializations for static variables in a clean-up patch.
> static struct option builtin_rm_options[] = {
> OPT__DRY_RUN(&show_only),
> @@ -135,6 +135,7 @@ static struct option builtin_rm_options[] = {
> OPT_BOOLEAN('r', NULL, &recursive, "allow recursive removal"),
> OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
> "exit with a zero status even if nothing matched"),
> + OPT_BOOLEAN( 0 , "if-missing", &if_missing, "only remove missing files"),
Perhaps the command should error out if some of the named files still
exist in the working tree?
> @@ -168,6 +169,12 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
> struct cache_entry *ce = active_cache[i];
> if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
> continue;
> + if (if_missing)
> + {
> + struct stat st;
> + if ((lstat(ce->name, &st) == 0) || (errno != ENOENT))
> + continue;
> + }
(1) (Style). Opening brace comes on the same line as "if ()".
(2) (Design). How should this new option interact with --cached mode of
operation?
(3) (Design). Shouldn't "git rm --if-missing" without any pathspec remove
all missing paths from the index?
(4) If lstat fails due to I/O error or something, you do not continue and
add that path you did not get ENOENT for to the kill-list. Is that
desirable?
(5) I wonder if lstat() is enough here.
Consider:
- current commit has "kernel" symlink to "linux-2.6/" directory but
you want to remove kernel and move directory linux-2.6 to it, so:
- you run "rm kernel; mv linux-2.6 kernel"
- then you run "git rm --if-missing -- kernel"
What should the command do?
next prev parent reply other threads:[~2008-07-16 18:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-16 18:00 [PATCH,RFC] Implement 'git rm --if-missing' Ciaran McCreesh
2008-07-16 18:06 ` Petr Baudis
2008-07-16 18:17 ` Avery Pennarun
2008-07-16 18:48 ` Junio C Hamano [this message]
2008-07-16 18:58 ` Peter Baumann
2008-07-16 19:43 ` David Christensen
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vtzepr7g5.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=ciaran.mccreesh@googlemail.com \
--cc=git@vger.kernel.org \
/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.
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 NNTP newsgroup(s).