{"thread":{"id":"6541","subject":"[PATCH] git-merge: make it usable as the first class UI again.","startedAt":"2007-01-26T09:28:22Z","lastAt":"2007-01-26T10:24:29Z","messageCount":2,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32703","messageId":"7v4pqe16ix.fsf@assigned-by-dhcp.cox.net","threadId":"6541","inReplyTo":null,"subject":"[PATCH] git-merge: make it usable as the first class UI again.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-26T09:28:22Z","receivedAt":"2007-01-26T09:28:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"reflog wants to have a short-and-sweet single line message, but\nits set_reflog_action was slurping the whole command line arguments.\nWhen given a multi-line commit message from the command line, reflog\ncode refused to update the ref with the resulting commit.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n * When pull threw huge merge message, it has already set the\n   reflog action on its own so this breakage was hidden.  Also\n   because most of the time people did not specify -m message\n   (or use the old-style <msg> HEAD <others>) from the command\n   line, nobody seems to have noticed this.\n\n git-merge.sh |    2 +-\n git-pull.sh  |   27 +++++++++++++++++++++++++++\n 2 files changed, 28 insertions(+), 1 deletions(-)\n\ndiff --git a/git-merge.sh b/git-merge.sh\nindex 7b59026..91909b7 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -7,7 +7,7 @@ USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commi\n \n SUBDIRECTORY_OK=Yes\n . git-sh-setup\n-set_reflog_action \"merge $*\"\n+set_reflog_action merge\n require_work_tree\n cd_to_toplevel\n \ndiff --git a/git-pull.sh b/git-pull.sh\nindex a3665d7..fc76aea 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -51,6 +51,33 @@ do\n \tshift\n done\n \n+if test \"X$1\" = X.\n+then\n+\t# We are merging from this repository.  We can avoid fetch\n+\t# and go right into merge if the user isn't doing something\n+\t# odd like asking us to also update tracking branches in\n+\t# this repository as part of the pull.  Yeah, they probably\n+\t# shouldn't do that - but we allowed it in the past...\n+\t#\n+\tdirect_merge=1\n+\tfor remote\n+\tdo\n+\t\tcase \"$remote\" in\n+\t\t*:*) direct_merge=0; break;;\n+\t\tesac\n+\tdone\n+\tif test $direct_merge = 1\n+\tthen\n+\t\tshift\n+\t\texec git-merge \\\n+\t\t\t$no_summary $no_commit $squash $strategy_args \\\n+\t\t\t\"$@\"\n+\telse\n+\t\techo >&2 \"Clever... Updating tracking branch while pulling from yourself.\"\n+\t\techo >&2\n+\tfi\n+fi\n+\n orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)\n git-fetch --update-head-ok \"$@\" || exit 1\n \n-- \n1.5.0.rc2.g8a816\n"},{"id":"32714","messageId":"7vd552ytk2.fsf@assigned-by-dhcp.cox.net","threadId":"6541","inReplyTo":"7v4pqe16ix.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-merge: make it usable as the first class UI again.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-26T10:24:29Z","receivedAt":"2007-01-26T10:24:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> reflog wants to have a short-and-sweet single line message, but\n> its set_reflog_action was slurping the whole command line arguments.\n> When given a multi-line commit message from the command line, reflog\n> code refused to update the ref with the resulting commit.\n>\n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\nActually, let's rescind that one -- it was very silly of me.\nWe should do this instead.\n\n-- >8 --\n[PATCH] Make sure we do not write bogus reflog entries.\n\nThe file format dictates that entries are LF terminated so\nthe message cannot have one in it.  Chomp the message to make\nsure it only has a single line if necessary, while removing the\nleading whitespace.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n builtin-update-ref.c |    2 --\n refs.c               |   39 +++++++++++++++++++++++----------------\n 2 files changed, 23 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin-update-ref.c b/builtin-update-ref.c\nindex b34e598..f2506fa 100644\n--- a/builtin-update-ref.c\n+++ b/builtin-update-ref.c\n@@ -23,8 +23,6 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)\n \t\t\tmsg = argv[++i];\n \t\t\tif (!*msg)\n \t\t\t\tdie(\"Refusing to perform update with empty message.\");\n-\t\t\tif (strchr(msg, '\\n'))\n-\t\t\t\tdie(\"Refusing to perform update with \\\\n in message.\");\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(\"-d\", argv[i])) {\ndiff --git a/refs.c b/refs.c\nindex 4323e9a..0840b3b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -925,6 +925,7 @@ static int log_ref_write(struct ref_lock *lock,\n {\n \tint logfd, written, oflags = O_APPEND | O_WRONLY;\n \tunsigned maxlen, len;\n+\tint msglen;\n \tchar *logrec;\n \tconst char *committer;\n \n@@ -958,24 +959,30 @@ static int log_ref_write(struct ref_lock *lock,\n \t\t\t\t     lock->log_file, strerror(errno));\n \t}\n \n-\tcommitter = git_committer_info(-1);\n+\tmsglen = 0;\n \tif (msg) {\n-\t\tmaxlen = strlen(committer) + strlen(msg) + 2*40 + 5;\n-\t\tlogrec = xmalloc(maxlen);\n-\t\tlen = snprintf(logrec, maxlen, \"%s %s %s\\t%s\\n\",\n-\t\t\tsha1_to_hex(lock->old_sha1),\n-\t\t\tsha1_to_hex(sha1),\n-\t\t\tcommitter,\n-\t\t\tmsg);\n-\t}\n-\telse {\n-\t\tmaxlen = strlen(committer) + 2*40 + 4;\n-\t\tlogrec = xmalloc(maxlen);\n-\t\tlen = snprintf(logrec, maxlen, \"%s %s %s\\n\",\n-\t\t\tsha1_to_hex(lock->old_sha1),\n-\t\t\tsha1_to_hex(sha1),\n-\t\t\tcommitter);\n+\t\t/* clean up the message and make sure it is a single line */\n+\t\tfor ( ; *msg; msg++)\n+\t\t\tif (!isspace(*msg))\n+\t\t\t\tbreak;\n+\t\tif (*msg) {\n+\t\t\tconst char *ep = strchr(msg, '\\n');\n+\t\t\tif (ep)\n+\t\t\t\tmsglen = ep - msg;\n+\t\t\telse\n+\t\t\t\tmsglen = strlen(msg);\n+\t\t}\n \t}\n+\n+\tcommitter = git_committer_info(-1);\n+\tmaxlen = strlen(committer) + msglen + 100;\n+\tlogrec = xmalloc(maxlen);\n+\tlen = sprintf(logrec, \"%s %s %s\\n\",\n+\t\t      sha1_to_hex(lock->old_sha1),\n+\t\t      sha1_to_hex(sha1),\n+\t\t      committer);\n+\tif (msglen)\n+\t\tlen += sprintf(logrec + len - 1, \"\\t%.*s\\n\", msglen, msg) - 1;\n \twritten = len <= maxlen ? write_in_full(logfd, logrec, len) : -1;\n \tfree(logrec);\n \tclose(logfd);\n"}]}