示例:如何为DasBlog这样的开源项目贡献补丁

Lots of discussion going on around the death of NDoc and Open Source as a viable option for .NET projects. A lot of this harkens back to some of the things discussed in "Is Open Source a Crap Idea" from a a few months back.

关于NDoc和Open Source作为.NET项目的可行选择之死,正在进行大量讨论。 其中很多事情可以追溯到几个月前的“开源是废话”中讨论的一些事情。

  • I said Open Source is free like a Puppy. It requires care, feeding, and in the words of Pete Seale, if you beat it it will run away.

    我说过开源就像小狗一样免费。 它需要护理,喂养,用Pete Seale的话来说,如果打败它,它将消失。

  • Phil says Open Source is free like a Flower. "I think of Open Source software as being like a nice set of flowers in a common space such as a courtyard. Nobody that lives around the common space owns the flowers, yet they all enjoy the presence of the flowers."

    菲尔说开源就像花一样自由。 “我认为开放源代码软件就像是在公共空间(如院子)中的一组漂亮的花朵。住在公共空间中的人没有人拥有这些花朵,但是它们都喜欢花朵的存在。”

  • Jeff says Open Source is free as in Free. "The highest compliment you can pay any piece of open source software is to simply use it, because it's worth using."

    杰夫说开源和免费一样是免费的。 “您可以付给任何开源软件的最高赞誉就是简单地使用它,因为它值得使用。”

From my point of view, just USING Open Source software doesn't fix bugs. Volunteers fix bugs, whether they are a member of the project or not. (Assuming you haven't got an Open Source Sugar Daddy or a company that supports your work.)

从我的角度来看,仅使用开放源代码软件无法修复错误。 志愿者修复错误,无论他们是否为项目成员。 (假设您没有开源Sugar Daddy或一家支持您工作的公司。)

All that is required for Evil to succeed is that Good Men [and Women] do nothing.

邪恶成功的前提是,好男人(和女人)什么都不做。

If you have the power to fix a bug (or at least get the fix started), especially in software you're using, why not make THAT your contribution?

如果您有能力修复错误(或至少开始修复),尤其是在使用的软件中,为什么不花那么多钱?

Jeff says:

杰夫说:

Fine. Create a new blog entry. Walk us through, step by step, the process for contributing a fix to DasBlog. List EVERY step, starting with finding a bug.

精细。 创建一个新的博客条目。 逐步引导我们完成为DasBlog提供修复程序的过程。 列出每个步骤,从查找错误开始。

If it's that easy, prove it.
Jeff Atwood on August 2, 2006 09:40 AM

如果那样简单,那就证明一下。 Jeff Atwood于2006年8月2日上午9:40

Kind of a sassy tone that, Jeff ;) but here you go.

那种卑鄙的口吻,杰夫;),但是你来了。

Note, the bug might be one line, a single char, or quite involved. It all depends. The point is, any help you can give an Open Source dev, no matter how little is a good thing. If you can give them a line number and an idea, that's contributing. Here's an ideal (and real) bug report that stops just short of including the fix. We'll fix it and submit the patch.

注意,该错误可能是一行,一个字符或相当复杂。 一切取决于。 关键是,您可以给开放源代码开发人员任何帮助,无论多么有益。 如果您可以给他们一个电话号码和一个主意,那就很有帮助。 这是一个理想的(真实的)错误报告,仅在不包含此修复程序的情况下就停止了。 我们将对其进行修复并提交补丁。

How to fix a bug in an Open Source Project(Or at least one that uses Subversion or CVS and is hosted at SourceForge)

如何修复开源项目中的错误(或至少一个使用Subversion或CVS并托管在SourceForge上的计算机)

Get the Project

获得项目

Install TortoiseSVN and/or TortoiseCVS, depending on which source control system the Open Source Project is using. They both work about the same, integrating into Explorer.

根据Open Source Project使用的源代码控制系统,安装TortoiseSVN和/或TortoiseCVS 。 它们都差不多工作,并集成到资源管理器中。

Make a new folder, right-click, select Checkout.

新建一个文件夹,右键单击,选择“签出”。

Enter the URL of the Source Repository and click OK. In this example, the project at Source Forge is called "dasblogce" and we are getting the "trunk" so the URL is https://svn.sourceforge.net/svnroot/dasblogce/trunk. This is how folks are getting the very latest "bleeding edge" versions of DasBlog, since we haven't released in a while.

输入源存储库的URL,然后单击“确定”。 在此示例中,Source Forge的项目称为“ dasblogce”,而我们得到的是“ trunk”,因此URL为https://svn.sourceforge.net/svnroot/dasblogce/trunk 。 这是人们获得DasBlog的最新“出血边缘”版本的方式,因为我们已经有一段时间没有发布了。

Opensource2

Build the Project

建立项目

Every project is a little different, but most have a build file, readme or some detail that says how to get started.

每个项目都有点不同,但是大多数项目都有一个构建文件,自述文件或一些详细的说明如何开始的信息。

Assuming you have IIS installed, to build DasBlog, run the CreateDasBlogVdir.vbs file in the tools folder to make the IIS Virtual Directory for your local copy.

假设您已安装IIS,要构建DasBlog,请在tools文件夹中运行CreateDasBlogVdir.vbs文件,以为本地副本创建IIS虚拟目录。

Open up DasBlog All.sln in Visual Studio 2003 and build. Your virtual directory is mapped to <projectdir>\newtelligence.DasBlog.Web and your binaries - since this is a web application - are in the <projectdir>\newtelligence.DasBlog.Web\bin folder.

在Visual Studio 2003中打开DasBlog All.sln并进行构建。 您的虚拟目录已映射到<projectdir> \ newtelligence.DasBlog.Web,并且您的二进制文件(因为这是一个Web应用程序)位于<projectdir> \ newtelligence.DasBlog.Web \ bin文件夹中。

Example: Find a Bug

示例:查找错误

So perhaps you've found a bug. Maybe you got the Yellow Screen of Death. You likely have a stack trace or a strange bit of behavior.

所以也许您发现了一个错误。 也许你得到了死亡黄屏。 您可能有堆栈跟踪或一些奇怪的行为。

Most projects at SourceForge have a home page like http://sourceforge.net/projects/dasblogce. Visit ours and click the Bugs menu item. Pick one, or see if the bug you've found has already been reported.

SourceForge的大多数项目都有一个主页,例如http://sourceforge.net/projects/dasblogce 。 访问我们的网站,然后单击“错误”菜单项。 选择一个,或查看是否已报告您发现的错误。

For example, George V. Reilly reports in Bug 1397557 that our "content filter" feature for making words link as Google Searches doesn't work well. He writes:

例如,乔治五世·赖利( George V. Reilly)在错误1397557报告说,我们的“内容过滤器”功能无法在Google搜索中链接单词。 他写:

[The Content Filter] $g(multiple words) should produce
<a href="
http://www.google.com/search?q=multiple+words">
multiple words</a>. In other words, the spaces should
be URL encoded as pluses in the URL.

[内容过滤器]应该产生$ g(多个单词) <a href=" http://www.google.com/search?q=multiple+words "> 多个单词</a>。 换句话说,空格应URL编码为URL中的加号。

I spent some time looking into a fix. It doesn't seem
to be possible with a regex. See the thread I started at
http://regexadvice.com/forums/14513/ShowPost.aspx

我花了一些时间研究解决方法。 好像没使用正则表达式是可能的。 查看我开始的线程http://regexadvice.com/forums/14513/ShowPost.aspx

My suggested fix.
$g(expr) ->
<a href="
http://www.google.com/search?q=$h(${expr})">
${expr}</a>
where $h is a new kind of content filter, one that uses
a builtin function to URL encode the string.

我建议的修复程序。 $ g(expr)-> <a href=" http://www.google.com/search?q=$h(${expr })"> $ {expr} </a> 其中$ h是一种新型的内容过滤器,它使用URL编码的内置函数。

Here he is kind enough to suggest the desired behavior. As you may have found the bug or undesirable behavior, you may have an opinion as to how to fix it.

在这里,他足够善良地建议期望的行为。 由于您可能已发现该错误或不良行为,因此您可能对如何解决它有意见。

Example: Fixing the Bug

示例:修复错误

So since this bug involves DasBlog's content filter feature, I'll search the project for "ContentFilter" using Ctrl-Shift-F (Find in Files).

因此,由于此错误涉及DasBlog的内容过滤器功能,因此我将使用Ctrl-Shift-F(在文件中查找)在项目中搜索“ ContentFilter”。

Looking at my search, "ApplyContentFilters" looks promising in Utilities line 645.

看我的搜索,“ ApplyContentFilters”在实用程序第645行中看起来很有前途。

As George points out in the bug report, we want to UrlEncoded the result, but we don't want to UrlEncode all results. Just some.

正如George在错误报告中指出的那样,我们想对结果进行UrlEncode,但是我们不想对所有结果进行UrlEncode。 一些。

He also helpfully points me to a post on a RegularExpressions forum where he tried to get the bug fixed using pure Regex. It doesn't appear possible with just RegEx, so we'll use a System.Text.RegularExpressions.MatchEvalulator like the post suggested. He also recommends a new kind of Content Filter that would UrlEncode. In this case, it'll be necessary because we want to do this:

他还为我提供了一个指向RegularExpressions论坛的帖子,他尝试使用纯正则表达式修复该错误。 仅RegEx似乎无法实现,因此我们将使用System.Text.RegularExpressions.MatchEvalulator,如所建议的那样。 他还建议使用UrlEncode的新型内容过滤器。 在这种情况下,这是必须的,因为我们要这样做:

$g(The Quick Brown Fox)

$ g(快棕色狐狸)

into

进入

<a href="http://www.google.com/search?q=The+Quick+Brown+Fox">The Quick Brown Fox</a>

<a href="http://www.google.com/search?q=The+Quick+Brown+Fox"> Quick Brown Fox </a>

Note that if we did a blanket UrlEncode on the first string, we'd get + signs in our linked text.

请注意,如果我们在第一个字符串上进行了覆盖UrlEncode,则在链接的文本中将获得+号。

So, we'll take his suggestion. Here's the code for a new ApplyContentFilters function with our changes in red.

因此,我们接受他的建议。 这是新的ApplyContentFilters函数的代码,其中我们的更改为红色。

Remember, we will be submitting our changes as a DIFF file for the developers/commmiters/admins to check in, as we're assuming we don't have source 'commit' access.

记住,我们将所做的更改作为DIFF文件提交给开发人员/提交者/管理员以签入,因为我们假设我们没有源“提交”访问权限。

private static string CustomUrlEncodingRegexReplacer(Match m)

私有静态字符串CustomUrlEncodingRegexReplacer(匹配m)

{

{

    // Remove the $<char>() from around the string and encode the result.

//从字符串周围删除$ <char>()并对结果进行编码。

    if (m.Value.Length < 4) throw new ArgumentOutOfRangeException("Match",m.Value,"UrlEncoded Content Filters should be in the format $u() where 'u' is any single character. Match strings must be at least 4 characters long.");

如果(m.Value.Length <4)抛出新的ArgumentOutOfRangeException(“ Match”,m.Value,“ UrlEncoded内容过滤器应采用$ u()格式,其中'u'是任何单个字符。匹配字符串至少应为4个字符长。“);

    string trimmed = m.Value.Substring(3,m.Value.Length-4);

修剪字符串= m.Value.Substring(3,m.Value.Length-4);

    return HttpUtility.UrlEncode(trimmed);

返回HttpUtility.UrlEncode(修剪);

}

}

public static string ApplyContentFilters( SiteConfig siteConfig, string content )

公共静态字符串ApplyContentFilters(SiteConfig siteConfig,字符串内容)

{

{

    if ( content == null ){return String.Empty;}

if (content == null ){返回String.Empty;}

    foreach ( ContentFilter filter in siteConfig.ContentFilters )

的foreach(在siteConfig.ContentFilters ContentFilter过滤器)

    {

{

        if ( filter.IsRegEx )

如果(filter.IsRegEx)

        {

{

            try

尝试

            {

{

                if(filter.UrlEncode)

如果(filter.UrlEncode)

                {

{

                    content = Regex.Replace(content, filter.Expression, new MatchEvaluator(CustomUrlEncodingRegexReplacer), RegexOptions.Singleline);

内容= Regex.Replace(内容,filter.Expression,新的MatchEvaluator(CustomUrlEncodingRegexReplacer),RegexOptions.Singleline);

                }

}

                content = Regex.Replace(content, filter.Expression,filter.MapTo,RegexOptions.Singleline);

内容= Regex.Replace(内容,filter.Expression,filter.MapTo,RegexOptions.Singleline);

            }

}

            catch

抓住

            {

{

            }

}

        }

}

        else

其他

        {

{

            content = content.Replace( filter.Expression, filter.MapTo );

content = content.Replace(filter.Expression,filter.MapTo);

        }

}

    }

}

    return content;

返回内容;

}

}

And we'll add our new Content Filter as George suggested to the XML settings file. (Note: we don't need to edit the XML directly, we'll change the editor page in a moment)

然后,我们将乔治建议的新内容过滤器添加到XML设置文件中。 (注意:我们不需要直接编辑XML,我们稍后将更改编辑器页面)

Again, changes in red.

再次,更改为红色

  <ContentFilters>
    <ContentFilter find="\$g\((?&lt;expr&gt;[\w\s\d]+)\)" replace="&lt;a href=&quot;http://www.google.com/search?q=$u(${expr})&quot;&gt;${expr}&lt;/a&gt;" isregex="true"/>
    <ContentFilter find="\$u\((?&lt;expr&gt;[\w\s\d]+)\)" replace="${expr}" isregex="true" urlencode="true"/>...snip other filters...
  </ContentFilters>

<ContentFilters> <ContentFilter find =“ \ $ g \((?&lt; expr&gt; [\ w \ s \ d] +)\)” replace =“&lt; a href =&quot; http://www.google.com/search ?q = $ u( $ {expr} ) ”&gt; $ {expr}&lt; / a&gt;” isregex =“ true” /> <ContentFilter find =“ \ $ u \((?&lt; expr&gt; [\ w \ s \ d] +)\)” replace =“ $ {expr}” isregex =“ true” urlencode =“ true” /> 剪掉其他过滤器</ ContentFilters>

So now after our Google filter (or dictionary filter, or any of the dozens of filters that folks use) runs, we'll be able to UrlEncode arbitrary parts of the result.

因此,现在运行我们的Google过滤器(或字典过滤器,或人们使用的数十种过滤器中的任何一个)后,我们就可以对结果的任意部分进行UrlEncode编码。

Now we'll add UrlEncode as an option to the ContentFilters object. We'll make false the default so we don't break our public interface as we don't want to break existing code or change existing behavior.

现在,我们将UrlEncode作为选项添加到ContentFilters对象。 我们将false设置为默认值,这样我们就不会破坏我们的公共接口,因为我们不想破坏现有的代码或更改现有的行为。

Content Filters don't have to be edited in the XML file directly, they are managed by a rich UI. We'll want to extend the UI quickly.

内容过滤器不必直接在XML文件中进行编辑,它们由功能丰富的UI进行管理。 我们将要快速扩展UI。

On the EditContentFilters page, I'll add a new column to allow us to edit this new option in "EditContentFilters" by copy-pasting from another column.

在EditContentFilters页面上,我将添加一个新列,以允许我们通过从另一列复制粘贴来编辑“ EditContentFilters”中的此新选项。

I also do copy paste of the code to update the config file by using the existing "IsRegEx" example. It's a true/false checkbox-style option, just like the new one we're adding.

我还通过使用现有的“ IsRegEx”示例来复制代码的粘贴以更新配置文件。 这是一个true / false复选框样式的选项,就像我们要添加的新选项一样。

Here's a test of the results. Note the + in the URL in the Status Bar.

这是测试结果。 请注意状态栏中URL中的+。

Making the Patch

制作补丁

Now that we think the bug is fixed, we want to make a patch/diff file that will allow the developer(s) to apply easily so they can consider our patch for committing to the project. We don't want to email them a zip of our project directory. That would mean they'd have to manually diff each file and that's a hassle. Remember the goal here is easy on everyone's part. We don't want to bust our asses sending in the patch and we don't want to stress them out by sending 4 megs of code when we only changed 10 lines.

现在我们认为错误已修复,我们想要制作一个补丁/差异文件,使开发人员可以轻松应用它们,以便他们可以考虑将我们的补丁提交给项目。 我们不想通过电子邮件将他们的项目目录压缩文件发送给他们。 这意味着他们将不得不手动比较每个文件,这很麻烦。 记住,这里的目标对每个人来说都很容易。 我们不想破坏我们在补丁程序中发送的驴子,也不想在我们只更改10行时通过发送4兆代码来给他们压力。

Now I'll right click in the main folder of my project in Explorer and click Create Patch.

现在,我将在资源管理器中右键单击项目的主文件夹,然后单击创建补丁。

From the Create Patch window I will select the files I changed:

在“创建补丁”窗口中,我将选择更改的文件:

In this example, it was only four files. I'll save the unified diff/patch as "contentfilterchange.patch"

在此示例中,只有四个文件。 我将统一的差异/补丁保存为“ contentfilterchange.patch”

If I look inside the patch file with Notepad2 (with it's lovely diff/patch syntax highlighting) I'll see just my few changes with deletes and adds highlighted.

如果我用Notepad2查看补丁文件(突出显示了diff / patch语法),我将看到删除和添加突出显示的部分更改。

Now, we'll log back into SourceForge and upload and attach our patch to the bug.

现在,我们将重新登录SourceForge并上传并将补丁附加到bug

Conclusion

结论

We've just downloaded source to an Open Source application, built it, found a bug, fixed the bug, and submitted a patch to an Open Source Project that we were not committing members of. 

我们刚刚将源代码下载到一个开源应用程序中,对其进行了构建,发现了一个错误,修复了该错误,并向不属于其成员的开源项目提交了补丁。

翻译自: https://www.hanselman.com/blog/example-how-to-contribute-a-patch-to-an-open-source-project-like-dasblog

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值