# [PATCH] branch.c: delete size check of newly tracked branch names

5 messages from 2014-02-28 to 2014-02-28. Participants: Jacopo Notarstefano, Duy Nguyen.
Thread: https://gitlist.dev/t/35992

## Jacopo Notarstefano, 2014-02-28 11:09

Subject: [PATCH] branch.c: delete size check of newly tracked branch names
Message-ID: <1393585744-2569-1-git-send-email-jacopo.notarstefano@gmail.com>
URL: https://gitlist.dev/e/1393585744-2569-1-git-send-email-jacopo.notarstefano%40gmail.com

```
Since commit 6f084a56 the length of a newly tracked branch name was limited
to 1019 = 1024 - 7 - 7 - 1 characters, a bound derived by having to store
this name in a char[1024] called key with two strings of length at most 7
and a '\0' character.

This was no longer necessary as of commit a9f2c136, which uses a strbuf
(documented in Documentation/technical/api-strbuf.txt) to store this value.

This patch removes this unneeded check and thus allows for branch names
longer than 1019 characters.

Signed-off-by: Jacopo Notarstefano <jacopo.notarstefano@gmail.com>
---

Submitted as GSoC microproject #3.

 branch.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/branch.c b/branch.c
index 723a36b..05feaff 100644
--- a/branch.c
+++ b/branch.c
@@ -114,10 +114,6 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
 	struct tracking tracking;
 	int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
 
-	if (strlen(new_ref) > 1024 - 7 - 7 - 1)
-		return error(_("Tracking not set up: name too long: %s"),
-				new_ref);
-
 	memset(&tracking, 0, sizeof(tracking));
 	tracking.spec.dst = (char *)orig_ref;
 	if (for_each_remote(find_tracked_branch, &tracking))
-- 
1.9.0.1.g5abca64

```

## Jacopo Notarstefano, 2014-02-28 11:16

Subject: Re: [PATCH] branch.c: delete size check of newly tracked branch names
Message-ID: <CAL0uuq3fZby7SG4Q5B8R1h8wHOGOHBamT+9ZR8mbNms40if6nw@mail.gmail.com>
URL: https://gitlist.dev/e/CAL0uuq3fZby7SG4Q5B8R1h8wHOGOHBamT%2B9ZR8mbNms40if6nw%40mail.gmail.com
In-Reply-To: <1393585744-2569-1-git-send-email-jacopo.notarstefano@gmail.com>

```
> This patch removes this unneeded check and thus allows for branch names
> longer than 1019 characters.
>

Ach! I amended the commit in my local history to read "Remove this
unneded check and thus allow for branch names longer than 1019
characters", but for some reason git format-patch -1 --signoff isn't
reflecting this change.

```

## Duy Nguyen, 2014-02-28 11:41

Subject: Re: [PATCH] branch.c: delete size check of newly tracked branch names
Message-ID: <CACsJy8A7jVM1wdU2BK-NyQ5HJoY_19oKhSXCKqV_7qNN+OA+mw@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8A7jVM1wdU2BK-NyQ5HJoY_19oKhSXCKqV_7qNN%2BOA%2Bmw%40mail.gmail.com
In-Reply-To: <1393585744-2569-1-git-send-email-jacopo.notarstefano@gmail.com>

```
On Fri, Feb 28, 2014 at 6:09 PM, Jacopo Notarstefano
<jacopo.notarstefano@gmail.com> wrote:
> Since commit 6f084a56 the length of a newly tracked branch name was limited
> to 1019 = 1024 - 7 - 7 - 1 characters, a bound derived by having to store
> this name in a char[1024] called key with two strings of length at most 7
> and a '\0' character.
>
> This was no longer necessary as of commit a9f2c136, which uses a strbuf
> (documented in Documentation/technical/api-strbuf.txt) to store this value.
>
> This patch removes this unneeded check and thus allows for branch names
> longer than 1019 characters.

Nice. new_ref is passed in install_branch_config() in latest code. I
guess you already made sure this function did not make any assumption
about new_ref's length?

>
> Signed-off-by: Jacopo Notarstefano <jacopo.notarstefano@gmail.com>
> ---
>
> Submitted as GSoC microproject #3.
>
>  branch.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/branch.c b/branch.c
> index 723a36b..05feaff 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -114,10 +114,6 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
>         struct tracking tracking;
>         int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
>
> -       if (strlen(new_ref) > 1024 - 7 - 7 - 1)
> -               return error(_("Tracking not set up: name too long: %s"),
> -                               new_ref);
> -
>         memset(&tracking, 0, sizeof(tracking));
>         tracking.spec.dst = (char *)orig_ref;
>         if (for_each_remote(find_tracked_branch, &tracking))
> --
> 1.9.0.1.g5abca64
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Duy

```

## Jacopo Notarstefano, 2014-02-28 12:14

Subject: Re: [PATCH] branch.c: delete size check of newly tracked branch names
Message-ID: <CAL0uuq263WEFWvZFDeqdN4=fAJGPUtux2wwFGOUQEMfzmDOweQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAL0uuq263WEFWvZFDeqdN4%3DfAJGPUtux2wwFGOUQEMfzmDOweQ%40mail.gmail.com
In-Reply-To: <CACsJy8A7jVM1wdU2BK-NyQ5HJoY_19oKhSXCKqV_7qNN+OA+mw@mail.gmail.com>

```
> Nice. new_ref is passed in install_branch_config() in latest code. I
> guess you already made sure this function did not make any assumption
> about new_ref's length?
>

The function install_branch_config uses the strbuf, as I wrote in the
commit message. The contents of this buffer are then fed to
git_config_set, which, after a few more function calls, parses the key
with git_config_parse_key. This function does not rely on any
assumptions (as far as I can tell!) on the name's length, and
allocates enough space for it in
https://github.com/git/git/blob/master/config.c#L1462.

```

## Duy Nguyen, 2014-02-28 12:43

Subject: Re: [PATCH] branch.c: delete size check of newly tracked branch names
Message-ID: <CACsJy8BaGL9EQW87MSC98sKTfN6V9tPbqWXPAtM+nvoxV_NShg@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8BaGL9EQW87MSC98sKTfN6V9tPbqWXPAtM%2BnvoxV_NShg%40mail.gmail.com
In-Reply-To: <CAL0uuq263WEFWvZFDeqdN4=fAJGPUtux2wwFGOUQEMfzmDOweQ@mail.gmail.com>

```
On Fri, Feb 28, 2014 at 7:14 PM, Jacopo Notarstefano
<jacopo.notarstefano@gmail.com> wrote:
>> Nice. new_ref is passed in install_branch_config() in latest code. I
>> guess you already made sure this function did not make any assumption
>> about new_ref's length?
>>
>
> The function install_branch_config uses the strbuf, as I wrote in the
> commit message. The contents of this buffer are then fed to
> git_config_set, which, after a few more function calls, parses the key
> with git_config_parse_key. This function does not rely on any
> assumptions (as far as I can tell!) on the name's length, and
> allocates enough space for it in
> https://github.com/git/git/blob/master/config.c#L1462.

Thanks for checking!
-- 
Duy

```
