Re: [PATCHv2 8/9] checkout-index: Fix negations of even numbers of -n

2013-07-31 Thread Eric Sunshine
On Wed, Jul 31, 2013 at 12:28 PM, Stefan Beller
 wrote:
> The --no-create was parsed with OPT_BOOLEAN, which has a counting up
> logic implemented. Since b04ba2bb (parse-options: deprecate OPT_BOOLEAN,
> 2011-09-27) the OPT_BOOLEAN is deprecated and is only a define:
> /* Deprecated synonym */
> #define OPTION_BOOLEAN OPTION_COUNTUP
>
> However the variable not_new, which can be counted up by giving multiple
> --no-create multiple times, is used to set a bit in the struct checkout

s/multiple --no-create multiple times/--no-create multiple times/

> bitfield (defined in cache.h:969, declared at builtin/checkout-index.c:19):
>
> state.not_new = not_new;
>
> When assigning a value other than 0 or 1 to a bit, all leading digits but
> the last are ignored and only the last bit is used for setting the bit
> variable.
>
> Hence the following:
> # in git.git:
> $ git status
> # working directory clean
> rm COPYING
> $ git status
> # deleted:COPYING
> $ git checkout-index -a -n
> # deleted:COPYING
> # which is expected as we're telling git to not restore or create
> # files, however:
> $ git checkout-index -a -n -n
> $ git status
> # working directory clean, COPYING is restored again!
> # That's the bug, we're fixing here.
>
> By restraining the variable not_new to a value being definitely 0 or 1
> by the macro OPT_BOOL the bug is fixed.
>
> Signed-off-by: Stefan Beller 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2 8/9] checkout-index: Fix negations of even numbers of -n

2013-07-31 Thread Eric Sunshine
On Wed, Jul 31, 2013 at 12:28 PM, Stefan Beller
 wrote:
> The --no-create was parsed with OPT_BOOLEAN, which has a counting up
> logic implemented. Since b04ba2bb (parse-options: deprecate OPT_BOOLEAN,
> 2011-09-27) the OPT_BOOLEAN is deprecated and is only a define:
> /* Deprecated synonym */
> #define OPTION_BOOLEAN OPTION_COUNTUP
>
> However the variable not_new, which can be counted up by giving multiple
> --no-create multiple times, is used to set a bit in the struct checkout
> bitfield (defined in cache.h:969, declared at builtin/checkout-index.c:19):
>
> state.not_new = not_new;
>
> When assigning a value other than 0 or 1 to a bit, all leading digits but
> the last are ignored and only the last bit is used for setting the bit
> variable.
>
> Hence the following:
> # in git.git:
> $ git status
> # working directory clean
> rm COPYING
> $ git status
> # deleted:COPYING
> $ git checkout-index -a -n

Missing "$ git status" at this point in example.

> # deleted:COPYING
> # which is expected as we're telling git to not restore or create
> # files, however:
> $ git checkout-index -a -n -n
> $ git status
> # working directory clean, COPYING is restored again!
> # That's the bug, we're fixing here.
>
> By restraining the variable not_new to a value being definitely 0 or 1
> by the macro OPT_BOOL the bug is fixed.
>
> Signed-off-by: Stefan Beller 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv2 8/9] checkout-index: Fix negations of even numbers of -n

2013-07-31 Thread Stefan Beller
The --no-create was parsed with OPT_BOOLEAN, which has a counting up
logic implemented. Since b04ba2bb (parse-options: deprecate OPT_BOOLEAN,
2011-09-27) the OPT_BOOLEAN is deprecated and is only a define:
/* Deprecated synonym */
#define OPTION_BOOLEAN OPTION_COUNTUP

However the variable not_new, which can be counted up by giving multiple
--no-create multiple times, is used to set a bit in the struct checkout
bitfield (defined in cache.h:969, declared at builtin/checkout-index.c:19):

state.not_new = not_new;

When assigning a value other than 0 or 1 to a bit, all leading digits but
the last are ignored and only the last bit is used for setting the bit
variable.

Hence the following:
# in git.git:
$ git status
# working directory clean
rm COPYING
$ git status
# deleted:COPYING
$ git checkout-index -a -n
# deleted:COPYING
# which is expected as we're telling git to not restore or create
# files, however:
$ git checkout-index -a -n -n
$ git status
# working directory clean, COPYING is restored again!
# That's the bug, we're fixing here.

By restraining the variable not_new to a value being definitely 0 or 1
by the macro OPT_BOOL the bug is fixed.

Signed-off-by: Stefan Beller 
---
 builtin/checkout-index.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index aa922ed..69e167b 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -188,7 +188,7 @@ int cmd_checkout_index(int argc, const char **argv, const 
char *prefix)
OPT__FORCE(&force, N_("force overwrite of existing files")),
OPT__QUIET(&quiet,
N_("no warning for existing files and files not in 
index")),
-   OPT_BOOLEAN('n', "no-create", ¬_new,
+   OPT_BOOL('n', "no-create", ¬_new,
N_("don't checkout new files")),
{ OPTION_CALLBACK, 'u', "index", &newfd, NULL,
N_("update stat information in the index file"),
-- 
1.8.4.rc0.1.g8f6a3e5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html