Created
March 17, 2009 17:01
-
-
Save MikeRalphson/80650 to your computer and use it in GitHub Desktop.
Partial patch to 'git diff as a better diff' to cope with common d/f case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/diff-no-index.c b/diff-no-index.c | |
index 598687b..6546975 100644 | |
--- a/diff-no-index.c | |
+++ b/diff-no-index.c | |
@@ -54,11 +54,34 @@ static int get_mode(const char *path, int *mode) | |
static int queue_diff(struct diff_options *o, | |
const char *name1, const char *name2) | |
{ | |
- int mode1 = 0, mode2 = 0; | |
+ int mode1 = 0, mode2 = 0, mode3 = 0; | |
+ struct strbuf tmpsb = STRBUF_INIT; | |
if (get_mode(name1, &mode1) || get_mode(name2, &mode2)) | |
return -1; | |
+ if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) { | |
+ if (S_ISDIR(mode1)) { | |
+ strbuf_addstr(&tmpsb, name1); | |
+ strbuf_addch(&tmpsb, '/'); | |
+ strbuf_addstr(&tmpsb, name2); | |
+ if (!get_mode(tmpsb.buf, &mode3) && !S_ISDIR(mode3)) { | |
+ mode1 = mode3; | |
+ name1 = tmpsb.buf; | |
+ } | |
+ } | |
+ else { | |
+ strbuf_addstr(&tmpsb, name2); | |
+ strbuf_addch(&tmpsb, '/'); | |
+ strbuf_addstr(&tmpsb, name1); | |
+ if (!get_mode(tmpsb.buf, &mode3) && !S_ISDIR(mode3)) { | |
+ mode2 = mode3; | |
+ name2 = tmpsb.buf; | |
+ } | |
+ } | |
+ /* strbuf_release(&tmpsb); */ | |
+ } | |
+ | |
if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) | |
return error("file/directory conflict: %s, %s", name1, name2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment