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

Re: [PATCH 15/15] refs.c: add an err argument to pack_refs

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 30, 2014, 19:57 UTC
Message-ID
<xmqqr3xpuy8c.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1413923820-14457-16-git-send-email-sahlberg@google.com>
Ronnie Sahlberg <sahlberg@google.com> writes:
Show 62 quoted lines
> diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
> index b20b1ec..299768e 100644
> --- a/builtin/pack-refs.c
> +++ b/builtin/pack-refs.c
> @@ -10,6 +10,7 @@ static char const * const pack_refs_usage[] = {
>  int cmd_pack_refs(int argc, const char **argv, const char *prefix)
>  {
>  	unsigned int flags = PACK_REFS_PRUNE;
> +	struct strbuf err = STRBUF_INIT;
>  	struct option opts[] = {
>  		OPT_BIT(0, "all",   &flags, N_("pack everything"), PACK_REFS_ALL),
>  		OPT_BIT(0, "prune", &flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
> @@ -17,5 +18,10 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
>  	};
>  	if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
>  		usage_with_options(pack_refs_usage, opts);
> -	return pack_refs(flags);
> +	if (pack_refs(flags, &err)) {
> +		error("%s", err.buf);
> +		strbuf_release(&err);
> +		return -1;
> +	}
> +	return 0;
>  }
> diff --git a/refs.c b/refs.c
> index 7fb0d6c..a5e1eff 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -2588,16 +2588,15 @@ static void prune_refs(struct ref_to_prune *r)
>  	}
>  }
>  
> -int pack_refs(unsigned int flags)
> +int pack_refs(unsigned int flags, struct strbuf *err)
>  {
>  	struct pack_refs_cb_data cbdata;
> -	struct strbuf err = STRBUF_INIT;
>  
>  	memset(&cbdata, 0, sizeof(cbdata));
>  	cbdata.flags = flags;
>  
> -	if (lock_packed_refs(&err))
> -		die("%s", err.buf);
> +	if (lock_packed_refs(err))
> +		return -1;
>  
>  	cbdata.packed_refs = get_packed_refs(&ref_cache);
>  
> diff --git a/refs.h b/refs.h
> index f3e08f5..be16c08 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -130,8 +130,9 @@ extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct st
>  /*
>   * Write a packed-refs file for the current repository.
>   * flags: Combination of the above PACK_REFS_* flags.
> + * Returns 0 on success and fills in err on failure.
>   */
> -int pack_refs(unsigned int flags);
> +int pack_refs(unsigned int flags, struct strbuf *err);
>  
>  extern int ref_exists(const char *);

Makes sense. Thanks.

Previous: Ronnie Sahlberg
Message 27 of 27 in “ref-transaction-rename”
  1. 00/15 ref-transaction-renameRonnie Sahlberg, Oct 21, 2014
  2. 01/15 refs.c: allow passing raw git_committer_info as email to _update_reflogRonnie Sahlberg, Oct 21, 2014
  3. 02/15 refs.c: return error instead of dying when locking fails during transactionRonnie Sahlberg, Oct 21, 2014
  4. Jeff KingNov 11, 2014
  5. Ronnie SahlbergNov 11, 2014
  6. 03/15 refs.c: use packed refs when deleting refs during a transactionRonnie Sahlberg, Oct 21, 2014
  7. Junio C HamanoOct 22, 2014
  8. 04/15 refs.c: use a stringlist for repack_without_refsRonnie Sahlberg, Oct 21, 2014
  9. 05/15 refs.c: update rename_ref to use a transactionRonnie Sahlberg, Oct 21, 2014
  10. Junio C HamanoOct 28, 2014
  11. Junio C HamanoOct 28, 2014
  12. Ronnie SahlbergOct 28, 2014
  13. Junio C HamanoOct 28, 2014
  14. Ronnie SahlbergOct 29, 2014
  15. Junio C HamanoOct 29, 2014
  16. Ronnie SahlbergOct 30, 2014
  17. 06/15 refs.c: rollback the lockfile before we die() in repack_without_refsRonnie Sahlberg, Oct 21, 2014
  18. 07/15 refs.c: move reflog updates into its own functionRonnie Sahlberg, Oct 21, 2014
  19. 08/15 refs.c: write updates to packed refs when a transaction has more than one refRonnie Sahlberg, Oct 21, 2014
  20. 09/15 remote.c: use a transaction for deleting refsRonnie Sahlberg, Oct 21, 2014
  21. 10/15 refs.c: make repack_without_refs staticRonnie Sahlberg, Oct 21, 2014
  22. 11/15 refs.c: make the *_packed_refs functions staticRonnie Sahlberg, Oct 21, 2014
  23. 12/15 refs.c: replace the onerr argument in update_ref with a strbuf errRonnie Sahlberg, Oct 21, 2014
  24. 13/15 refs.c: make add_packed_ref return an error instead of calling dieRonnie Sahlberg, Oct 21, 2014
  25. 14/15 refs.c: make lock_packed_refs take an err argumentRonnie Sahlberg, Oct 21, 2014
  26. 15/15 refs.c: add an err argument to pack_refsRonnie Sahlberg, Oct 21, 2014
  27. Junio C HamanoOct 30, 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.