gpt4 book ai didi

c - 为什么 GNU 补丁无法解决这个差异?

转载 作者:太空狗 更新时间:2023-10-29 16:09:51 28 4
gpt4 key购买 nike

你好,

编辑:我想我会提到这个有点长的问题现在已经解决了,这要归功于下面 Adam Goode 的回答,如果您只是在浏览时略读的话。

我已经获得了要添加到 Apache 2.2.14 的补丁,但一个统一的 diff 根本没有为文件打补丁。我正在使用 GNU 补丁 2.5.4。

我不得不忽略空格,因为原始补丁没有做好,即许多差异似乎是针对制表符 -> 空格转换。这些差异的用处甚至更少,因为补丁文件已在交付链的某处进行了修改,例如svn 仓库、Jira 系统、web 界面等等,这样反正所有的tabs 都已经转换成空格了!

我在 Solaris 10 上使用的命令是:

/usr/bin/gpatch --verbose --ignore-whitespace -p1 -d . \
<mod_cache.diff

输出是:

...

Hmm... The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: httpd/modules/cache/mod_cache.h
|===================================================================
|--- httpd/modules/cache/mod_cache.h
|+++ httpd/modules/cache/mod_cache.h
--------------------------
Patching file modules/cache/mod_cache.h using Plan A...
Hunk #1 succeeded at 24.
Hunk #2 succeeded at 86.
Hunk #3 succeeded at 138.
Hunk #4 succeeded at 163.
Hunk #5 succeeded at 184.
Hunk #6 succeeded at 217.
Hunk #7 succeeded at 271.
Hunk #8 succeeded at 380.

...

注意

Hunk #2 succeeded at 86.

行。

补丁文件包含几个统一的差异,但相关的差异是:

...

Index: httpd/modules/cache/mod_cache.h
===================================================================
--- httpd/modules/cache/mod_cache.h
+++ httpd/modules/cache/mod_cache.h
@@ -86,9 +86,13 @@
#define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY
#define DEFAULT_CACHE_EXPIRE MSEC_ONE_HR
#define DEFAULT_CACHE_LMFACTOR (0.1)
+#define DEFAULT_CACHE_MAXAGE 5
+#define DEFAULT_CACHE_LOCKPATH "/mod_cache-lock"
+#define CACHE_LOCKNAME_KEY "mod_cache-lockname"
+#define CACHE_LOCKFILE_KEY "mod_cache-lockfile"

-/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
- * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
+/* Create a set of CACHE_DECLARE(type), CACHE_DECLARE_NONSTD(type) and
+ * CACHE_DECLARE_DATA with appropriate export and import tags for the platform
*/
#if !defined(WIN32)
#define CACHE_DECLARE(type) type

...

源的相关部分,应用补丁后(据推测),加上一些上下文,是:

...

#define MSEC_ONE_DAY ((apr_time_t)(86400*APR_USEC_PER_SEC)) /* one day, in microseconds */
#define MSEC_ONE_HR ((apr_time_t)(3600*APR_USEC_PER_SEC)) /* one hour, in microseconds */
#define MSEC_ONE_MIN ((apr_time_t)(60*APR_USEC_PER_SEC)) /* one minute, in microseconds */
#define MSEC_ONE_SEC ((apr_time_t)(APR_USEC_PER_SEC)) /* one second, in microseconds */
#define DEFAULT_CACHE_MAXEXPIRE MSEC_ONE_DAY
#define DEFAULT_CACHE_EXPIRE MSEC_ONE_HR
#define DEFAULT_CACHE_LMFACTOR (0.1)

/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
* PROXY_DECLARE_DATA with appropriate export and import tags for the platform
*/
#if !defined(WIN32)
#define CACHE_DECLARE(type) type
#define CACHE_DECLARE_NONSTD(type) type
#define CACHE_DECLARE_DATA
#elif defined(CACHE_DECLARE_STATIC)

...

所有其他补丁似乎已成功应用或被忽略。

为什么这个特殊的 diff 没有采取任何想法?

编辑:按照下面 Adam 的建议将补丁模糊因子降低到零后,补丁成功运行。

感谢 Adam Goode,如果我能再给你投票,我会的!这是 relevant paragraph for fuzz如果您有兴趣,请参阅 GNU diffutils 手册。

编辑 2: 顺便说一句,在该模糊段落的底部有一个高度相关的警告:

patch usually produces the correct results, even when it must make many guesses. However, the results are guaranteed only when the patch is applied to an exact copy of the file that the patch was generated from.

不幸的是,在这种情况下,我不能确定他们的mod_cache.h和官方的2.2.14 mod_cache,h是一样的! )-:

最佳答案

当你使用 --ignore-whitespace 而不使用 --fuzz=0 时,你基本上是在告诉补丁它应该做一个尽力而为的补丁,而不是完全失败。因为这是尽力而为,所以真的没有办法保证它会完美地工作。出于这个原因,git 和 Fedora RPM 默认设置 --fuzz=0 以便这些类型的问题在补丁时(而不是编译时或运行时)失败。

如果你想将你的文件保存为上游压缩包 + 补丁,你应该重做补丁并确保它可以应用 --fuzz=0

关于c - 为什么 GNU 补丁无法解决这个差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1651996/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com