From: Junio C Hamano <gitster@pobox.com>
To: Aviv Eyal <avivey@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Support specific color for a specific remote branches
Date: Mon, 08 Aug 2011 11:08:26 -0700 [thread overview]
Message-ID: <7v8vr3zsh1.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1312818553-25042-1-git-send-email-avivey@gmail.com> (Aviv Eyal's message of "Mon, 8 Aug 2011 18:49:13 +0300")
Aviv Eyal <avivey@gmail.com> writes:
> +remote.<name>.color:
> + If set, the `branch` command will use the colors specified here
> + for the names of all branches tracking this remote. Colors
> + specified here take precedent over `color.branch.remote` config.
> +static char *strclone(const char *start, int len)
> +{
Hmm, don't we have xmemdupz() for this?
> + char *result = malloc((len + 1) * sizeof(char));
> + if (!result)
> + return NULL;
> + strncpy(result, start, len);
> + result[len] = '\0';
> + return result;
> +}
> +
> +static int git_branch_config_custom_color_remote(const char *var, const char *value)
> +{
> + struct string_list_item *item;
> + char *name, *color;
> + name = strclone(var + 7, strlen(var) - 13); // "remote."=7, "remote..color"=13.
No // comments please.
> + if (!name)
> + return 0;
> + color = malloc(COLOR_MAXLEN * sizeof(char));
At least use xmalloc(); also isn't sizeof(char) by definition 1?
> + if (!color) {
> + free(name);
> + return 0;
> + }
> + item = string_list_insert(&custom_colors, name);
> + color_parse(value, var, color);
> + item->util = color;
It may be just a style thing, but I'd rather see this caller call
color_parse() first, and after letting that function validate the end-user
input, call string_list_insert().
Also what happens when there are two entries that talk about the same
remote branch in the configuration? Such a configuration is not an error;
your ~/.gitconfig may say one thing for remote.origin.master and your
repository specific .git/config may override it for a particular
repository.
> + return 0;
> +}
> +
> +static char *git_branch_get_custom_color_remote(const char *name)
> +{
> + int name_len;
> + char* repo_name;
> + struct string_list_item *custom;
> + name_len = strchr(name, '/') - name;
Who said a remote name is terminated with (and cannot contain) a slash?
Shouldn't this code be consulting the configuration file to learn the
remote mapping, e.g.
[remote "frotz"]
fetch = +refs/heads/*:refs/remotes/nitfol/*
so that remote branches from "frotz" remote, that happen to be stored
under refs/remotes/nitfol/ hierarchy, are painted in the correct color?
next prev parent reply other threads:[~2011-08-08 18:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-08 15:49 [PATCH] Support specific color for a specific remote branches Aviv Eyal
2011-08-08 18:08 ` Junio C Hamano [this message]
2011-08-08 20:52 ` Jeff King
2011-08-08 21:31 ` Junio C Hamano
2011-08-10 12:16 ` Jeff King
2011-08-09 18:59 ` Aviv Eyal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v8vr3zsh1.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=avivey@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).