# # # patch "cmd_ws_commit.cc" # from [78f5120093456fd5a4fac92c7c26f39328ca3d83] # to [90bed7e987225e0705db556a3c383bc459b4f440] # ============================================================ --- cmd_ws_commit.cc 78f5120093456fd5a4fac92c7c26f39328ca3d83 +++ cmd_ws_commit.cc 90bed7e987225e0705db556a3c383bc459b4f440 @@ -699,8 +699,9 @@ CMD(commit, N_("workspace"), N_("[PATH]. CMD(commit, N_("workspace"), N_("[PATH]..."), N_("commit workspace to database"), - options::opts::branch | options::opts::message | options::opts::msgfile | options::opts::date - | options::opts::author | options::opts::depth | options::opts::exclude) + options::opts::branch | options::opts::message | options::opts::msgfile + | options::opts::date | options::opts::author | options::opts::depth + | options::opts::exclude) { utf8 log_message(""); bool log_message_given; @@ -728,35 +729,38 @@ CMD(commit, N_("workspace"), N_("[PATH]. old_rosters, new_roster, app); app.work.update_current_roster_from_filesystem(new_roster, mask); - make_restricted_revision(old_rosters, new_roster, mask, restricted_rev, excluded); + make_restricted_revision(old_rosters, new_roster, mask, restricted_rev, + excluded); restricted_rev.check_sane(); N(restricted_rev.is_nontrivial(), F("no changes to commit")); revision_id restricted_rev_id; calculate_ident(restricted_rev, restricted_rev_id); - E(app.db.revision_exists(restricted_rev_id), - F("revision %s is already in the database\n" - "(update and try again?)") % restricted_rev_id); - utf8 branchname, bn_candidate; - - for (edge_map::iterator i = restricted_rev.edges.begin(); - i != restricted_rev.edges.end(); - i++) + // We need the 'if' because guess_branch will try to override any branch + // picked up from _MTN/options. + if (app.opts.branch_name().empty()) { - // this will prefer --branch if it was set - guess_branch(edge_old_revision(i), app, bn_candidate); - N(branchname() == "" || branchname == bn_candidate, - F("parent revisions of this commit are in different branches:\n" - "'%s' and '%s'.\n" - "please specify a branch name for the commit, with --branch.") - % branchname % bn_candidate); - branchname = bn_candidate; + utf8 branchname, bn_candidate; + for (edge_map::iterator i = restricted_rev.edges.begin(); + i != restricted_rev.edges.end(); + i++) + { + // this will prefer --branch if it was set + guess_branch(edge_old_revision(i), app, bn_candidate); + N(branchname() == "" || branchname == bn_candidate, + F("parent revisions of this commit are in different branches:\n" + "'%s' and '%s'.\n" + "please specify a branch name for the commit, with --branch.") + % branchname % bn_candidate); + branchname = bn_candidate; + } + + app.opts.branch_name = branchname; } - // make sure everyone's on the same page - app.opts.branch_name = branchname; - P(F("beginning commit on branch '%s'") % branchname); + + P(F("beginning commit on branch '%s'") % app.opts.branch_name); L(FL("new manifest '%s'\n" "new revision '%s'\n") % restricted_rev.new_manifest @@ -806,41 +810,76 @@ CMD(commit, N_("workspace"), N_("[PATH]. // for the divergence check, below set heads; - app.get_project().get_branch_heads(branchname, heads); + app.get_project().get_branch_heads(app.opts.branch_name, heads); unsigned int old_head_size = heads.size(); - L(FL("inserting new revision %s") % restricted_rev_id); { transaction_guard guard(app.db); packet_db_writer dbw(app); - for (edge_map::const_iterator edge = restricted_rev.edges.begin(); - edge != restricted_rev.edges.end(); - edge++) + if (app.db.revision_exists(restricted_rev_id)) + W(F("revision %s already in database") % restricted_rev_id); + else { - // process file deltas or new files - cset const & cs = edge_changes(edge); - - for (map >::const_iterator - i = cs.deltas_applied.begin(); - i != cs.deltas_applied.end(); ++i) + L(FL("inserting new revision %s") % restricted_rev_id); + + for (edge_map::const_iterator edge = restricted_rev.edges.begin(); + edge != restricted_rev.edges.end(); + edge++) { - file_path path(i->first); - file_id old_content = i->second.first; - file_id new_content = i->second.second; + // process file deltas or new files + cset const & cs = edge_changes(edge); - if (app.db.file_version_exists(new_content)) + for (map >::const_iterator + i = cs.deltas_applied.begin(); + i != cs.deltas_applied.end(); ++i) { - L(FL("skipping file delta %s, already in database") - % delta_entry_dst(i)); + file_path path(i->first); + file_id old_content = i->second.first; + file_id new_content = i->second.second; + + if (app.db.file_version_exists(new_content)) + { + L(FL("skipping file delta %s, already in database") + % delta_entry_dst(i)); + } + else if (app.db.file_version_exists(old_content)) + { + L(FL("inserting delta %s -> %s") + % old_content % new_content); + file_data old_data; + data new_data; + app.db.get_file_version(old_content, old_data); + read_localized_data(path, new_data, app.lua); + // sanity check + hexenc tid; + calculate_ident(new_data, tid); + N(tid == new_content.inner(), + F("file '%s' modified during commit, aborting") + % path); + delta del; + diff(old_data.inner(), new_data, del); + dbw.consume_file_delta(old_content, + new_content, + file_delta(del)); + } + else + // If we don't err out here, our packet writer will + // later. + E(false, + F("Your database is missing version %s of file '%s'") + % old_content % path); } - else if (app.db.file_version_exists(old_content)) + + for (map::const_iterator + i = cs.files_added.begin(); + i != cs.files_added.end(); ++i) { - L(FL("inserting delta %s -> %s") - % old_content % new_content); - file_data old_data; + file_path path(i->first); + file_id new_content = i->second; + + L(FL("inserting full version %s") % new_content); data new_data; - app.db.get_file_version(old_content, old_data); read_localized_data(path, new_data, app.lua); // sanity check hexenc tid; @@ -848,46 +887,17 @@ CMD(commit, N_("workspace"), N_("[PATH]. N(tid == new_content.inner(), F("file '%s' modified during commit, aborting") % path); - delta del; - diff(old_data.inner(), new_data, del); - dbw.consume_file_delta(old_content, - new_content, - file_delta(del)); + dbw.consume_file_data(new_content, file_data(new_data)); } - else - // If we don't err out here, our packet writer will - // later. - E(false, - F("Your database is missing version %s of file '%s'") - % old_content % path); } - for (map::const_iterator - i = cs.files_added.begin(); - i != cs.files_added.end(); ++i) - { - file_path path(i->first); - file_id new_content = i->second; - - L(FL("inserting full version %s") % new_content); - data new_data; - read_localized_data(path, new_data, app.lua); - // sanity check - hexenc tid; - calculate_ident(new_data, tid); - N(tid == new_content.inner(), - F("file '%s' modified during commit, aborting") - % path); - dbw.consume_file_data(new_content, file_data(new_data)); - } + revision_data rdat; + write_revision(restricted_rev, rdat); + dbw.consume_revision_data(restricted_rev_id, rdat); } - revision_data rdat; - write_revision(restricted_rev, rdat); - dbw.consume_revision_data(restricted_rev_id, rdat); - app.get_project().put_standard_certs_from_options(restricted_rev_id, - branchname, + app.opts.branch_name, log_message, dbw); guard.commit(); @@ -904,7 +914,7 @@ CMD(commit, N_("workspace"), N_("[PATH]. app.work.blank_user_log(); - app.get_project().get_branch_heads(branchname, heads); + app.get_project().get_branch_heads(app.opts.branch_name, heads); if (heads.size() > old_head_size && old_head_size > 0) { P(F("note: this revision creates divergence\n" "note: you may (or may not) wish to run '%s merge'")