Add Dirk Luetjen's ssphys libraries and command-line tool
[vss2svn.git] / ssphys / SSPhys / HistoryCommand.cpp
blobce33f600ea7a4b6f6d5d17a5019147da22f21e7a
1 // HistoryCommand.cpp: implementation of the CHistoryCommand class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "HistoryCommand.h"
7 #include "VersionFilter.h"
8 #include "Formatter.h"
9 #include <SSPhysLib\SSItemInfoObject.h>
11 //////////////////////////////////////////////////////////////////////
12 // Construction/Destruction
13 //////////////////////////////////////////////////////////////////////
15 //---------------------------------------------------------------------------
16 CHistoryCommand::CHistoryCommand ()
17 : CCommand ("history"),
18 m_bIncludeDeadRecords (false),
19 m_bIncludeLabels (false),
20 m_bIncludeActions (true)
24 COptionInfoList CHistoryCommand::GetOptionsInfo () const
26 COptionInfoList options = CCommand::GetOptionsInfo();
27 options.push_back (COptionInfo ('d', 'd', "dead", "include dead records", COptionInfo::tristateArgument));
28 options.push_back (COptionInfo ('l', 'l', "label", "include label records", COptionInfo::tristateArgument));
29 return options;
32 bool CHistoryCommand::SetOption (const COption& option)
34 switch (option.id)
36 case 'd':
37 m_bIncludeDeadRecords = true;
38 m_bOnlyDeadRecords &= option.value.pTristateValue;
39 break;
40 case 'l':
41 m_bIncludeLabels = true;
42 if (option.value.pTristateValue == set)
43 m_bIncludeActions = false;
44 else if (option.value.pTristateValue == cleared)
45 m_bIncludeLabels = false;
46 break;
47 default:
48 return false;
50 return true;
53 bool CHistoryCommand::SetArguments (CArguments& args)
55 if (args.empty ())
56 throw SSException ("no argument");
58 m_PhysFile = args.front ();
59 args.pop ();
60 return true;
63 void CHistoryCommand::Execute ()
65 SSHistoryFile file(m_PhysFile);
67 const CVersionFilter* pFilter = NULL; // m_pOptions->GetVersionFilter ();
68 // std::auto_ptr <ISSObjectVisitor> pFormatter (CVssFormatterFactory::MakeFormatter());
70 SSVersionObject version = file.GetLastVersion();
71 while (version)
73 bool bFiltered = pFilter ? pFilter->Filter(&version) : false;
75 if (!m_bIncludeLabels && version.GetActionID () == Labeled)
76 bFiltered = true;
78 if (!m_bIncludeActions && version.GetActionID () != Labeled)
79 bFiltered = true;
81 if (!bFiltered)
82 g_pFormatter->Format (version);
84 version = file.GetPrevVersion(version);