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

Re: [PATCH 3/5] refs.c: drop dead code checking lock status in `delete_pseudoref()`

From
David Turner <novalis@novalis.org>
Date
May 6, 2018, 15:54 UTC
Message-ID
<1525622054.16035.12.camel@novalis.org>
In-Reply-To
<20180506141031.30204-4-martin.agren@gmail.com>
Same concern here about staticness.
On Sun, 2018-05-06 at 16:10 +0200, Martin Ågren wrote:
Show 48 quoted lines
> After taking the lock we check whether we got it and die otherwise.
> But
> since we take the lock using `LOCK_DIE_ON_ERROR`, we would already
> have
> died.
> 
> Unlike in the previous patch, this function is not prepared for
> indicating errors via a `strbuf err`, so let's just drop the dead
> code.
> Any improved error-handling can be added later.
> 
> While at it, make the lock non-static and reduce its scope.
> 
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
>  refs.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/refs.c b/refs.c
> index 8c50b8b139..7abd30dfe1 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -689,20 +689,17 @@ static int write_pseudoref(const char
> *pseudoref, const struct object_id *oid,
>  
>  static int delete_pseudoref(const char *pseudoref, const struct
> object_id *old_oid)
>  {
> -	static struct lock_file lock;
>  	const char *filename;
>  
>  	filename = git_path("%s", pseudoref);
>  
>  	if (old_oid && !is_null_oid(old_oid)) {
> -		int fd;
> +		struct lock_file lock = LOCK_INIT;
>  		struct object_id actual_old_oid;
>  
> -		fd = hold_lock_file_for_update_timeout(
> +		hold_lock_file_for_update_timeout(
>  				&lock, filename, LOCK_DIE_ON_ERROR,
>  				get_files_ref_lock_timeout_ms());
> -		if (fd < 0)
> -			die_errno(_("Could not open '%s' for
> writing"), filename);
>  		if (read_ref(pseudoref, &actual_old_oid))
>  			die("could not read ref '%s'", pseudoref);
>  		if (oidcmp(&actual_old_oid, old_oid)) {
Previous: Martin ÅgrenNext: Jeff King
Message 2 of 4 in “refs.c: drop dead code checking lock status in `delete_pseudoref()`”
  1. 3/5 refs.c: drop dead code checking lock status in `delete_pseudoref()`Martin Ågren, May 6, 2018
  2. David TurnerMay 6, 2018
  3. Jeff KingMay 8, 2018
  4. Martin ÅgrenMay 9, 2018

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.