8 import cPickle
as pickle
9 from cStringIO
import StringIO
11 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(sys
.argv
[0])))
13 from cvs2svn_lib
import config
14 from cvs2svn_lib
.context
import Ctx
15 from cvs2svn_lib
.common
import DB_OPEN_READ
16 from cvs2svn_lib
.artifact_manager
import artifact_manager
21 sys
.stderr
.write('Usage: %s OPTION [DIRECTORY]\n\n' % os
.path
.basename(cmd
))
23 'Show the contents of the temporary database files created by cvs2svn\n'
24 'in a structured human-readable way.\n'
27 ' -R SVNRepositoryMirror revisions table\n'
28 ' -N SVNRepositoryMirror nodes table\n'
29 ' -r rev SVNRepositoryMirror node tree for specific revision\n'
30 ' -m MetadataDatabase\n'
31 ' -f CVSPathDatabase\n'
32 ' -c PersistenceManager SVNCommit table\n'
33 ' -C PersistenceManager cvs-revs-to-svn-revnums table\n'
34 ' -i CVSItemDatabase (normal)\n'
35 ' -I CVSItemDatabase (filtered)\n'
36 ' -p file Show the given file, assuming it contains a pickle.\n'
38 'DIRECTORY is the directory containing the temporary database files.\n'
39 'If omitted, the current directory is assumed.\n')
43 def print_node_tree(db
, key
="0", name
="<rootnode>", prefix
=""):
44 print "%s%s (%s)" % (prefix
, name
, key
)
46 dict = marshal
.loads(db
[key
])
50 print_node_tree(db
, entry
[1], entry
[0], prefix
+ " ")
53 def show_int2str_db(fname
):
54 db
= anydbm
.open(fname
, 'r')
55 k
= map(int, db
.keys())
58 print "%6d: %s" % (i
, db
[str(i
)])
60 def show_str2marshal_db(fname
):
61 db
= anydbm
.open(fname
, 'r')
65 print "%6s: %s" % (i
, marshal
.loads(db
[i
]))
67 def show_str2pickle_db(fname
):
68 db
= anydbm
.open(fname
, 'r')
72 o
= pickle
.loads(db
[i
])
73 print "%6s: %r" % (i
, o
)
76 def show_str2ppickle_db(fname
):
77 db
= anydbm
.open(fname
, 'r')
80 k
.sort(key
=lambda s
: int(s
, 16))
81 u1
= pickle
.Unpickler(StringIO(db
['_']))
84 u2
= pickle
.Unpickler(StringIO(db
[i
]))
85 u2
.memo
= u1
.memo
.copy()
87 print "%6s: %r" % (i
, o
)
90 def show_cvsitemstore():
91 for cvs_file_items
in Ctx()._cvs
_items
_db
.iter_cvs_file_items():
92 items
= cvs_file_items
.values()
93 items
.sort(key
=lambda i
: i
.id)
95 print "%6x: %r" % (item
.id, item
,)
98 def show_filtered_cvs_item_store():
99 from cvs2svn_lib
.cvs_item_database
import IndexedCVSItemStore
100 db
= IndexedCVSItemStore(
101 artifact_manager
.get_temp_file(config
.CVS_ITEMS_FILTERED_STORE
),
102 artifact_manager
.get_temp_file(config
.CVS_ITEMS_FILTERED_INDEX_TABLE
),
105 ids
= list(db
.iterkeys())
109 print "%6x: %r" % (cvs_item
.id, cvs_item
,)
114 """A mock project-list that can be assigned to Ctx()._projects."""
119 def __getitem__(self
, i
):
120 return self
.projects
.setdefault(i
, 'Project%d' % i
)
125 artifact_manager
.register_temp_file(filename
, None)
127 from cvs2svn_lib
.common
import DB_OPEN_READ
128 from cvs2svn_lib
.symbol_database
import SymbolDatabase
129 from cvs2svn_lib
.cvs_path_database
import CVSPathDatabase
130 rf(config
.CVS_PATHS_DB
)
132 from cvs2svn_lib
.cvs_item_database
import OldCVSItemStore
133 from cvs2svn_lib
.metadata_database
import MetadataDatabase
134 rf(config
.METADATA_DB
)
135 rf(config
.CVS_ITEMS_STORE
)
136 rf(config
.CVS_ITEMS_FILTERED_STORE
)
137 rf(config
.CVS_ITEMS_FILTERED_INDEX_TABLE
)
138 artifact_manager
.pass_started(None)
140 Ctx()._projects
= ProjectList()
141 Ctx()._symbol
_db
= SymbolDatabase()
142 Ctx()._cvs
_path
_db
= CVSPathDatabase(DB_OPEN_READ
)
143 Ctx()._cvs
_items
_db
= OldCVSItemStore(
144 artifact_manager
.get_temp_file(config
.CVS_ITEMS_STORE
)
146 Ctx()._metadata
_db
= MetadataDatabase(DB_OPEN_READ
)
150 opts
, args
= getopt
.getopt(sys
.argv
[1:], "RNr:mlfcCiIp:")
151 except getopt
.GetoptError
:
154 if len(args
) > 1 or len(opts
) != 1:
158 Ctx().tmpdir
= args
[0]
162 show_int2str_db(config
.SVN_MIRROR_REVISIONS_TABLE
)
165 config
.SVN_MIRROR_NODES_STORE
,
166 config
.SVN_MIRROR_NODES_INDEX_TABLE
172 sys
.stderr
.write('Option -r requires a valid revision number\n')
174 db
= anydbm
.open(config
.SVN_MIRROR_REVISIONS_TABLE
, 'r')
175 key
= db
[str(revnum
)]
177 db
= anydbm
.open(config
.SVN_MIRROR_NODES_STORE
, 'r')
178 print_node_tree(db
, key
, "Revision %d" % revnum
)
180 show_str2marshal_db(config
.METADATA_DB
)
183 cvs_files
= list(Ctx()._cvs
_path
_db
.itervalues())
185 for cvs_file
in cvs_files
:
186 print '%6x: %s' % (cvs_file
.id, cvs_file
,)
190 config
.SVN_COMMITS_INDEX_TABLE
, config
.SVN_COMMITS_STORE
193 show_str2marshal_db(config
.CVS_REVS_TO_SVN_REVNUMS
)
199 show_filtered_cvs_item_store()
201 obj
= pickle
.load(open(a
))
209 if __name__
== '__main__':