monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone.issue-120: 5738f6ad3484cf1e


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone.issue-120: 5738f6ad3484cf1ea2621890c217a8cfcdea3a9f
Date: Mon, 24 Jan 2011 22:36:39 GMT

revision:            5738f6ad3484cf1ea2621890c217a8cfcdea3a9f
date:                2011-01-24T21:56:45
author:              Richard Hopkins
branch:              net.venge.monotone.issue-120
changelog:
Function framework based on CMD(status

NOTE: This version is NOT a working replacement.

This is almost an exact copy of the CMD(status code but with
unnecessary things removed such as finding the author name, which
should then make the timings effectively the same.

The output code has been modified to only output the filename
for each type of change, however it does not respect the sorting
expected by "mtn ls changed".

I tried to use a std::set<string> as the output, so each change
will be inserted to it then we can sort and iterate through it
later to output it to screen - but I couldn't get it to work
due to my lack of knowledge of C++ and it's standard library.

There is also a TODO placed over the parameters as this function
could really be extracted into a helper, which would also provide
us with additional "mtn ls" functions such as "mtn ls added",
"mtn ls patched" etc.

manifest:
format_version "1"

new_manifest [3e705ccb528182a0361a819088d5565fc969dcde]

old_revision [e0d65e6639c5596e1f01ca5d4c74420eeb3d8e32]

patch "cmd_list.cc"
 from [d5f1d76cb76151d303cda19a974fe5c86f806d70]
   to [407919e0d297548d5f0e59ef1cb7dcdb4ce4335a]
============================================================
--- cmd_list.cc	d5f1d76cb76151d303cda19a974fe5c86f806d70
+++ cmd_list.cc	407919e0d297548d5f0e59ef1cb7dcdb4ce4335a
@@ -12,6 +12,8 @@
 #include "safe_map.hh"
 #include <utility>
 #include <iostream>
+#include <sstream>
+#include <set>
 #include <iterator>
 
 #include <boost/tuple/tuple.hpp>
@@ -45,6 +47,7 @@ using std::ostream;
 using std::sort;
 using std::copy;
 using std::ostream;
+using std::ostringstream;
 using std::string;
 using std::vector;
 
@@ -853,51 +856,102 @@ CMD(changed, "changed", "", CMD_REF(list
     "",
     options::opts::depth | options::opts::exclude)
 {
+  roster_t new_roster;
+  parent_map old_rosters;
+  revision_t rev;
+  temp_node_id_source nis;
+
   database db(app);
+  project_t project(db);
   workspace work(app);
 
-  parent_map parents;
-  roster_t new_roster;
-  temp_node_id_source nis;
+  work.get_parent_rosters(db, old_rosters);
   work.get_current_roster_shape(db, nis, new_roster);
-  work.update_current_roster_from_filesystem(new_roster);
 
-  work.get_parent_rosters(db, parents);
-
   node_restriction mask(args_to_paths(args),
                         args_to_paths(app.opts.exclude),
                         app.opts.depth,
-                        parents, new_roster, ignored_file(work));
+                        old_rosters, new_roster, ignored_file(work));
 
-  revision_t rrev;
-  make_restricted_revision(parents, new_roster, mask, rrev);
+  work.update_current_roster_from_filesystem(new_roster, mask);
+  make_restricted_revision(old_rosters, new_roster, mask, rev);
 
-  // to be printed sorted, with duplicates removed
-  set<file_path> print_paths;
+  revision_id rid;
+  calculate_ident(rev, rid);
 
-  for (edge_map::const_iterator i = rrev.edges.begin();
-       i != rrev.edges.end(); i++)
+  ostringstream out; // TODO: We probably don't want to use this as we
+  // need to sort and filter duplicates before outputting.
+
+  // TODO: Refactor this method and promote these locals to parameters
+  // We can then use the method to provide us with "mtn ls added" for
+  // example
+  bool output_dropped = true;
+  bool output_renamed = true;
+  bool output_added = true;
+  bool output_patched = true;
+  bool output_attrs = true;
+
+  for (edge_map::const_iterator i = rev.edges.begin(); i != rev.edges.end(); ++i)
     {
-      set<node_id> nodes;
-      roster_t const & old_roster
-        = *safe_get(parents, edge_old_revision(i)).first;
-      select_nodes_modified_by_cset(edge_changes(i),
-                                    old_roster, new_roster, nodes);
+      revision_id parent = edge_old_revision(*i);
+      cset const & cs = edge_changes(*i);
 
-      for (set<node_id>::const_iterator i = nodes.begin(); i != nodes.end();
-           ++i)
+      if (output_dropped)
         {
-          file_path p;
-          if (new_roster.has_node(*i))
-            new_roster.get_name(*i, p);
-          else
-            old_roster.get_name(*i, p);
-          print_paths.insert(p);
+          for (set<file_path>::const_iterator i = cs.nodes_deleted.begin();
+            i != cs.nodes_deleted.end(); ++i)
+            out << *i << "\n";
         }
+
+      if (output_renamed)
+        {
+          for (map<file_path, file_path>::const_iterator
+            i = cs.nodes_renamed.begin();
+            i != cs.nodes_renamed.end(); ++i)
+            out << i->second << "\n";
+        }
+
+      if (output_added)
+        {
+          for (set<file_path>::const_iterator i = cs.dirs_added.begin();
+            i != cs.dirs_added.end(); ++i)
+            out << *i << "\n";
+
+          for (map<file_path, file_id>::const_iterator i = cs.files_added.begin();
+            i != cs.files_added.end(); ++i)
+            out << i->first << "\n";
+        }
+
+      if (output_patched)
+        {
+          for (map<file_path, pair<file_id, file_id> >::const_iterator
+            i = cs.deltas_applied.begin(); i != cs.deltas_applied.end(); ++i)
+            out << i->first << "\n";
+        }
+
+      if (output_attrs)
+        {
+          for (map<pair<file_path, attr_key>, attr_value >::const_iterator
+            i = cs.attrs_set.begin(); i != cs.attrs_set.end(); ++i)
+            out << i->first.first << "\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<pair<file_path, attr_key> >::const_iterator
+              i = cs.attrs_cleared.begin(); i != cs.attrs_cleared.end(); ++i)
+              out << i->first << "\n";
+        }
     }
 
-  copy(print_paths.begin(), print_paths.end(),
-       ostream_iterator<file_path>(cout, "\n"));
+  utf8 summary = utf8(out.str(), origin::internal);
+
+  external summary_external;
+  utf8_to_system_best_effort(summary, summary_external);
+  cout << summary_external;
 }
 
 namespace

reply via email to

[Prev in Thread] Current Thread [Next in Thread]