9 _boundary_line_regex
= re
.compile(r
'^---')
10 _diff_head_regex
= re
.compile(r
'^diff --git a/(.*) b/(.*)$')
11 _index_line_regex
= re
.compile(r
'^index ([a-f0-9]{7,})\.\.([a-f0-9]{7,}) ')
12 _all_zeros_regex
= re
.compile(r
'^0+$')
14 class PatchError(Exception):
19 file_cache
= dbcache
.Cache(db
.Filename
, db
.Filename
.name
, db
.Session())
21 def __init__(self
, data
):
22 self
.blobs_pre
= set()
23 self
.blobs_post
= set()
24 self
.missing_files
= False
29 def _parse(self
, data
):
34 for line
in data
.splitlines(True):
35 if _boundary_line_regex
.match(line
):
38 m
= _diff_head_regex
.match(line
)
41 # at least the 'pre' filename should exist
45 m
= _index_line_regex
.match(line
)
47 if not _all_zeros_regex
.match(m
.group(1)):
48 self
.blobs_pre
.add(m
.group(1))
49 self
._check
_file
(filename
)
50 self
.blobs_post
.add(m
.group(2))
55 self
.notes
= ''.join(notes
)
57 def _check_file(self
, name
):
58 if (not self
.missing_files
59 and os
.path
.basename(name
) not in self
.file_cache
):
60 self
.missing_files
= True
61 print 'patch for missing file "%s"' % name
64 print 'trying to apply patch-%x' % id(self
)
65 output
, ret
= git('am', input=self
.data
)
69 git('reset', '--hard')