# # # add_file "rev_output.cc" # content [d8d29a05cb917058ef7b7188a8544ff5cd45cf26] # # add_file "rev_output.hh" # content [930cdf038dc5094b7e9f51b159502bea4c97a39c] # # patch "Makefile.am" # from [b64f1bb21ea623267925f28d086205263a36e3f1] # to [b8971ebe590b8e00f88ce24dfe320127a4e11f40] # # patch "cmd_ws_commit.cc" # from [14c7772a4d71ba158755bbecfab8d0425b67d8b3] # to [d877a94843bcbee880eb45d0aab4ebd3f6cdb794] # ============================================================ --- rev_output.cc d8d29a05cb917058ef7b7188a8544ff5cd45cf26 +++ rev_output.cc d8d29a05cb917058ef7b7188a8544ff5cd45cf26 @@ -0,0 +1,137 @@ +// Copyright (C) 2010 Derek Scherger +// +// This program is made available under the GNU GPL version 2.0 or +// greater. See the accompanying file COPYING for details. +// +// This program is distributed WITHOUT ANY WARRANTY; without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. + +#include "base.hh" +#include +#include +#include + +#include "cset.hh" +#include "dates.hh" +#include "rev_output.hh" +#include "revision.hh" + +using std::map; +using std::pair; +using std::set; +using std::string; +using std::ostringstream; + +void +revision_header(revision_id rid, revision_t const & rev, string const & author, + date_t const date, branch_name const & branch, + bool const branch_changed, utf8 & header) +{ + ostringstream out; + int const width = 70; + + // FIXME bad suffix + out << string(width, '-') << '\n' + << _("Revision: ") << rid << _(" (uncommitted)") << '\n'; + + for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i) + { + revision_id parent = edge_old_revision(*i); + out << _("Parent: ") << parent << '\n'; + } + + out << _("Author: ") << author << '\n' + << _("Date: ") << date << '\n'; + + if (branch_changed) + { + // FIXME bad suffix + 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); +} + +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. + + ostringstream out; + revision_id rid; + calculate_ident(rev, rid); + + for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i) + { + revision_id parent = edge_old_revision(*i); + cset const & cs = edge_changes(*i); + + out << '\n'; + + // A colon at the end of this string looked nicer, but it made + // double-click copying from terminals annoying. + if (!null_id(parent)) + out << _("Changes against parent ") << parent << "\n\n"; + + // presumably a merge rev could have an empty edge if one side won + if (cs.empty()) + out << _("no changes") << '\n'; + + for (set::const_iterator i = cs.nodes_deleted.begin(); + i != cs.nodes_deleted.end(); ++i) + out << _(" dropped ") << *i << '\n'; + + for (map::const_iterator + i = cs.nodes_renamed.begin(); + i != cs.nodes_renamed.end(); ++i) + out << _(" renamed ") << i->first + << _(" to ") << i->second << '\n'; + + for (set::const_iterator i = cs.dirs_added.begin(); + i != cs.dirs_added.end(); ++i) + out << _(" added ") << *i << '\n'; + + for (map::const_iterator i = cs.files_added.begin(); + i != cs.files_added.end(); ++i) + out << _(" added ") << i->first << '\n'; + + for (map >::const_iterator + i = cs.deltas_applied.begin(); i != cs.deltas_applied.end(); ++i) + out << _(" patched ") << i->first << '\n'; + + for (map, attr_value >::const_iterator + i = cs.attrs_set.begin(); i != cs.attrs_set.end(); ++i) + out << _(" attr on ") << i->first.first << '\n' + << _(" set ") << i->first.second << '\n' + << _(" to ") << i->second << '\n'; + + // FIXME: naming here could not be more inconsistent + // the cset calls it attrs_cleared + // the command is attr drop + // here it is called unset + // the revision text uses attr clear + + for (set >::const_iterator + i = cs.attrs_cleared.begin(); i != cs.attrs_cleared.end(); ++i) + out << _(" attr on ") << i->first << '\n' + << _(" unset ") << i->second << '\n'; + } + summary = utf8(out.str(), origin::internal); +} + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: ============================================================ --- rev_output.hh 930cdf038dc5094b7e9f51b159502bea4c97a39c +++ rev_output.hh 930cdf038dc5094b7e9f51b159502bea4c97a39c @@ -0,0 +1,34 @@ +// Copyright (C) 2010 Derek Scherger +// +// This program is made available under the GNU GPL version 2.0 or +// greater. See the accompanying file COPYING for details. +// +// This program is distributed WITHOUT ANY WARRANTY; without even the +// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. + +#ifndef __REV_SUMMARY_HH__ +#define __REV_SUMMARY_HH__ + +#include "rev_types.hh" +#include "vocab.hh" + +struct date_t; + +void +revision_header(revision_id rid, revision_t const & rev, std::string const & author, + date_t const date, branch_name const & branch, + bool const branch_changed, utf8 & header); + +void +revision_summary(revision_t const & rev, utf8 & summary); + +#endif // header guard + +// Local Variables: +// mode: C++ +// fill-column: 76 +// c-file-style: "gnu" +// indent-tabs-mode: nil +// End: +// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: ============================================================ --- Makefile.am b64f1bb21ea623267925f28d086205263a36e3f1 +++ Makefile.am b8971ebe590b8e00f88ce24dfe320127a4e11f40 @@ -101,6 +101,7 @@ MOST_SOURCES = \ sha1.cc \ pcrewrap.cc pcrewrap.hh \ rev_height.cc rev_height.hh \ + rev_output.cc rev_output.hh \ asciik.cc asciik.hh \ dates.cc dates.hh \ \ ============================================================ --- cmd_ws_commit.cc 14c7772a4d71ba158755bbecfab8d0425b67d8b3 +++ cmd_ws_commit.cc d877a94843bcbee880eb45d0aab4ebd3f6cdb794 @@ -31,6 +31,7 @@ #include "simplestring_xform.hh" #include "database.hh" #include "roster.hh" +#include "rev_output.hh" #include "vocab_cast.hh" using std::cout; @@ -46,111 +47,6 @@ static void using boost::shared_ptr; static void -revision_header(revision_id rid, revision_t const & rev, string const & author, - date_t const date, branch_name const & branch, - bool const branch_changed, utf8 & header) -{ - ostringstream out; - int const width = 70; - - // FIXME bad suffix - out << string(width, '-') << '\n' - << _("Revision: ") << rid << _(" (uncommitted)") << '\n'; - - for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i) - { - revision_id parent = edge_old_revision(*i); - out << _("Parent: ") << parent << '\n'; - } - - out << _("Author: ") << author << '\n' - << _("Date: ") << date << '\n'; - - if (branch_changed) - { - // FIXME bad suffix - 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. - - ostringstream out; - revision_id rid; - calculate_ident(rev, rid); - - for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i) - { - revision_id parent = edge_old_revision(*i); - cset const & cs = edge_changes(*i); - - out << '\n'; - - // A colon at the end of this string looked nicer, but it made - // double-click copying from terminals annoying. - if (!null_id(parent)) - out << _("Changes against parent ") << parent << "\n\n"; - - // presumably a merge rev could have an empty edge if one side won - if (cs.empty()) - out << _("no changes") << '\n'; - - for (set::const_iterator i = cs.nodes_deleted.begin(); - i != cs.nodes_deleted.end(); ++i) - out << _(" dropped ") << *i << '\n'; - - for (map::const_iterator - i = cs.nodes_renamed.begin(); - i != cs.nodes_renamed.end(); ++i) - out << _(" renamed ") << i->first - << _(" to ") << i->second << '\n'; - - for (set::const_iterator i = cs.dirs_added.begin(); - i != cs.dirs_added.end(); ++i) - out << _(" added ") << *i << '\n'; - - for (map::const_iterator i = cs.files_added.begin(); - i != cs.files_added.end(); ++i) - out << _(" added ") << i->first << '\n'; - - for (map >::const_iterator - i = cs.deltas_applied.begin(); i != cs.deltas_applied.end(); ++i) - out << _(" patched ") << i->first << '\n'; - - for (map, attr_value >::const_iterator - i = cs.attrs_set.begin(); i != cs.attrs_set.end(); ++i) - out << _(" attr on ") << i->first.first << '\n' - << _(" set ") << i->first.second << '\n' - << _(" to ") << i->second << '\n'; - - // FIXME: naming here could not be more inconsistent - // the cset calls it attrs_cleared - // the command is attr drop - // here it is called unset - // the revision text uses attr clear - - for (set >::const_iterator - i = cs.attrs_cleared.begin(); i != cs.attrs_cleared.end(); ++i) - out << _(" attr on ") << i->first << '\n' - << _(" unset ") << i->second << '\n'; - } - summary = utf8(out.str(), origin::internal); -} - -static void get_old_branch_names(database & db, parent_map const & parents, set & old_branch_names) {