From: Yurii Shevtsov <ungetch@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH/RFC][GSoC] diff-no-index: transform "$directory $file" args to "$directory/$file $file"
Date: Sat, 21 Mar 2015 14:50:32 +0200 [thread overview]
Message-ID: <CAHLaBN+x3SVL9+jDzeSEMapVd2BVrwQuVx_7ENspjbUPrium_A@mail.gmail.com> (raw)
git diff --no-index refuses to compare if args are directory and file,
instead of usual diff.
Now git diff --no-index compares args' target names and, if they are
equal, refuses to compare. If args differ, it transforms args and
diffs files, as usual diff does.
This is the least expensive way in terms of amount of new code and
also doesn't affect usual behaviour.
Changes are done in queue_diff(). Adding args transformation logic to
top-level is irrational,
because requires writing additional code to define args' types, which
is already done in
queue_diff(). The error message about file\directory conflict left as
is until further guidence.
Signed-off-by: Yurii Shevtsov <ungetch@gmail.com>
---
diff-no-index.c | 35 +++++++++++++++++++++++++++++++++--
1 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 265709b..9a3439a 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -97,8 +97,39 @@ static int queue_diff(struct diff_options *o,
if (get_mode(name1, &mode1) || get_mode(name2, &mode2))
return -1;
- if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))
- return error("file/directory conflict: %s, %s", name1, name2);
+ if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) {
+ struct strbuf path;
+ const char *dir, *file;
+ char *filename, *dirname = 0;
+ int i, ret = 0;
+
+ dir = S_ISDIR(mode1) ? name1 : name2;
+ file = (dir == name1) ? name2 : name1;
+ strbuf_init(&path, strlen(name1) + strlen(name2) + 1);
+ strbuf_addstr(&path, dir);
+ filename = strrchr(file, '/');
+ if (path.len && path.buf[path.len - 1] != '/')
+ strbuf_addch(&path, '/');
+ for (i = path.len - 2; i >= 0; i--)
+ if (path.buf[i] == '/') {
+ dirname = &path.buf[i];
+ break;
+ }
+ if (dirname == 0)
+ dirname = path.buf;
+
+ if (!strncmp(dirname, filename, strlen(filename)))
+ return error("file/directory conflict: %s, %s", name1, name2);
+
+ strbuf_addstr(&path, filename ? (filename + 1) : file);
+ if (file == name1)
+ ret = queue_diff(o, file, path.buf);
+ else
+ ret = queue_diff(o, path.buf, file);
+ strbuf_release(&path);
+
+ return ret;
+ }
if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
struct strbuf buffer1 = STRBUF_INIT;
--
next reply other threads:[~2015-03-21 12:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-21 12:50 Yurii Shevtsov [this message]
2015-03-21 18:18 ` [PATCH/RFC][GSoC] diff-no-index: transform "$directory $file" args to "$directory/$file $file" Junio C Hamano
2015-03-21 19:08 ` Yurii Shevtsov
2015-03-22 2:39 ` Eric Sunshine
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=CAHLaBN+x3SVL9+jDzeSEMapVd2BVrwQuVx_7ENspjbUPrium_A@mail.gmail.com \
--to=ungetch@gmail.com \
--cc=git@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).