From: Clemens Buchacher <drizzd@aon.at>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context
Date: Sat, 30 Aug 2008 18:56:00 +0200 [thread overview]
Message-ID: <20080830165600.GB25370@localhost> (raw)
In-Reply-To: <20080830164527.GA25370@localhost>
git apply does not work correctly with zero-context patches. It does a
little better with --unidiff-zero.
---
This appears to fix staging hunks with zero context lines in the majority of
cases. Staging individual lines still is a problem frequently.
In any case, it's easy enough to break zero-context diff & patch like this:
echo a > victim
git add victim
echo b >> victim
git diff -U0 | git apply --cached --unidiff-zero
git diff
So before delving into this problem to deeply, I'd like to find out who
needs fixing exactly. Is there documentation defining how zero-context git
diff output should look like? Or is git apply the culprit in the bug above?
Or do we even want to support applying zero-context patches? If not, we
should detect and fail such attempts.
Clemens
git-gui/lib/diff.tcl | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index 52b79e4..78c1b56 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -302,12 +302,15 @@ proc read_diff {fd scroll_pos} {
proc apply_hunk {x y} {
global current_diff_path current_diff_header current_diff_side
- global ui_diff ui_index file_states
+ global ui_diff ui_index file_states repo_config
if {$current_diff_path eq {} || $current_diff_header eq {}} return
if {![lock_index apply_hunk]} return
set apply_cmd {apply --cached --whitespace=nowarn}
+ if {$repo_config(gui.diffcontext) eq 0} {
+ lappend apply_cmd --unidiff-zero
+ }
set mi [lindex $file_states($current_diff_path) 0]
if {$current_diff_side eq $ui_index} {
set failed_msg [mc "Failed to unstage selected hunk."]
@@ -375,12 +378,15 @@ proc apply_hunk {x y} {
proc apply_line {x y} {
global current_diff_path current_diff_header current_diff_side
- global ui_diff ui_index file_states
+ global ui_diff ui_index file_states repo_config
if {$current_diff_path eq {} || $current_diff_header eq {}} return
if {![lock_index apply_hunk]} return
set apply_cmd {apply --cached --whitespace=nowarn}
+ if {$repo_config(gui.diffcontext) eq 0} {
+ lappend apply_cmd --unidiff-zero
+ }
set mi [lindex $file_states($current_diff_path) 0]
if {$current_diff_side eq $ui_index} {
set failed_msg [mc "Failed to unstage selected line."]
--
1.6.0
next prev parent reply other threads:[~2008-08-30 17:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-30 16:45 [PATCH] git gui: show diffs with a minimum of 1 context line Clemens Buchacher
2008-08-30 16:56 ` Clemens Buchacher [this message]
2008-08-30 17:53 ` [PATCH] git gui: use apply --unidiff-zero when staging hunks without context Junio C Hamano
2008-08-30 19:03 ` [PATCH] git apply: do not match beginning in special unidiff-zero case Clemens Buchacher
2008-08-30 19:54 ` Junio C Hamano
2008-08-30 19:40 ` [PATCH] git-apply: Loosen "match_beginning" logic Junio C Hamano
2008-08-30 19:43 ` [PATCH] git gui: use apply --unidiff-zero when staging hunks without context Johannes Sixt
2008-08-30 20:27 ` Clemens Buchacher
2008-08-30 20:52 ` Junio C Hamano
2008-08-30 21:00 ` Clemens Buchacher
2008-09-01 19:40 ` Shawn O. Pearce
2008-08-30 17:19 ` [PATCH] git gui: show diffs with a minimum of 1 context line Junio C Hamano
2008-08-30 17:30 ` Junio C Hamano
2008-08-30 20:46 ` Clemens Buchacher
2008-09-01 19:33 ` Shawn O. Pearce
2008-09-01 19:41 ` Clemens Buchacher
2008-09-01 19:47 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080830165600.GB25370@localhost \
--to=drizzd@aon.at \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.