11 _boundary_line_regex
= re
.compile(r
'^---')
12 _diff_head_regex
= re
.compile(r
'^diff --git a/(.*) b/(.*)$')
13 _index_line_regex
= re
.compile(r
'^index ([a-f0-9]{7,})\.\.([a-f0-9]{7,}) ')
14 _all_zeros_regex
= re
.compile(r
'^0+$')
16 class PatchError(Exception):
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 os
.path
.basename(name
) not in dbcache
.file_cache
:
59 self
.missing_files
= True
60 print 'patch for missing file "%s"' % name
63 output
, ret
= git('am', '-3', input=self
.data
)
66 git('am', '-3', '--abort')
67 git('reset', '--hard')
71 def fast_patch_id(self
):
74 i
= data
.rfind('\n-- \n')
78 output
= git('patch-id', input=data
)[0]
82 patch_id
, commit_id
= output
.split()