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

Re: [RFC/ PATCH 2/5] unpack_trees: group errors by type

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 9, 2010, 16:50 UTC
Message-ID
<7v39wwp2ur.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1276087446-25112-4-git-send-email-diane.gasselin@ensimag.imag.fr>
Diane Gasselin <diane.gasselin@ensimag.imag.fr> writes:
Show 14 quoted lines
> +/*
> + * Store error messages in an array, each case
> + * corresponding to a error message type
> + */
> +typedef enum {
> +	would_overwrite,
> +	not_uptodate_file,
> +	not_uptodate_dir,
> +	would_lose_untracked,
> +	would_lose_untracked_removed,
> +	sparse_not_uptodate_file
> +} unpack_trees_error;
> +#define NB_UNPACK_TREES_ERROR 6
> +struct rejected_files *unpack_rejects[NB_UNPACK_TREES_ERROR];

You folks seem to like global variables a lot... Isn't there a struct passed throughout the callchain in unpack_trees that you can attach this information to?

Also "rejected_files" is not as technically correct (there are symlinks) as "rejected_paths".

Style: we don't encourage "typedef enum { ... } unpack_trees_error";
instead we tend to just say "enum unpack_trees_error" both in the
definition and in the use.
> +	if (!porcelain) {
> +		error(msg,file,action);
> +		return -1;
> +	}
Style:
	if (!porcelain)
        	return error(msg, file, action);
> +static void free_rejected_files(unpack_trees_error e)
> +{
> +	while(unpack_rejects[e]->list) {
Style:
	while (unpack_rejects[e]->list) {
> +static void display_error_msgs()
> +{
> +	int i;
> +	int hasPorcelain = 0;
Style: we don't encourage camelCase.
Whichever way spelled, "has porcelain?" is puzzling.

Is this about "are we issuing error messages as a Porcelain program, or are we a plumbing without noisy error messages?" Or is this about "have we said anything in the loop, and if so finish the message with 'Aborting'"? If the former, I would name it after "we are Porcelain"; if the latter, I would name it after "we said something".

> +	for (i=0; i<NB_UNPACK_TREES_ERROR; i++) {
Style:
	for (i = 0; i < NB_UNPACK_TREES_ERROR; i++) {
Show 14 quoted lines
> +		if (unpack_rejects[i] && unpack_rejects[i]->list) {
> +			hasPorcelain = 1;
> +			struct rejected_files_list *f = unpack_rejects[i]->list;
> +			char *action = unpack_rejects[i]->action;
> +			char *file = malloc(unpack_rejects[i]->size+1);
> +			*file = '\0';
> +			while (f) {
> +				strcat(file,"\t");
> +				strcat(file,f->file);
> +				strcat(file,"\n");
> +				f = f->next;
> +			}
> +			error(unpack_rejects[i]->msg,file,action);
> +			free_rejected_files(i);

It feels wrong to malloc() inside the loop (and without freeing, which is worse). At least the code should use strbuf to do something like:

	struct strbuf indented = STRBUF_INIT;
	for (f = unpack_rejects[i]->list; f; f = f->next)
                strbuf_addf(&indented, "\t%s\n", f->file);
	error(..., indented.buf, action);
        strbuf_release(&indented);
Previous: Diane GasselinNext: Diane Gasselin
Message 16 of 21 in “unpack_trees: nicer error messages”
  1. 0/5 unpack_trees: nicer error messagesDiane Gasselin, Jun 9, 2010
  2. 0/5 unpack_trees: nicer error messagesDiane Gasselin, Jun 9, 2010
  3. 1/5 tree-walk: do not stop when an error is detectedDiane Gasselin, Jun 9, 2010
  4. 2/5 unpack_trees: group errors by typeDiane Gasselin, Jun 9, 2010
  5. 3/5 unpack_trees_options: update porcelain messagesDiane Gasselin, Jun 9, 2010
  6. 4/5 t3030: update porcelain expected messageDiane Gasselin, Jun 9, 2010
  7. 5/5 t7609: test merge and checkout error messagesDiane Gasselin, Jun 9, 2010
  8. Matthieu MoyJun 9, 2010
  9. Diane GasselinJun 9, 2010
  10. Matthieu MoyJun 9, 2010
  11. Junio C HamanoJun 9, 2010
  12. Matthieu MoyJun 9, 2010
  13. Jeff KingJun 10, 2010
  14. Diane GasselinJun 10, 2010
  15. Diane GasselinJun 9, 2010
  16. Junio C HamanoJun 9, 2010
  17. Diane GasselinJun 10, 2010
  18. Matthieu MoyJun 9, 2010
  19. Junio C HamanoJun 9, 2010
  20. Diane GasselinJun 9, 2010
  21. Matthieu MoyJun 9, 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.