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

Re: [PATCH 4/6] repack_without_refs(): make the refnames argument a string_list

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 25, 2014, 07:42 UTC
Message-ID
<547432D5.8070802@alum.mit.edu>
In-Reply-To
<20141122211722.GD15320@google.com>
On 11/22/2014 10:17 PM, Jonathan Nieder wrote:
Show 5 quoted lines
> Michael Haggerty wrote:
> 
>> All of the callers have string_lists available already
> 
> Technically ref_transaction_commit doesn't, but that doesn't matter.
You're right. I'll correct this.
Show 46 quoted lines
>> Suggested-by: Ronnie Sahlberg <sahlberg@google.com>
>> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
>> ---
>>  builtin/remote.c | 14 ++------------
>>  refs.c           | 38 ++++++++++++++++++++------------------
>>  refs.h           | 11 ++++++++++-
>>  3 files changed, 32 insertions(+), 31 deletions(-)
> 
> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
> 
> One (optional) nit at the bottom of this message.
> 
> [...]
>> +++ b/refs.c
>> @@ -2639,22 +2639,25 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)
>>  	return 0;
>>  }
>>  
>> -int repack_without_refs(const char **refnames, int n, struct strbuf *err)
>> +int repack_without_refs(struct string_list *refnames, struct strbuf *err)
>>  {
>>  	struct ref_dir *packed;
>>  	struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
>> -	struct string_list_item *ref_to_delete;
>> -	int i, ret, removed = 0;
>> +	struct string_list_item *refname, *ref_to_delete;
>> +	int ret, needs_repacking = 0, removed = 0;
>>  
>>  	assert(err);
>>  
>>  	/* Look for a packed ref */
>> -	for (i = 0; i < n; i++)
>> -		if (get_packed_ref(refnames[i]))
>> +	for_each_string_list_item(refname, refnames) {
>> +		if (get_packed_ref(refname->string)) {
>> +			needs_repacking = 1;
>>  			break;
>> +		}
>> +	}
>>  
>>  	/* Avoid locking if we have nothing to do */
>> -	if (i == n)
>> +	if (!needs_repacking)
> 
> This makes me wish C supported something like Python's for/else
> construct.  Oh well. :)
Ahhh, Python, where arrays of strings *are* string_lists :-)
Show 20 quoted lines
> [...]
>> +++ b/refs.h
>> @@ -163,7 +163,16 @@ extern void rollback_packed_refs(void);
>>   */
>>  int pack_refs(unsigned int flags);
>>  
>> -extern int repack_without_refs(const char **refnames, int n,
>> +/*
>> + * Remove the refs listed in 'refnames' from the packed-refs file.
>> + * On error, packed-refs will be unchanged, the return value is
>> + * nonzero, and a message about the error is written to the 'err'
>> + * strbuf.
>> + *
>> + * The refs in 'refnames' needn't be sorted. The err buffer must not be
>> + * omitted.
> 
> (nit)
> 
> s/buffer/strbuf/, or s/The err buffer/'err'/
> s/omitted/NULL/

I will fix this too (and improve the docstring a bit in general). Thanks for your careful review!

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
Previous: Jonathan NiederNext: Michael Haggerty
Message 37 of 61 in “refs.c: use a stringlist for repack_without_refs”
  1. refs.c: use a stringlist for repack_without_refsStefan Beller, Nov 18, 2014
  2. Junio C HamanoNov 18, 2014
  3. Junio C HamanoNov 18, 2014
  4. Jonathan NiederNov 18, 2014
  5. Stefan BellerNov 19, 2014
  6. refs.c: use a stringlist for repack_without_refsStefan Beller, Nov 19, 2014
  7. Junio C HamanoNov 19, 2014
  8. refs.c: use a stringlist for repack_without_refsStefan Beller, Nov 19, 2014
  9. Jonathan NiederNov 19, 2014
  10. refs.c: use a stringlist for repack_without_refsStefan Beller, Nov 19, 2014
  11. refs.c: use a stringlist for repack_without_refsStefan Beller, Nov 19, 2014
  12. Jonathan NiederNov 20, 2014
  13. Junio C HamanoNov 20, 2014
  14. 1/1 refs.c: use a stringlist for repack_without_refsStefan Beller, Nov 20, 2014
  15. refs.c: repack_without_refs may be called without error string bufferStefan Beller, Nov 20, 2014
  16. Ronnie SahlbergNov 20, 2014
  17. Jonathan NiederNov 20, 2014
  18. Ronnie SahlbergNov 20, 2014
  19. Stefan BellerNov 20, 2014
  20. Jonathan NiederNov 20, 2014
  21. Jonathan NiederNov 20, 2014
  22. Junio C HamanoNov 20, 2014
  23. Stefan BellerNov 20, 2014
  24. refs.c: use a string_list for repack_without_refsStefan Beller, Nov 20, 2014
  25. Jonathan NiederNov 20, 2014
  26. 0/6 repack_without_refs(): convert to string_listMichael Haggerty, Nov 21, 2014
  27. 1/6 prune_remote(): exit early if there are no stale referencesMichael Haggerty, Nov 21, 2014
  28. Jonathan NiederNov 22, 2014
  29. 2/6 prune_remote(): initialize both delete_refs lists in a single loopMichael Haggerty, Nov 21, 2014
  30. 3/6 prune_remote(): sort delete_refs_list references en masseMichael Haggerty, Nov 21, 2014
  31. Junio C HamanoNov 21, 2014
  32. Michael HaggertyNov 25, 2014
  33. Michael HaggertyNov 25, 2014
  34. Jonathan NiederNov 22, 2014
  35. 4/6 repack_without_refs(): make the refnames argument a string_listMichael Haggerty, Nov 21, 2014
  36. Jonathan NiederNov 22, 2014
  37. Michael HaggertyNov 25, 2014
  38. 5/6 prune_remote(): rename local variableMichael Haggerty, Nov 21, 2014
  39. Jonathan NiederNov 22, 2014
  40. 6/6 prune_remote(): iterate using for_each_string_list_item()Michael Haggerty, Nov 21, 2014
  41. Jonathan NiederNov 22, 2014
  42. Michael HaggertyNov 21, 2014
  43. Junio C HamanoNov 21, 2014
  44. Stefan BellerNov 21, 2014
  45. Our cumbersome mailing list workflow (was: Re: [PATCH 0/6] repack_without_refs(): convert to string_list)Michael Haggerty, Nov 25, 2014
  46. Torsten BögershausenNov 27, 2014
  47. Matthieu MoyNov 27, 2014
  48. Philip OakleyNov 28, 2014
  49. Eric WongNov 27, 2014
  50. Michael HaggertyNov 28, 2014
  51. brian m. carlsonNov 28, 2014
  52. Junio C HamanoDec 1, 2014
  53. Stefan BellerDec 3, 2014
  54. Jonathan NiederDec 3, 2014
  55. Junio C HamanoDec 3, 2014
  56. Torsten BögershausenDec 3, 2014
  57. Michael HaggertyNov 28, 2014
  58. Marc BranchaudNov 28, 2014
  59. Damien RobertNov 28, 2014
  60. Philip OakleyDec 3, 2014
  61. Stefan BellerDec 4, 2014

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.