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

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 31, 2013, 17:16 UTC
Message-ID
<CAPig+cTQV=2OFg_4OSFzkYWE8Uxz0ErWgXKOoV6mUWEMT65F4w@mail.gmail.com>
In-Reply-To
<1375288117-1576-9-git-send-email-stefanbeller@googlemail.com>

On Wed, Jul 31, 2013 at 12:28 PM, Stefan Beller <stefanbeller@googlemail.com> wrote:

Show 8 quoted lines
> 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/
Show 28 quoted lines
> 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 <stefanbeller@googlemail.com>
Previous: Stefan BellerNext: Eric Sunshine
Message 12 of 14 in “[PATCHv2 0/9] Removing deprecated parsing macros”
  1. Stefan BellerJul 31, 2013
  2. 1/9 Remove deprecated OPTION_BOOLEAN for parsing argumentsStefan Beller, Jul 31, 2013
  3. 2/9 Replace deprecated OPT_BOOLEAN by OPT_BOOLStefan Beller, Jul 31, 2013
  4. 3/9 log, format-patch: parsing uses OPT__QUIETStefan Beller, Jul 31, 2013
  5. Eric SunshineJul 31, 2013
  6. 4/9 checkout: remove superfluous local variableStefan Beller, Jul 31, 2013
  7. 5/9 branch, commit, name-rev: ease up boolean conditionsStefan Beller, Jul 31, 2013
  8. 6/9 hash-object: Replace stdin parsing OPT_BOOLEAN by OPT_COUNTUPStefan Beller, Jul 31, 2013
  9. Eric SunshineJul 31, 2013
  10. 7/9 config: parsing options: config file flag multiple timesStefan Beller, Jul 31, 2013
  11. 8/9 checkout-index: Fix negations of even numbers of -nStefan Beller, Jul 31, 2013
  12. Eric SunshineJul 31, 2013
  13. Eric SunshineJul 31, 2013
  14. 9/9 revert: use the OPT_CMDMODE for parsing, reducing codeStefan Beller, Jul 31, 2013

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.