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

Re: [PATCH v8 32/41] environment: add set_index_file()

From
Christian Couder <christian.couder@gmail.com>
Date
Jul 29, 2016, 14:21 UTC
Message-ID
<CAP8UFD1SSjSGV+1e+zP4s=p+ohgSz6mct3EhPXqbde_y48ST7g@mail.gmail.com>
In-Reply-To
<CACsJy8Bi00yBb6UPm7_x8BDnwQKCXXpOPbswKtayRofmSOstcg@mail.gmail.com>
On Wed, Jul 27, 2016 at 5:14 PM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 22 quoted lines
> On Tue, Jul 26, 2016 at 9:28 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Christian Couder <christian.couder@gmail.com> writes:
>>
>>> Introduce set_index_file() to be able to temporarily change the index file.
>>>
>>> It should be used like this:
>>>
>>>     /* Save current index file */
>>>     old_index_file = get_index_file();
>>>     set_index_file((char *)tmp_index_file);
>>>
>>>     /* Do stuff that will use tmp_index_file as the index file */
>>>     ...
>>>
>>>     /* When finished reset the index file */
>>>     set_index_file(old_index_file);
>>
>> WHY is glaringly missing.
>
> It's used in a4aaa23 (builtin/am: use apply api in run_apply() -
> 2016-06-27) as a straight conversion of "GIT_INDEX_FILE=xxx git apply"
> .
Yeah, I would add something like the following to clarify the WHY:

"It is intended to be used by builtins commands to temporarily change the index file used by libified code.

This is useful when libified code uses the global index, but a builtin command wants another index file to be used instead."

>> Doesn't calling this have a global effect that is flowned upon when
>> used by a library-ish function?  Who is the expected caller in this
>> series that wants to "libify" a part of the system?
The expected caller is a builtin, like "builtin/am.c".
> I agree we should avoid this. There's a bunch of cache_name_pos() (and
> even read_cache()) in the libified apply.c, those will need to be
> converted  to take struct index_state* directly (read_index_from or
> index_name_pos).
There is a lot of other "libified" code that is calling these functions:

$ git grep -l cache_name_pos -- '*.c' | grep -v builtin apply.c diff.c dir.c merge-recursive.c pathspec.c rerere.c sha1_name.c submodule.c wt-status.c

$ git grep -l read_cache -- '*.c' | grep -v builtin | egrep -v '^t/' apply.c check-racy.c diff.c dir.c merge-recursive.c merge.c read-cache.c rerere.c revision.c sequencer.c sha1_name.c submodule.c

and some of that code is perhaps directly and indirectly called by the libified apply code.

Also I am not sure that read_cache() and cache_name_pos() are the only functions that should be changed.

So it looks like it is a very big and different project to make the current libified code be explicit about which index it is using. And by the way perhaps this other project should just remove the "the_index" global altogether.

> But at least read-cache.c has supported multiple
> indexes for a long time.
This is great, but it is unfortunately not the only lib file involved.
Previous: Duy NguyenNext: Duy Nguyen
Message 20 of 59 in “libify apply and use lib in am, part 2”
  1. 00/41 libify apply and use lib in am, part 2Christian Couder, Jun 27, 2016
  2. 03/41 builtin/apply: make apply_patch() return -1 or -128 instead of die()ingChristian Couder, Jun 27, 2016
  3. 06/41 builtin/apply: make parse_chunk() return a negative integer on errorChristian Couder, Jun 27, 2016
  4. 07/41 builtin/apply: make parse_single_patch() return -1 on errorChristian Couder, Jun 27, 2016
  5. 01/41 apply: make some names more specificChristian Couder, Jun 27, 2016
  6. 12/41 builtin/apply: make check_apply_state() return -1 instead of die()ingChristian Couder, Jun 27, 2016
  7. 19/41 builtin/apply: make build_fake_ancestor() return -1 on errorChristian Couder, Jun 27, 2016
  8. 14/41 builtin/apply: make apply_all_patches() return 128 or 1 on errorChristian Couder, Jun 27, 2016
  9. 16/41 builtin/apply: make gitdiff_*() return 1 at end of headerChristian Couder, Jun 27, 2016
  10. 28/41 builtin/apply: rename option parsing functionsChristian Couder, Jun 27, 2016
  11. 29/41 apply: rename and move opt constants to apply.hChristian Couder, Jun 27, 2016
  12. 23/41 builtin/apply: make create_file() return -1 on errorChristian Couder, Jun 27, 2016
  13. 24/41 builtin/apply: make write_out_one_result() return -1 on errorChristian Couder, Jun 27, 2016
  14. 21/41 builtin/apply: make add_conflicted_stages_file() return -1 on errorChristian Couder, Jun 27, 2016
  15. 20/41 builtin/apply: make remove_file() return -1 on errorChristian Couder, Jun 27, 2016
  16. 26/41 builtin/apply: make try_create_file() return -1 on errorChristian Couder, Jun 27, 2016
  17. 32/41 environment: add set_index_file()Christian Couder, Jun 27, 2016
  18. Junio C HamanoJul 26, 2016
  19. Duy NguyenJul 27, 2016
  20. Christian CouderJul 29, 2016
  21. Duy NguyenJul 29, 2016
  22. Christian CouderJul 29, 2016
  23. Duy NguyenJul 29, 2016
  24. Junio C HamanoJul 29, 2016
  25. 31/41 apply: make some parsing functions static againChristian Couder, Jun 27, 2016
  26. 38/41 usage: add get_error_routine() and get_warn_routine()Christian Couder, Jun 27, 2016
  27. 35/41 apply: make 'be_silent' incompatible with 'apply_verbosely'Christian Couder, Jun 27, 2016
  28. Junio C HamanoJul 26, 2016
  29. 39/41 apply: change error_routine when be_silent is setChristian Couder, Jun 27, 2016
  30. 33/41 write_or_die: use warning() instead of fprintf(stderr, ...)Christian Couder, Jun 27, 2016
  31. Junio C HamanoJun 28, 2016
  32. Christian CouderJun 30, 2016
  33. 40/41 builtin/am: use apply api in run_apply()Christian Couder, Jun 27, 2016
  34. Junio C HamanoJul 26, 2016
  35. 34/41 apply: add 'be_silent' variable to 'struct apply_state'Christian Couder, Jun 27, 2016
  36. Junio C HamanoJul 26, 2016
  37. 41/41 apply: use error_errno() where possibleChristian Couder, Jun 27, 2016
  38. 37/41 usage: add set_warn_routine()Christian Couder, Jun 27, 2016
  39. 36/41 apply: don't print on stdout when be_silent is setChristian Couder, Jun 27, 2016
  40. Junio C HamanoJul 26, 2016
  41. 22/41 builtin/apply: make add_index_file() return -1 on errorChristian Couder, Jun 27, 2016
  42. 13/41 builtin/apply: move check_apply_state() to apply.cChristian Couder, Jun 27, 2016
  43. 27/41 builtin/apply: make create_one_file() return -1 on errorChristian Couder, Jun 27, 2016
  44. 25/41 builtin/apply: make write_out_results() return -1 on errorChristian Couder, Jun 27, 2016
  45. 15/41 builtin/apply: make parse_traditional_patch() return -1 on errorChristian Couder, Jun 27, 2016
  46. 11/41 apply: make init_apply_state() return -1 instead of exit()ingChristian Couder, Jun 27, 2016
  47. 02/41 apply: move 'struct apply_state' to apply.hChristian Couder, Jun 27, 2016
  48. 04/41 builtin/apply: read_patch_file() return -1 instead of die()ingChristian Couder, Jun 27, 2016
  49. 08/41 builtin/apply: make parse_whitespace_option() return -1 instead of die()ingChristian Couder, Jun 27, 2016
  50. 09/41 builtin/apply: make parse_ignorewhitespace_option() return -1 instead of die()ingChristian Couder, Jun 27, 2016
  51. 05/41 builtin/apply: make find_header() return -128 instead of die()ingChristian Couder, Jun 27, 2016
  52. 18/41 builtin/apply: change die_on_unsafe_path() to check_unsafe_path()Christian Couder, Jun 27, 2016
  53. 17/41 builtin/apply: make gitdiff_*() return -1 on errorChristian Couder, Jun 27, 2016
  54. 10/41 builtin/apply: move init_apply_state() to apply.cChristian Couder, Jun 27, 2016
  55. Christian CouderJun 27, 2016
  56. Junio C HamanoJul 26, 2016
  57. Christian CouderJul 27, 2016
  58. Junio C HamanoJul 27, 2016
  59. Christian CouderJul 30, 2016

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.