Index: /CMT/HEAD/ChangeLog
===================================================================
--- /CMT/HEAD/ChangeLog	(revision 574)
+++ /CMT/HEAD/ChangeLog	(revision 575)
@@ -1,2 +1,13 @@
+2011-05-04    <rybkin@lal.in2p3.fr> 457
+
+	* source/cmt_use.h: In class Use, declare function set_auto_imports_state
+	with modified signature to follow policy similar to that of function
+	set_auto_imports
+	* source/cmt_use.cxx: In class Use, in function	set_auto_imports_state,
+	implement policy similar to that of function set_auto_imports
+	* source/cmt_parser.cxx: In class StandardMacroBuilder, in function
+	fill_for_all_constituents, make use of set_auto_imports_state with modified
+	signature
+	
 2011-05-02    <rybkin@lal.in2p3.fr> 456
 
Index: /CMT/HEAD/source/cmt_parser.cxx
===================================================================
--- /CMT/HEAD/source/cmt_parser.cxx	(revision 574)
+++ /CMT/HEAD/source/cmt_parser.cxx	(revision 575)
@@ -9023,5 +9023,5 @@
 		if (Cmt::get_debug ())
 		  {
-		    cout << constituent.name  << " needs imports " << import
+		    cout << constituent.name  << " has import request " << import
 			 << " i=" << use_index << " package=" 
 			 << u->get_package()->get_name()
@@ -9057,15 +9057,12 @@
 	  }
 
+	/*
 	cmt_map <Use*, bool> visited;
 	static bool yes (true);
 	visited.add (&(Use::current()), yes);
 	Use::set_auto_imports_state (uses, auto_imports_states, visited);
-	
-	if (Cmt::get_debug ())
-	  {
-	    cout << constituent.name  << " has imports " << endl;
-	  }
-	
-	
+	*/	
+	Use::set_auto_imports_state (uses, auto_imports_states);
+
 	/**
 	 *   Find all newly exposed packages and precompute this list inside
@@ -9090,13 +9087,25 @@
 	    Package* p = u->get_package ();
 	    if (p->is_cmt ()) continue;
-	    
-	    if (Cmt::get_debug ())
-	      {
-		cout << constituent.name  << " has import " << p->get_name () << endl;
-	      }
-	    
+
 	    imports.push_back (u);
 	  }
         
+	if (Cmt::get_debug ())
+	  {
+	    if (imports.size () == 0)
+	      {
+		cout << constituent.name  << " needs no imports" << endl;
+	      }
+	    else
+	      {
+		cout << constituent.name  << " has imports" << endl;
+		for (int i = 0; i < imports.size (); i++)
+		  {
+		    cout << constituent.name  << " has import "
+			 << imports[i]->get_package_name () << endl;
+		  }
+	      }
+	  }
+
 	/**
 	 *  Only for linkopts we take care of the order. This means
Index: /CMT/HEAD/source/cmt_use.cxx
===================================================================
--- /CMT/HEAD/source/cmt_use.cxx	(revision 574)
+++ /CMT/HEAD/source/cmt_use.cxx	(revision 575)
@@ -1251,4 +1251,110 @@
 //----------------------------------------------------------
 void Use::set_auto_imports_state (const Use::UsePtrVector& uses,
+				  cmt_vector<bool>& auto_imports_states)
+{
+  if (0 == uses.size ()) return;
+
+  static int level (0);
+  if (level == 0)
+    {
+      unselect_all ();
+      Use::current().select ();
+    }
+
+  if (Cmt::get_debug ())
+    {
+      cout << "Use::set_auto_imports_state>|";
+      for (int i = level; i > 0; i--) cout << "-";
+      for (int i = 0; i < uses.size (); i++)
+      //for (int i = uses.size () - 1; i >= 0; i--)
+	{
+	  cout << " " << uses[i]->get_package_name ()
+	       << "(" << uses[i]->auto_imports << ")";
+	}
+      cout << ">" << endl;
+    }
+
+  for (int i = 0; i < uses.size (); i++)
+  //for (int i = uses.size () - 1; i >= 0; i--)
+    {
+      const Use* use = uses[i];
+      if (!auto_imports_states[use->m_index])
+	auto_imports_states[use->m_index] = true;
+    }
+
+  Use::UsePtrVector subuses;
+  for (int k = 0; k < uses.size (); k++)
+  //for (int i = uses.size () - 1; i >= 0; i--)
+    {
+      Use* use = uses[k];
+      if (use->is_selected ()) continue;
+      use->select ();
+      for (int i = 0; i < use->sub_uses.size (); i++)
+	{
+	  if (use->sub_uses[i]->m_index >= 0 && !use->sub_uses[i]->discarded)
+	    {
+	      if (use->sub_use_auto_imports[i] != Off
+		  && !use->sub_uses[i]->is_selected ())
+		{
+		  subuses.push_back (use->sub_uses[i]);
+		}
+	    }
+	  else
+	    {
+	      if (Cmt::get_debug ())
+		{
+		  cout << "Use::set_auto_imports_state> " << use->get_package_name ()
+		       << " -> sub_use " << use->sub_uses[i]->get_package_name ()
+		       << "[" << use->sub_uses[i] << ", discarded="
+		       << use->sub_uses[i]->discarded << ", m_index="
+		       << use->sub_uses[i]->m_index << " : invalid]" << endl;
+		}
+	      Use* au (find_valid (use->sub_uses[i]->get_package_name ()));
+	      if (au)
+		{
+		  if (Cmt::get_debug ())
+		    {
+		      cout << "Use::set_auto_imports_state> " << use->get_package_name ()
+			   << " -> sub_use " << au->get_package_name ()
+			   << "[" << au << ", discarded="
+			   << au->discarded << ", m_index="
+			   << au->m_index << " : valid]" << endl;
+		    }
+		  if (use->sub_use_auto_imports[i] != Off
+		      && !au->is_selected ())
+		    {
+		      subuses.push_back (au);
+		    }
+		}
+	      else
+		{
+		  use->sub_uses[i]->select ();
+		}
+	    }
+	}
+    }
+
+  level++;
+  Use::set_auto_imports_state (subuses, auto_imports_states);
+  level--;
+
+  if (Cmt::get_debug ())
+    {
+      cout << "Use::set_auto_imports_state><";
+      for (int i = level; i > 0; i--) cout << "-";
+      for (int i = 0; i < uses.size (); i++)
+      //for (int i = uses.size () - 1; i >= 0; i--)
+	{
+	  cout << " " << uses[i]->get_package_name ()
+	       << "(" << (auto_imports_states[uses[i]->m_index] ? "+" : "-") << ")";
+	}
+      cout << "|" << endl;
+    }
+
+  return;
+}
+
+//----------------------------------------------------------
+void Use::set_auto_imports_state (const Use::UsePtrVector& uses,
 				  cmt_vector<bool>& auto_imports_states,
 				  cmt_map <Use*, bool>& visited)
Index: /CMT/HEAD/source/cmt_use.h
===================================================================
--- /CMT/HEAD/source/cmt_use.h	(revision 574)
+++ /CMT/HEAD/source/cmt_use.h	(revision 575)
@@ -35,4 +35,6 @@
   //static void set_auto_imports_state (int use_index,
   //cmt_vector<bool>& auto_imports_states);
+  static void set_auto_imports_state (const Use::UsePtrVector& uses,
+				      cmt_vector<bool>& auto_imports_states);
   static void set_auto_imports_state (const Use::UsePtrVector& uses,
 				      cmt_vector<bool>& auto_imports_states,
