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

Re: [PATCH 13/22] config: change write_error() to take a (struct lock_file *) argument

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 2, 2014, 17:29 UTC
Message-ID
<xmqqob0jvdve.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1396367910-7299-14-git-send-email-mhagger@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 19 quoted lines
> Reduce the amount of code that has to know about the lock_file's
> filename field.
>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
>  config.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/config.c b/config.c
> index 6821cef..1ea3f39 100644
> --- a/config.c
> +++ b/config.c
> @@ -1303,9 +1303,9 @@ static int store_aux(const char *key, const char *value, void *cb)
>  	return 0;
>  }
>  
> -static int write_error(const char *filename)
> +static int write_error(struct lock_file *lk)
>  {

The earlier one would have been usable for reporting an error while writing any file, but the caller must hold a lock file on it with a new one. Would this change warrant a renaming of the function, I wonder.

It is a file-scope static, so all callers know about how they are supposed to call it, hence the keeping the original name would be OK, I would think.

This hunk triggered my smello-meter, primarily because "write-error" would not be the name I would pick for this function if I were writing everything in this file from scratch (before or after this particular patch).

Show 32 quoted lines
> -	error("failed to write new configuration file %s", filename);
> +	error("failed to write new configuration file %s", lk->filename);
>  
>  	/* Same error code as "failed to rename". */
>  	return 4;
> @@ -1706,7 +1706,7 @@ out_free:
>  	return ret;
>  
>  write_err_out:
> -	ret = write_error(lock->filename);
> +	ret = write_error(lock);
>  	goto out_free;
>  
>  }
> @@ -1821,7 +1821,7 @@ int git_config_rename_section_in_file(const char *config_filename,
>  				}
>  				store.baselen = strlen(new_name);
>  				if (!store_write_section(out_fd, new_name)) {
> -					ret = write_error(lock->filename);
> +					ret = write_error(lock);
>  					goto out;
>  				}
>  				/*
> @@ -1847,7 +1847,7 @@ int git_config_rename_section_in_file(const char *config_filename,
>  			continue;
>  		length = strlen(output);
>  		if (write_in_full(out_fd, output, length) != length) {
> -			ret = write_error(lock->filename);
> +			ret = write_error(lock);
>  			goto out;
>  		}
>  	}
Previous: Michael HaggertyNext: Michael Haggerty
Message 42 of 62 in “Lockfile refactoring and pre-activation”
  1. 00/22 Lockfile refactoring and pre-activationMichael Haggerty, Apr 1, 2014
  2. 01/22 t3204: test deleting references when lock files already existMichael Haggerty, Apr 1, 2014
  3. Jeff KingApr 1, 2014
  4. Michael HaggertyApr 2, 2014
  5. 02/22 try_merge_strategy(): remove redundant lock_file allocationMichael Haggerty, Apr 1, 2014
  6. Jeff KingApr 1, 2014
  7. Michael HaggertyApr 2, 2014
  8. Junio C HamanoApr 2, 2014
  9. Michael HaggertyApr 3, 2014
  10. 03/22 rollback_lock_file(): do not clear filename redundantlyMichael Haggerty, Apr 1, 2014
  11. 04/22 rollback_lock_file(): set fd to -1Michael Haggerty, Apr 1, 2014
  12. Jeff KingApr 1, 2014
  13. Junio C HamanoApr 2, 2014
  14. Michael HaggertyApr 6, 2014
  15. Junio C HamanoApr 7, 2014
  16. 05/22 lockfile: unlock file if lockfile permissions cannot be adjustedMichael Haggerty, Apr 1, 2014
  17. Jeff KingApr 1, 2014
  18. Jeff KingApr 1, 2014
  19. Torsten BögershausenApr 2, 2014
  20. Michael HaggertyApr 6, 2014
  21. 06/22 hold_lock_file_for_append(): release lock on errorsMichael Haggerty, Apr 1, 2014
  22. 07/22 lock_file(): always add lock_file object to lock_file_listMichael Haggerty, Apr 1, 2014
  23. Jeff KingApr 1, 2014
  24. Junio C HamanoApr 2, 2014
  25. Michael HaggertyApr 6, 2014
  26. Jeff KingApr 7, 2014
  27. 08/22 struct lock_file: replace on_list field with flags fieldMichael Haggerty, Apr 1, 2014
  28. 09/22 api-lockfile: expand the documentationMichael Haggerty, Apr 1, 2014
  29. Jeff KingApr 1, 2014
  30. Michael HaggertyApr 2, 2014
  31. 10/22 lockfile.c: document the various states of lock_file objectsMichael Haggerty, Apr 1, 2014
  32. 11/22 lockfile: define a constant LOCK_SUFFIX_LENMichael Haggerty, Apr 1, 2014
  33. Junio C HamanoApr 2, 2014
  34. 12/22 delete_ref_loose(): don't muck around in the lock_file's filenameMichael Haggerty, Apr 1, 2014
  35. Jeff KingApr 1, 2014
  36. Michael HaggertyApr 2, 2014
  37. Torsten BögershausenApr 2, 2014
  38. Jeff KingApr 2, 2014
  39. 13/22 config: change write_error() to take a (struct lock_file *) argumentMichael Haggerty, Apr 1, 2014
  40. Torsten BögershausenApr 2, 2014
  41. Michael HaggertyApr 6, 2014
  42. Junio C HamanoApr 2, 2014
  43. 14/22 lockfile: use strbufs when handling (most) pathsMichael Haggerty, Apr 1, 2014
  44. Jeff KingApr 1, 2014
  45. Junio C HamanoApr 2, 2014
  46. 15/22 resolve_symlink(): use a strbuf internallyMichael Haggerty, Apr 1, 2014
  47. 16/22 commit_lock_file(): don't work with a fixed-length bufferMichael Haggerty, Apr 1, 2014
  48. 17/22 lock_file(): exit early if lockfile cannot be openedMichael Haggerty, Apr 1, 2014
  49. 18/22 lockfile: also keep track of the filename of the file being lockedMichael Haggerty, Apr 1, 2014
  50. Junio C HamanoApr 2, 2014
  51. Michael HaggertyApr 6, 2014
  52. 19/22 struct lock_file: rename lock_filename field to staging_filenameMichael Haggerty, Apr 1, 2014
  53. 20/22 remove_lock_file(): call rollback_lock_file()Michael Haggerty, Apr 1, 2014
  54. 21/22 lockfile: extract a function reset_lock_file()Michael Haggerty, Apr 1, 2014
  55. Eric SunshineApr 2, 2014
  56. Michael HaggertyApr 2, 2014
  57. 22/22 lockfile: allow new file contents to be written while retaining lockMichael Haggerty, Apr 1, 2014
  58. Jeff KingApr 1, 2014
  59. Eric SunshineApr 2, 2014
  60. Junio C HamanoApr 2, 2014
  61. Jeff KingApr 1, 2014
  62. Michael HaggertyApr 3, 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.