# # # patch "cmd_ws_commit.cc" # from [e21003d69f6d650aa59a3d88ea6a361c18bc73b5] # to [3c4e9acf69a20e12ea857d4e29ae8ac36078f92c] # # patch "tests/commit_default_editor/test_hooks.lua" # from [7c76aaca31bc9e1b61921cc32c687883ff051779] # to [04b87e8e247d7927dd09e3cb09cb031261dc390d] # ============================================================ --- cmd_ws_commit.cc e21003d69f6d650aa59a3d88ea6a361c18bc73b5 +++ cmd_ws_commit.cc 3c4e9acf69a20e12ea857d4e29ae8ac36078f92c @@ -47,10 +47,13 @@ revision_header(revision_id rid, revisio static void revision_header(revision_id rid, revision_t const & rev, string const & author, - date_t const date, branch_name const & branch, utf8 & header) + date_t const date, branch_name const & branch, + bool const branch_changed, utf8 & header) { ostringstream out; - out << string(70, '-') << "\n" + int const width = 70; + + out << string(width, '-') << "\n" << "Revision: " << rid << " (uncommitted)\n"; for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i) @@ -58,28 +61,28 @@ revision_header(revision_id rid, revisio revision_id parent = edge_old_revision(*i); out << "Parent: " << parent << "\n"; } + out << "Author: " << author << "\n" - << "Date: " << date << "\n" - << "Branch: " << branch << "\n" - << "Changelog:\n\n"; + << "Date: " << date << "\n"; + if (branch_changed) + { + int space = width - branch().length() - 8 - 10; + if (space < 0) space = 0; + out << "Branch: " << branch << string(space, ' ') << " (changed)\n"; + } + else + out << "Branch: " << branch << "\n"; + + out << "Changelog:\n\n"; + header = utf8(out.str(), origin::internal); } static void revision_summary(revision_t const & rev, utf8 & summary) { - // We intentionally do not collapse the final \n into the format - // strings here, for consistency with newline conventions used by most - // other format strings. - string out; - // FIXME: use an ostringstream here too? -revision_summary(revision_t const & rev, branch_name const & branch, - set const & old_branch_names, - utf8 & summary) -{ - string out; // We intentionally do not collapse the final \n into the format // strings here, for consistency with newline conventions used by most // other format strings. @@ -87,20 +90,8 @@ revision_summary(revision_t const & rev, revision_id rid; calculate_ident(rev, rid); - out += (F("Current revision: %s") % rid).str() += '\n'; - if (old_branch_names.find(branch) == old_branch_names.end()) - { - for (set::const_iterator i = old_branch_names.begin(); - i != old_branch_names.end(); ++i) - { - out += (F("Old branch: %s") % *i).str() += '\n'; - } - out += (F("New branch: %s") % branch).str() += '\n'; - } - else - out += (F("Current branch: %s") % branch).str() += '\n'; + // FIXME: use an ostringstream here too? - for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i) { revision_id parent = edge_old_revision(*i); @@ -183,7 +174,7 @@ get_log_message_interactively(lua_hooks get_log_message_interactively(lua_hooks & lua, workspace & work, revision_id const rid, revision_t const & rev, string & author, date_t & date, branch_name & branch, - set const & old_branch_names, + bool const branch_changed, utf8 & log_message) { external instructions( @@ -196,7 +187,7 @@ get_log_message_interactively(lua_hooks utf8 message; utf8 summary; - revision_header(rid, rev, author, date, branch, header); + revision_header(rid, rev, author, date, branch, branch_changed, header); work.read_user_log(message); revision_summary(rev, summary); @@ -290,7 +281,10 @@ get_log_message_interactively(lua_hooks F("Modifications outside of Author, Date, Branch or Changelog.\n" "Commit failed (missing branch).")); - branch = branch_name(trim(line->substr(8)), origin::user); + if (branch_changed && line->rfind("(changed)") == line->length() - 9) + branch = branch_name(trim(line->substr(8, line->length() - 17)), origin::user); + else + branch = branch_name(trim(line->substr(8)), origin::user); ++line; E(*line == "Changelog:", @@ -731,6 +725,7 @@ CMD(status, "status", "", CMD_REF(inform temp_node_id_source nis; database db(app); + project_t project(db); workspace work(app); work.get_parent_rosters(db, old_rosters); work.get_current_roster_shape(db, nis, new_roster); @@ -759,28 +754,32 @@ CMD(status, "status", "", CMD_REF(inform } } - set old_branch_names; - get_old_branch_names(db, old_rosters, old_branch_names); - revision_id rid; string author; key_store keys(app); - rsa_keypair_id key; + key_identity_info key; - calculate_ident(rev, rid); + get_user_key(app.opts, app.lua, db, keys, project, key.id); + project.complete_key_identity(app.lua, key); - get_user_key(app.opts, app.lua, db, keys, key); if (!app.lua.hook_get_author(app.opts.branch, key, author)) - author = key(); + author = key.official_name(); utf8 header; utf8 message; utf8 summary; - revision_summary(rev, app.opts.branch, old_branch_names, summary); - revision_header(rid, rev, author, date_t::now(), app.opts.branch, header); + calculate_ident(rev, rid); + + set old_branches; + get_old_branch_names(db, old_rosters, old_branches); + bool branch_changed = + old_branches.find(app.opts.branch) == old_branches.end(); + + revision_header(rid, rev, author, date_t::now(), + app.opts.branch, branch_changed, header); + work.read_user_log(message); - revision_summary(rev, summary); string text = message(); if (text.empty() || text.substr(text.length()-1) != "\n") @@ -789,6 +788,8 @@ CMD(status, "status", "", CMD_REF(inform message = utf8(text, origin::user); } + revision_summary(rev, summary); + external header_external; external message_external; external summary_external; @@ -1341,21 +1342,26 @@ CMD(commit, "commit", "ci", CMD_REF(work if (author.empty()) { - rsa_keypair_id key; - get_user_key(app.opts, app.lua, db, keys, key); + key_identity_info key; + get_user_key(app.opts, app.lua, db, keys, project, key.id); + project.complete_key_identity(app.lua, key); + if (!app.lua.hook_get_author(app.opts.branch, key, author)) - author = key(); + author = key.official_name(); } if (!log_message_given) { - set old_branch_names; - get_old_branch_names(db, old_rosters, old_branch_names); + set old_branches; + get_old_branch_names(db, old_rosters, old_branches); + bool branch_changed = + old_branches.find(app.opts.branch) == old_branches.end(); // This call handles _MTN/log. get_log_message_interactively(app.lua, work, restricted_rev_id, restricted_rev, author, date, app.opts.branch, + branch_changed, log_message); // We only check for empty log messages when the user entered them ============================================================ --- tests/commit_default_editor/test_hooks.lua 7c76aaca31bc9e1b61921cc32c687883ff051779 +++ tests/commit_default_editor/test_hooks.lua 04b87e8e247d7927dd09e3cb09cb031261dc390d @@ -5,9 +5,17 @@ function execute(path,...) return 1 end if path == "editor" then + + tmp = io.open(tname, "r") + text = tmp:read("*a") + io.close(tmp) + + text = string.gsub(text, "\nChangelog:\n\n\n", "\nChangelog:\n\nHello\n") + tmp = io.open(tname, "w") - tmp:write("Hello\n") + tmp:write(text) io.close(tmp) + return 0 end return 1