{"thread":{"id":"13811","subject":"[PATCH] Fix remote_get so it will return NULL when no remote is found.","startedAt":"2008-06-05T12:48:11Z","lastAt":"2008-06-05T13:26:30Z","messageCount":2,"participants":["Victor Bogado da Silva Lins","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"78759","messageId":"1212670091.30293.3.camel@omicron.ep.petrobras.com.br","threadId":"13811","inReplyTo":null,"subject":"[PATCH] Fix remote_get so it will return NULL when no remote is found.","fromName":"Victor Bogado da Silva Lins","fromEmail":"victor@bogado.net","sentAt":"2008-06-05T12:48:11Z","receivedAt":"2008-06-05T12:48:11Z","isPatch":true,"sender":{"key":"victor@bogado.net","avatar":"https://gravatar.com/avatar/4ad1d046d4c1a5673a65aac199e2113f4e2d2ffe88d095cb3e17c1f20126cfac?d=mp&s=160"},"body":">From 0cf45f264cf7f1b3aa3a8875109fbf4c03d56126 Mon Sep 17 00:00:00 2001\nFrom: Victor Bogado <victor@bogado.net>\nDate: Thu, 5 Jun 2008 09:36:41 -0300\nSubject: [PATCH] Fix remote_get so it will return NULL when no remote is\nfound.\n\nremote_get should return NULL when there is no remote with that name, at\nleast this is what remote.c's rm() function seems to think. As this is a\nreasonable assumption, and it seems that the function remote_get is\nacutally trying to do this, I fixed the test so it will test if the URL\nis equal to the name of the remote.\n---\n remote.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 91e3b11..62b3611 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -598,7 +598,7 @@ struct remote *remote_get(const char *name)\n \t}\n \tif (!ret->url)\n \t\tadd_url_alias(ret, name);\n-\tif (!ret->url)\n+\tif (!strcmp(*ret->url,ret->name))\n \t\treturn NULL;\n \tret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr,\nret->fetch_refspec);\n \tret->push = parse_push_refspec(ret->push_refspec_nr,\nret->push_refspec);\n-- \n1.5.5\n"},{"id":"78768","messageId":"alpine.DEB.1.00.0806051415000.21190@racer","threadId":"13811","inReplyTo":"1212670091.30293.3.camel@omicron.ep.petrobras.com.br","subject":"Re: [PATCH] Fix remote_get so it will return NULL when no remote is found.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-06-05T13:26:30Z","receivedAt":"2008-06-05T13:26:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\n[nice to go to sleep and see a patch in the morning]\n\nOn Thu, 5 Jun 2008, Victor Bogado da Silva Lins wrote:\n\n> >>From 0cf45f264cf7f1b3aa3a8875109fbf4c03d56126 Mon Sep 17 00:00:00 2001\n> From: Victor Bogado <victor@bogado.net>\n> Date: Thu, 5 Jun 2008 09:36:41 -0300\n> Subject: [PATCH] Fix remote_get so it will return NULL when no remote is\n> found.\n\nPlease imitate what you see on this list, especially by the Git regulars.  \nThey never include these headers.\n\n> remote_get should return NULL when there is no remote with that name, at \n> least this is what remote.c's rm() function seems to think. As this is a \n> reasonable assumption, and it seems that the function remote_get is \n> acutally trying to do this, I fixed the test so it will test if the URL \n> is equal to the name of the remote.\n\nThis is a bit vague, a bit wrong, and it has the subjective \"I\" in it.  \nremote_get() _is_ assumed to return NULL when no remote with that name was \nfound.\n\nAnd the function was fixed (3rd person, passive).  At least that is how I \nremember most of the rest of git.git's commit messages.\n\n> diff --git a/remote.c b/remote.c\n> index 91e3b11..62b3611 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -598,7 +598,7 @@ struct remote *remote_get(const char *name)\n>  \t}\n>  \tif (!ret->url)\n>  \t\tadd_url_alias(ret, name);\n> -\tif (!ret->url)\n> +\tif (!strcmp(*ret->url,ret->name))\n>  \t\treturn NULL;\n\nHmm.  That sounds very dangerous, using a pointer without checking that it \nis NULL.\n\nBesides, I think that the add_url_alias(ret, name) above is at \nfault.  Not the alias part about it, though.  This used to be an add_url() \nfrom the conception of remote.c, but then it was only used for fetching.\n\nI think the proper solution is to add a parameter, or a function, to force \nNULL if the remote did not exist.\n\nOf course, this involves a careful review of the existing callers, to find \nout which ones rely on getting a newly created remote when none was found.\n\nIn any case, thank you very much for finding that bug (the if() I pointed \nout was in remote.c from the very beginning, even then never being \ntriggered).\n\nCiao,\nDscho\n"}]}