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

Re: [PATCH 2/5] refs: split log_ref_write logic into log_ref_setup

From
Junio C Hamano <gitster@pobox.com>
Date
May 26, 2010, 05:07 UTC
Message-ID
<7v632bs13c.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1274488119-6989-3-git-send-email-erick.mattos@gmail.com>
Erick Mattos <erick.mattos@gmail.com> writes:
Show 20 quoted lines
> -static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
> -			 const unsigned char *new_sha1, const char *msg)
> +int log_ref_setup(const char *ref_name, char **log_file)
>  {
> -	int logfd, written, oflags = O_APPEND | O_WRONLY;
> -	unsigned maxlen, len;
> -	int msglen;
> -	char log_file[PATH_MAX];
> -	char *logrec;
> -	const char *committer;
> -
> -	if (log_all_ref_updates < 0)
> -		log_all_ref_updates = !is_bare_repository();
> -
> -	git_snpath(log_file, sizeof(log_file), "logs/%s", ref_name);
> +	int logfd, oflags = O_APPEND | O_WRONLY;
> +	char logfile[PATH_MAX];
> +	git_snpath(logfile, sizeof(logfile), "logs/%s", ref_name);
> +	*log_file = logfile;
> ...

I have a slight suspicion that it would have made the patch smaller and easier to read if you kept the name of the on-stack log_file[] as-is, and named the retval parameter logfile_p or soemthing. Also you would need to make this buffer "static char log_file[]", no? Otherwise you would be returning a pointer to a dead buffer to the caller.

Show 9 quoted lines
> +static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
> +			 const unsigned char *new_sha1, const char *msg)
> +{
> + ...
> +	result = log_ref_setup(ref_name, &log_file);
> +	if (result)
> +		return result;
> +
> +	logfd = open(log_file, oflags);

Yuck, the caller needs to call "setup" which discards the file descriptor opened for writing and then open it again itself?

Previous: Erick MattosNext: Erick Mattos
Message 4 of 18 in “checkout --orphan improvements”
  1. 0/5 checkout --orphan improvementsErick Mattos, May 22, 2010
  2. 1/5 Documentation: alter checkout --orphan descriptionErick Mattos, May 22, 2010
  3. 2/5 refs: split log_ref_write logic into log_ref_setupErick Mattos, May 22, 2010
  4. Junio C HamanoMay 26, 2010
  5. Erick MattosMay 26, 2010
  6. Junio C HamanoJun 2, 2010
  7. Erick MattosJun 2, 2010
  8. 3/5 checkout --orphan: respect -l option alwaysErick Mattos, May 22, 2010
  9. Junio C HamanoMay 26, 2010
  10. Erick MattosMay 26, 2010
  11. Erik Faye-LundMay 26, 2010
  12. Erick MattosMay 26, 2010
  13. Erick MattosJun 3, 2010
  14. Michael J GruberMay 26, 2010
  15. Erick MattosMay 26, 2010
  16. Michael J GruberMay 27, 2010
  17. 4/5 t3200: test -l with core.logAllRefUpdates optionsErick Mattos, May 22, 2010
  18. 5/5 bash completion: add --orphan to 'git checkout'Erick Mattos, May 22, 2010

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.