开发者

Identifying .patch files

Here is the problem. I am writing a piece of software that query bug attachments from a Bug Tracking System. I am able to filter the query by only getting text attachment (plain/text etc) and I want to keep only valid patch files (files that have a similar diff -u output that can be applied as a patch to a source file). So I need a way to specify which attachment is a valid patch. For example:

let say I have this attachment with the following content:

Index: compiler/cpp/src/generate/t_csharp_generator.cc

--- compiler/cpp/src/generate/t_csharp_generator.cc (revision 1033689) +++ compiler/cpp/src/generate/t_csharp_generator.cc (working copy) @@ -456,7 +456,7 @@ t = ((t_typedef*)t)->get_type(); } if ((*m_iter)->get_value() != NULL) { - print_const_value(out, "this." + (*m_iter)->get_name(), t, (*m_iter)->get_value(), true, true); + print_const_value(out, "this._" + (*m_iter)->get_name(), t, (*m_iter)->get_value(), true, true); } }

How can I know this is a valid patch? Is there a regex to match some possible diff -u outputs so I can write something like this in java:

String attachmentContent = ..... if(attachmentContent.matches(regex开发者_运维问答))...

Thank you in advance, Elvis


You won't be able to test with a simple Regex, nor a complex by the way, it would require a regular expression engine which is able to interpret the portions between @@ as numbers, and define repetition counts from that, I don't know a RE engine which does that.

On the other hand you should not have too much problems finding a library parsing and loading Unix patches (and this is definitely not a compute-intensive task), so simply trying to load the patch would allow you to validate it. e.g. Java diff utils should do that straight forward.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜