1 import sys
, os
, subprocess
4 class RCSError(Exception):
7 class ParseError(Exception):
11 def __init__(self
, work_tree
, git_dir
=None, strip_directories
=True):
12 self
.work_tree
= work_tree
13 if git_dir
is not None:
14 self
.git_dir
= git_dir
16 self
.git_dir
= os
.path
.join(work_tree
, '.git')
17 self
.strip_dir
= strip_directories
19 def command(self
, *args
):
20 cmd
= ["git", "--git-dir=" + self
.git_dir
, "--work-tree=" + self
.work_tree
,]
22 subprocess
.check_call(cmd
)
30 def __init__(self
, name
, revision
, date
, author
, context
=None):
31 self
.name
= os
.path
.normpath(name
)
32 self
.revision
= revision
35 self
.branch
= self
.gitref
38 def _data_blob(self
, data
, write
=sys
.stdout
.write
):
39 write("data %s\n" % len(data
))
43 def to_git(self
, branch
=None, write
=sys
.stdout
.write
, strip_dir
=False):
45 filename
= os
.path
.basename(self
.name
)
51 write("commit %s\n" % branch
)
52 write("committer %s <%s@flossmanuals.net> %s +0000\n" %
53 (self
.author
, self
.author
, self
.date
))
54 self
._data
_blob
("TWiki import: %s revision %s" % (self
.name
, self
.revision
))
55 write('M 644 inline %s\n' % (filename
))
56 self
._data
_blob
(self
.contents
)
59 def to_git_slow(self
, branch
=None, write
=None, strip_dir
=False):
60 """Write to git via the working tree"""
62 filename
= os
.path
.basename(self
.name
)
66 if branch
is not None and branch
!= self
.branch
:
67 if branch
in self
.branches
:
68 self
.git
.command("checkout", branch
)
70 self
.git
.command("checkout", "-l", "-b", branch
)
71 self
.branches
.add(branch
)
73 # put the new version there
74 f
= open(filename
, 'w')
75 f
.write(self
.contents
)
77 subprocess
.check_call(["git", "--git-dir=%s"% self
.gitdir
,
78 "--work-tree=%s" % self
.worktree
,
80 "--author=%s@flossmanuals.net" % self
.author
,
81 "-m", "TWiki import: %s rev. %s" % (self
.name
, self
.revision
),
86 return ("<File %s revision %s branch: %s (%s, %s)>" %
87 (self
.name
, self
.revision
, self
.branch
, self
.author
, self
.date
))
91 def set_date(self
, date
):
92 raise NotImplementedError("subclass me, please")
95 def twiki_clean(lines
):
96 """Remove TWiki Metadata"""
100 if not line
.startswith('%META:'):
107 def thoeny_filter(revision
):
108 """Reject old commits and commits by known twiki authors"""
109 if (revision
.author
in ('PeterThoeny', 'thoeny')
110 or int(revision
.date
) < 1050000000):