Re: diff-patch: Avoid emitting double-slashes in textual patch.
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Feb 23, 2007, 16:07 UTC
- Message-ID
- <Pine.LNX.4.63.0702231705370.22628@wbgn013.biozentrum.uni-wuerzburg.de>
- In-Reply-To
- <7vmz353xpd.fsf@assigned-by-dhcp.cox.net>
Hi,
On Fri, 23 Feb 2007, Junio C Hamano wrote:
> - a_one = quote_two("a/", name_a);
> - b_two = quote_two("b/", name_b);
> + a_one = quote_two("a/", name_a + (*name_a == '/'));
> + b_two = quote_two("b/", name_b + (*name_b == '/'));I briefly thought about something like this instead:
- a_one = quote_two("a/", name_a + (*name_a == '/'));
- b_two = quote_two("b/", name_b + (*name_b == '/'));
+ a_one = quote_two(*name_a == '/' ? "" : "a/", name_a);
+ b_two = quote_two(*name_b == '/' ? "" : "b/", name_b);
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
- printf("%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
+ printf("%sdiff %s%s %s%s\n", set, *name_a == '/' || *name_b == '/' ?
+ "" : "--git ", a_one, b_two, reset);but I think your approach is better.
Ciao, Dscho