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

Re: [PATCH 1/5] argv-array: Add argv_array_pop function [v2]

From
Neil Horman <nhorman@tuxdriver.com>
Date
Apr 6, 2012, 01:12 UTC
Message-ID
<20120406011252.GA7204@neilslaptop.think-freely.org>
In-Reply-To
<20120406001942.GA14224@sigill.intra.peff.net>
On Thu, Apr 05, 2012 at 08:19:42PM -0400, Jeff King wrote:
Show 14 quoted lines
> On Thu, Apr 05, 2012 at 07:24:29PM -0400, Neil Horman wrote:
> 
> > > > CC: Jeff King <peff@peff.net>
> > > > CC: Phil Hord <phil.hord@gmail.com>
> > > > CC: Junio C Hamano <gitster@pobox.com>
> > > > ---
> > > 
> > > Please don't do "Cc:" here; they belong to your e-mail header.
> > > 
> > You mean place them below the snip line?  I can do that.
> 
> No, I think he means to drop them entirely; that information is already
> in the list of people you have cc'd in the email.
> 

No, its not, thats what I'm saying. git send-email parses the above information to build the CC list. I can take it out and add the cc's to the command line of git-send-email, but if parsing the above info is incorrect, that seems like a bug that needs fixing, one which will get resistance, because its the standard way alot of other lists use the CC: tag.

Show 56 quoted lines
> > > > +int argv_array_pop(struct argv_array *array, unsigned int num)
> > > > +{
> > > > +	if (num > array->argc)
> > > > +		return -1;
> > > 
> > > If your use case is "After using an argv_array for the first invocation,
> > > truncate it while keeping the common ones that appear early, so that ones
> > > that are specific to the second invocation can be pushed", it strikes me
> > > somewhat odd why you would want to specify "how many to pop".
> > > 
> > Why?  It seems perfectly logical to me to be able to, as a convienience, specify
> > how many items to pop, and the api call seems pleasantly symmetric to the
> > push[f] calls.
> 
> I don't mind a "pop" call if there is a good use, but personally I find
> your use case to be hard to read. Your patch 3/5 does this:
> 
>   /* make a partial argv */
>   argv_array_init(&array);
>   argv_array_push(&array, "commit");
>   argv_array_push(&array, "-n");
> 
>   /* now do some speculative command */
>   if (some_logic) {
>           argv_array_push(&array, "--porcelain");
>           if (run_command(array.argv)) {
>               argv_array_clear(&array);
>               return 0;
>           }
>           argv_array_pop(&array, 1);
>   }
> 
>   /* and then possibly proceed to reuse part of the array */
>   argv_array_push(&array, ...);
>   argv_array_push(&array, ...);
>   run_command(array.argv);
> 
> It saves you having to repeat "commit -n", but at the expense of making
> the logic much harder to read. I think this is much easier to read:
> 
>   if (some_logic) {
>           const char *argv[] = { "commit", "-n", "--porcelain", NULL };
>           if (run_command(argv))
>                   return 0;
>   }
> 
>   argv_array_init(&array);
>   argv_array_push(&array, "commit");
>   argv_array_push(&array, "-n");
>   argv_array_push(&array, /* other options */);
>   run_command(array.argv);
> 
> You repeat "-n", but it is very clear what goes into the speculative
> command and what goes into the final command (and there is no chance of
> the "1" in your pop becoming stale and sending cruft to the real command).
> 
Ok, I can see the use of the argv array above being more readable, but (I think
your) comment from the first iteration of this patch, suggested re-doing this
logic to use struct argv_array.  I do like the above better.  I'll redo that.
 
> That being said, I think Junio commented on 3/5 that "git commit
> --porcelain" is not the right way of doing your speculative command
> anyway, so the two commands would not end up sharing any argv anyway.
>
I'm still not completely convinced about that, given that commit --porcelain
effectively does a git diff-index, but I'll defer to the experts on that,
diff-index works just as well for this.  And if I use your above static array
implementation instead, I can get rid of the pop api addition entirely.
 
Show 9 quoted lines
> > > > +	for(num--; num>0; num--) {
> > > 
> > > Gaah.
> > > 
> > Eeek :).  If you want something else equally....equal here, please ask for it.
> > I prefer for loops, but if you would rather have a while loop here, I'm fine
> > with that.
> 
> I think he may have been responding to the style (lack of whitespace). I

That was really my problem with it. I appreciate the direct comment. A note about lack of whitespace is something I can work with, Gaah is not :)

> also find a side-effecting initializer a little non-idiomatic. And
> indeed, I think it causes a bug in this case. "num" is an unsigned int.
> So what happens to the loop when num is 0 coming in?
> 

That should be caught by the case checking logic at the top of the function. Although I think you're right, the 1 case I think has an OBO error. Its moot anyway, if I use your static array approach above, I'll remove all of this.

Show 7 quoted lines
> I think a more traditional way of writing this would be:
> 
>   while (num--) {
>           free((char **)array->argv[num);
>           array->argv[num] = NULL;
>   }
> 

Thats certainly another way to do it, and I'm happy to do that if its the consensus. I just happen to prefer for loops (for no particular reason, its just me). But again, using your approach above, this will all get removed.

Thanks for the review.  I'll fix this up, and have a new version in a few days.

Best Neil

> -Peff
> 
Previous: Jeff KingNext: Junio C Hamano
Message 24 of 121 in “Enhance git-rebases flexibiilty in handling empty commits”
  1. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Mar 30, 2012
  2. 1/4 git-cherry-pick: add keep-empty optionNeil Horman, Mar 30, 2012
  3. Junio C HamanoMar 30, 2012
  4. Jeff KingMar 30, 2012
  5. Neil HormanMar 31, 2012
  6. 2/4 git-rebase: add keep_empty flagNeil Horman, Mar 30, 2012
  7. Junio C HamanoMar 30, 2012
  8. Neil HormanMar 31, 2012
  9. 3/4 git-commit-am: Allow automatic rebasing to preserve empty commitsNeil Horman, Mar 30, 2012
  10. Junio C HamanoMar 30, 2012
  11. Neil HormanMar 31, 2012
  12. Junio C HamanoMar 30, 2012
  13. Neil HormanMar 31, 2012
  14. 4/4 git-commit-interactive: Allow rebasing to preserve empty commitsNeil Horman, Mar 30, 2012
  15. Junio C HamanoMar 30, 2012
  16. Neil HormanMar 31, 2012
  17. Junio C HamanoMar 30, 2012
  18. 0/5 Enhance git-rebases flexibiilty handling empty commits [v2]Neil Horman, Apr 5, 2012
  19. 1/5 argv-array: Add argv_array_pop function [v2]Neil Horman, Apr 5, 2012
  20. Junio C HamanoApr 5, 2012
  21. Neil HormanApr 5, 2012
  22. Neil HormanApr 6, 2012
  23. Jeff KingApr 6, 2012
  24. Neil HormanApr 6, 2012
  25. Junio C HamanoApr 6, 2012
  26. Jeff KingApr 6, 2012
  27. Cc tags in the commit message (Re: [PATCH 1/5] argv-array: Add argv_array_pop function [v2])Jonathan Nieder, Apr 6, 2012
  28. Junio C HamanoApr 6, 2012
  29. Jeff KingApr 6, 2012
  30. Junio C HamanoApr 6, 2012
  31. Neil HormanApr 6, 2012
  32. 2/5 git-cherry-pick: add allow-empty option [v2]Neil Horman, Apr 5, 2012
  33. 3/5 git-cherry-pick: Add ignore-if-made-empty option [v2]Neil Horman, Apr 5, 2012
  34. Junio C HamanoApr 5, 2012
  35. Neil HormanApr 5, 2012
  36. Junio C HamanoApr 6, 2012
  37. Neil HormanApr 6, 2012
  38. Johannes SixtApr 6, 2012
  39. 4/5 git-cherry-pick: Add test to validate new options [v2]Neil Horman, Apr 5, 2012
  40. 5/5 git-rebase: add keep_empty flag [v2]Neil Horman, Apr 5, 2012
  41. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 10, 2012
  42. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 10, 2012
  43. Junio C HamanoApr 10, 2012
  44. Neil HormanApr 10, 2012
  45. Junio C HamanoApr 10, 2012
  46. Neil HormanApr 10, 2012
  47. Junio C HamanoApr 10, 2012
  48. Neil HormanApr 10, 2012
  49. Junio C HamanoApr 10, 2012
  50. Neil HormanApr 11, 2012
  51. Junio C HamanoApr 11, 2012
  52. Neil HormanApr 11, 2012
  53. Junio C HamanoApr 11, 2012
  54. Neil HormanApr 11, 2012
  55. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 10, 2012
  56. Junio C HamanoApr 10, 2012
  57. Neil HormanApr 10, 2012
  58. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 10, 2012
  59. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 10, 2012
  60. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 13, 2012
  61. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 13, 2012
  62. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 13, 2012
  63. Clemens BuchacherApr 15, 2012
  64. Neil HormanApr 16, 2012
  65. Clemens BuchacherApr 16, 2012
  66. Neil HormanApr 17, 2012
  67. Junio C HamanoApr 17, 2012
  68. Clemens BuchacherApr 17, 2012
  69. Neil HormanApr 18, 2012
  70. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 13, 2012
  71. Clemens BuchacherApr 15, 2012
  72. Neil HormanApr 16, 2012
  73. Neil HormanApr 16, 2012
  74. Junio C HamanoApr 16, 2012
  75. Neil HormanApr 16, 2012
  76. Clemens BuchacherApr 16, 2012
  77. Neil HormanApr 17, 2012
  78. Clemens BuchacherApr 17, 2012
  79. Neil HormanApr 18, 2012
  80. Clemens BuchacherApr 18, 2012
  81. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 13, 2012
  82. Clemens BuchacherApr 15, 2012
  83. Neil HormanApr 16, 2012
  84. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 17, 2012
  85. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 17, 2012
  86. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 17, 2012
  87. Clemens BuchacherApr 17, 2012
  88. Neil HormanApr 18, 2012
  89. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 17, 2012
  90. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 17, 2012
  91. Clemens BuchacherApr 17, 2012
  92. Neil HormanApr 18, 2012
  93. Junio C HamanoApr 18, 2012
  94. Neil HormanApr 19, 2012
  95. Junio C HamanoApr 19, 2012
  96. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 18, 2012
  97. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 18, 2012
  98. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 18, 2012
  99. Junio C HamanoApr 18, 2012
  100. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 18, 2012
  101. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 18, 2012
  102. Zbigniew Jędrzejewski-SzmekApr 19, 2012
  103. Thomas RastApr 19, 2012
  104. Zbigniew Jędrzejewski-SzmekApr 19, 2012
  105. Neil HormanApr 19, 2012
  106. Junio C HamanoApr 19, 2012
  107. Junio C HamanoApr 19, 2012
  108. Neil HormanApr 20, 2012
  109. 0/4 Enhance git-rebases flexibiilty in handling empty commitsNeil Horman, Apr 20, 2012
  110. 1/4 git-cherry-pick: add allow-empty optionNeil Horman, Apr 20, 2012
  111. 2/4 git-cherry-pick: Add keep-redundant-commits optionNeil Horman, Apr 20, 2012
  112. Junio C HamanoApr 20, 2012
  113. Neil HormanApr 20, 2012
  114. 3/4 git-cherry-pick: Add test to validate new optionsNeil Horman, Apr 20, 2012
  115. 4/4 git-rebase: add keep_empty flagNeil Horman, Apr 20, 2012
  116. Junio C HamanoApr 25, 2012
  117. Neil HormanApr 25, 2012
  118. Martin von ZweigbergkJul 18, 2012
  119. Johannes SixtJul 18, 2012
  120. Martin von ZweigbergkJul 18, 2012
  121. Neil HormanJul 18, 2012

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.