{"thread":{"id":"7546","subject":"[PATCH] Make builtin-branch.c handle the git config file","startedAt":"2007-04-06T12:13:00Z","lastAt":"2007-04-06T12:13:00Z","messageCount":1,"participants":["Lars Hjemli"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"38788","messageId":"11758615802537-git-send-email-hjemli@gmail.com","threadId":"7546","inReplyTo":null,"subject":"[PATCH] Make builtin-branch.c handle the git config file","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2007-04-06T12:13:00Z","receivedAt":"2007-04-06T12:13:00Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"This moves the knowledge about .git/config usage out of refs.c and into\nbuiltin-branch.c instead, which allows git-branch to update HEAD to point\nat the moved branch before attempting to update the config file. It also\nallows git-branch to exit with an error code if updating the config file\nshould fail.\n\nSigned-off-by: Lars Hjemli <hjemli@gmail.com>\n---\n builtin-branch.c |    6 ++++++\n refs.c           |   10 ----------\n 2 files changed, 6 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex a4494ee..7408285 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -493,6 +493,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)\n {\n \tchar oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];\n \tunsigned char sha1[20];\n+\tchar oldsection[PATH_MAX], newsection[PATH_MAX];\n \n \tif (!oldname)\n \t\tdie(\"cannot rename the current branch while not on any.\");\n@@ -521,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force)\n \t/* no need to pass logmsg here as HEAD didn't really move */\n \tif (!strcmp(oldname, head) && create_symref(\"HEAD\", newref, NULL))\n \t\tdie(\"Branch renamed to %s, but HEAD is not updated!\", newname);\n+\n+\tsnprintf(oldsection, sizeof(oldsection), \"branch.%s\", oldref + 11);\n+\tsnprintf(newsection, sizeof(newsection), \"branch.%s\", newref + 11);\n+\tif (git_config_rename_section(oldsection, newsection) < 0)\n+\t\tdie(\"Branch is renamed, but update of config-file failed\");\n }\n \n int cmd_branch(int argc, const char **argv, const char *prefix)\ndiff --git a/refs.c b/refs.c\nindex 2ac6384..d2b7b7f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -828,16 +828,6 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)\n \t\tgoto rollback;\n \t}\n \n-\tif (!prefixcmp(oldref, \"refs/heads/\") &&\n-\t\t\t!prefixcmp(newref, \"refs/heads/\")) {\n-\t\tchar oldsection[1024], newsection[1024];\n-\n-\t\tsnprintf(oldsection, 1024, \"branch.%s\", oldref + 11);\n-\t\tsnprintf(newsection, 1024, \"branch.%s\", newref + 11);\n-\t\tif (git_config_rename_section(oldsection, newsection) < 0)\n-\t\t\terror(\"unable to update config-file\");\n-\t}\n-\n \treturn 0;\n \n  rollback:\n-- \n1.5.1.53.g77e6f\n"}]}