Index: /CMT/HEAD/ChangeLog
===================================================================
--- /CMT/HEAD/ChangeLog	(revision 571)
+++ /CMT/HEAD/ChangeLog	(revision 572)
@@ -1,2 +1,14 @@
+2011-04-29    <rybkin@lal.in2p3.fr> 455
+
+	* source/cmt_use.h: In class Use, declare function show_sub_uses with
+	modified signature to show, in more detail, origin of uses auto_imports
+	state
+	* source/cmt_use.cxx: In class Use, in function set_auto_imports,
+	implement policy where use has Off != auto_imports, if it is (direct)
+	sub-use without -no_auto_imports of either current use or sub-use with
+	Off != auto_imports, implement function show_sub_uses with modified
+	signature, in function show_all, make use of show_sub_uses with modified
+	signature
+	
 2011-04-25    <rybkin@lal.in2p3.fr> 454
 
Index: /CMT/HEAD/source/cmt_use.cxx
===================================================================
--- /CMT/HEAD/source/cmt_use.cxx	(revision 571)
+++ /CMT/HEAD/source/cmt_use.cxx	(revision 572)
@@ -521,5 +521,6 @@
   use = &(current ());
   use->unselect ();
-  if (!Cmt::get_quiet () && mode != Xml) use->show_sub_uses ("", skip_discarded, out);
+  cmt_map <Use*, bool> visited;
+  if (!Cmt::get_quiet () && mode != Xml) use->show_sub_uses (visited, "", use->auto_imports, skip_discarded, out);
 
   if (uses.size () > 0)
@@ -3962,4 +3963,5 @@
   static int level (-1);
   level++;
+  /*
   if (level == 0)
     {
@@ -3967,13 +3969,35 @@
       selected = true;
     }
-
-  if (visited.has (this) &&
-      (1 != level || selected))
-    // revisit sub-uses of current (level == 0) use
-    // encountered in its requirements file for the first time (selected == false)
-    // to ensure their auto_imports state takes precedence
-    {
-      level--;
-      return;
+  */
+  switch (context_state)
+    {
+    case Unspecified:
+    case On:
+      if (!visited.has (this) ||
+	  // revisit uses that may be turned into Off != auto_imports
+	  // via some other use(s)
+	  // policy being use has Off != auto_imports,
+	  // if it is (direct) sub-use without -no_auto_imports of
+	  // either current use or sub-use with Off != auto_imports
+	  (Off == auto_imports && Off != specified_state)
+	  )
+	{
+	  auto_imports = specified_state;
+	  context_state = UseContext::mask_auto_imports (context_state, auto_imports);
+	}
+      else
+	{
+	  level--;
+	  return;
+	}
+      break;
+    case Off:
+      if (visited.has (this))
+	{
+	  level--;
+	  return;
+	}
+      auto_imports = context_state;
+      break;
     }
 
@@ -3989,37 +4013,5 @@
   static bool yes (true);
   visited.add (this, yes);
-  if (1 == level) selected = true;
-  //  if (auto_imports == context_state) return;
-  
-  //State old_state = auto_imports;
-  
-  //auto_imports = context_state;
-
-  switch (context_state)
-    {
-    case Unspecified:
-    case On:
-      //if (auto_imports == specified_state) return;
-      auto_imports = specified_state;
-      /*
-      switch (auto_imports)
-	{
-	case Unspecified:
-	  break;
-	case Off:
-	  context_state = Off;
-	  break;
-	case On:
-	  context_state = On;
-	  break;
-	}
-      */
-      context_state = UseContext::mask_auto_imports (context_state, auto_imports);
-      break;
-    case Off:
-      //if (auto_imports == context_state) return;
-      auto_imports = context_state;
-      break;
-    }
+
   cmt_string s;
   static const cmt_string state_text[] = {"Unspecified", "Off", "On"};
@@ -4084,5 +4076,4 @@
 	    {
 	      visited.add (sub_uses[i], yes);
-	      sub_uses[i]->select ();
 	    }
 	}
@@ -4494,19 +4485,65 @@
 
 //----------------------------------------------------------
-void Use::show_sub_uses (const cmt_string& request, bool skip_discarded, ostream& out)
-//void Use::show_sub_uses (const cmt_string& request, bool skip_discarded)
-{
-  Use* current = &(Use::current ());
-  int n;
-  Use* use;
-  static int level = 0;
-
+void Use::show_sub_uses (cmt_map <Use*, bool>& visited,
+			 const cmt_string& request, State specified_state,
+			 bool skip_discarded, ostream& out)
+//void Use::show_sub_uses (const cmt_string& request, bool skip_discarded, ostream& out)
+{
   if (skip_discarded && discarded) return;
   if (m_hidden) return;
 
+  Use* current = &(Use::current ());
+  static State context_state (auto_imports);
+  static int level (-1);
+  level++;
+
+  if (level == 0)
+    {
+      unselect_all ();
+      selected = true;
+    }
+
+  State saved_context_state (context_state);
+  switch (context_state)
+    {
+    case Unspecified:
+    case On:
+      if (!visited.has (this)
+	  || level == 1)
+	// show all direct sub-uses of current use
+	{
+	  context_state = UseContext::mask_auto_imports (context_state, specified_state);
+	}
+      else if (Off != auto_imports && Off != specified_state
+	       //      else if (specified_state == auto_imports && Off != specified_state
+	       && !selected)
+	// show this sub-use as it may have been used to make Off != auto_imports
+	// and is sufficient in order to consider it Off != auto_imports,
+	// mark selected not to consider use again and thus avoid looping this way
+	{
+	  selected = true;
+	  //	  auto_imports = specified_state;
+	  context_state = UseContext::mask_auto_imports (context_state, specified_state);
+	}
+      else
+	{
+	  level--;
+	  return;
+	}
+      break;
+    case Off:
+      if (visited.has (this)
+	  )
+	{
+	  level--;
+	  return;
+	}
+      break;
+    }
+
   if (level > 0)
     {
       out << "# ";
-      for (n = 0; n < (level-1); n++) out << "  ";
+      for (int n = 0; n < (level-1); n++) out << "  ";
 
       if (request == "")
@@ -4536,8 +4573,8 @@
       else if (initial_scope != ScopePublic) out << " (private)";
 
-      if (auto_imports == Off) out << " (no_auto_imports)";
+      if (specified_state == Off) out << " (no_auto_imports)";
+      //      if (auto_imports == Off) out << " (no_auto_imports)";
 
       if (structuring_style == without_version_directory) out << " (no_version_directory)";
-      //      if (style == no_version_style) out << " (no_version_directory)";
 
       if (m_has_native_version)
@@ -4557,12 +4594,11 @@
     }
 
-  if (selected) return;
-  selected = true;
-
-  level++;
+  static bool yes (true);
+  visited.add (this, yes);
+
   for (int i = 0; i < sub_uses.size (); i++)
     {
-      //use = sub_uses[n];
       //if (use == 0) continue;
+      Use* use;
       if (sub_uses[i]->m_index >= 0 && !sub_uses[i]->discarded)
 	{
@@ -4578,4 +4614,5 @@
 	  else
 	    {
+	      visited.add (sub_uses[i], yes);
 	      continue;
 	    }
@@ -4585,15 +4622,18 @@
 
       ScopeType saved_scope = use->initial_scope;
-      State saved_state = use->auto_imports;
+      //      State saved_state = use->auto_imports;
 
       use->initial_scope = sub_use_scopes[i];
-      use->auto_imports = sub_use_auto_imports[i];
-
-      use->show_sub_uses (request, skip_discarded, out);
+      //      use->auto_imports = sub_use_auto_imports[i];
+
+      use->show_sub_uses (visited, request, sub_use_auto_imports[i], skip_discarded, out);
+      //use->show_sub_uses (request, skip_discarded, out);
 
       use->initial_scope = saved_scope;
-      use->auto_imports = saved_state;
+      //      use->auto_imports = saved_state;
     }
   level--;
+
+  context_state = saved_context_state;
 }
 
Index: /CMT/HEAD/source/cmt_use.h
===================================================================
--- /CMT/HEAD/source/cmt_use.h	(revision 571)
+++ /CMT/HEAD/source/cmt_use.h	(revision 572)
@@ -198,6 +198,7 @@
   bool is_client (const cmt_string& package,
                   const cmt_string& version);
-  void show_sub_uses (const cmt_string& request, bool skip_discarded = false,
-		      ostream& out = cout);
+  void show_sub_uses (cmt_map <Use*, bool>& visited,
+		      const cmt_string& request, State specified_state,
+		      bool skip_discarded = false, ostream& out = cout);
   //  void show_sub_uses (const cmt_string& request, bool skip_discarded = false);
   bool select_alternate ();
