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

Re: [PATCH v4] gc: save log from daemonized gc --auto and print it next time

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Sep 16, 2015, 09:28 UTC
Message-ID
<55F93646.9050709@alum.mit.edu>
In-Reply-To
<xmqq1te0ykaj.fsf@gitster.mtv.corp.google.com>
On 09/14/2015 07:37 PM, Junio C Hamano wrote:
Show 46 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
>> Thanks, will queue.
> 
> Ehh, I spoke a bit too early.
> 
>>> diff --git a/builtin/gc.c b/builtin/gc.c
>>> index bcc75d9..2c3aaeb 100644
>>> --- a/builtin/gc.c
>>> +++ b/builtin/gc.c
>>> @@ -43,9 +43,20 @@ static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
>>>  static struct argv_array rerere = ARGV_ARRAY_INIT;
>>>  
>>>  static char *pidfile;
>>> +static struct strbuf log_filename = STRBUF_INIT;
>>> +static int daemonized;
>>>  
>>>  static void remove_pidfile(void)
>>>  {
>>> +	if (daemonized && log_filename.len) {
>>> +		struct stat st;
>>> +
>>> +		close(2);
>>> +		if (stat(log_filename.buf, &st) ||
>>> +		    !st.st_size ||
>>> +		    rename(log_filename.buf, git_path("gc.log")))
>>> +			unlink(log_filename.buf);
>>> +	}
> 
> Unfortuantely we cannot queue this as-is, as we let the tempfile API
> to automatically manage the pidfile since ebebeaea (gc: use tempfile
> module to handle gc.pid file, 2015-08-10), and you cannot piggy-back
> the log file finalization to this function that no longer exists.
> 
> Besides, it is obviously wrong to remove this log file in a function
> whose name is remove_pidfile() ;-)
> 
> Adding a new function to tempfile API that puts the file to a final
> place if it is non-empty and otherwise remove it, and using that to
> create this "gc.log" file, would be the cleanest from the point of
> view of _this_ codepath.  I however do not know if that is too
> specific for the need of this codepath or "leave it if non-empty,
> but otherwise remove as it is uninteresting" is fairly common thing
> we would want and it is a good addition to the API set.
> 
> Michael, what do you think?

I'm not sure what behavior you want. At one point you say "puts the file to a final place if it is non-empty" but later you say "leave it if non-empty". Should the file be written directly, or should it be written to a lockfile and renamed into place only when complete?

Technically I don't see a problem implementing either behavior. POSIX allows [1] calls to stat() and rename() from a signal handler. There is a minor technical difficulty that commit_lock_file() allocates memory via get_locked_file_path(), but this would be surmountable by pre-allocating the memory for the locked file path and storing it in the lock_file object.

This doesn't seem like a common thing to want (as in, this might be the only caller), but it probably makes sense to build it into the tempfile/lockfile API nevertheless, because implementing it externally would require a lot of other code to be duplicated.

Another possibility that might work (maybe without requiring changes to tempfile/lockfile): don't worry about deleting the log file if it is empty, but make observers treat an empty log file the same as an absent one.

Michael

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03

-- 
Michael Haggerty
mhagger@alum.mit.edu
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 17 in “Since gc.autodetach=1 you can end up with auto-gc on every command with no user notification”
  1. Ævar Arnfjörð BjarmasonJul 8, 2015
  2. Duy NguyenJul 8, 2015
  3. gc: save log from daemonized gc --auto and print it next timeNguyễn Thái Ngọc Duy, Aug 22, 2015
  4. Junio C HamanoAug 25, 2015
  5. Duy NguyenAug 31, 2015
  6. gc: save log from daemonized gc --auto and print it next timeNguyễn Thái Ngọc Duy, Sep 13, 2015
  7. Junio C HamanoSep 14, 2015
  8. Junio C HamanoSep 14, 2015
  9. Michael HaggertySep 16, 2015
  10. Junio C HamanoSep 16, 2015
  11. Michael HaggertySep 17, 2015
  12. Duy NguyenSep 17, 2015
  13. Junio C HamanoSep 17, 2015
  14. gc: save log from daemonized gc --auto and print it next timeNguyễn Thái Ngọc Duy, Sep 19, 2015
  15. Junio C HamanoSep 21, 2015
  16. gc: save log from daemonized gc --auto and print it next timeNguyễn Thái Ngọc Duy, Sep 19, 2015
  17. Junio C HamanoSep 21, 2015

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.