From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] Add -r flag to show-diff for diff-cache/diff-tree like output.
Date: Tue, 26 Apr 2005 15:27:09 -0700 [thread overview]
Message-ID: <7vy8b5mawy.fsf_-_@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.58.0504251832480.18901@ppc970.osdl.org> (Linus Torvalds's message of "Mon, 25 Apr 2005 18:38:05 -0700 (PDT)")
This adds a new option -r (rational) to show-diff command, to
produce diff-cache/diff-tree compatible output. When -r is
specified, show-diff simply skips unmerged entries. This makes
the following thee behave quite similarly:
show-diff -r -z
diff-cache -r -z [--cached] <tree-or-commit>
diff-tree -r -z <tree-or-commit> <tree-or-commit>
When -z (machine readable) is used, it implies rational. In
addition to terminating each output record with NUL instead of
'\n', machine readable format also may output lines of the form:
U filename <NUL>
to show that there are unmerged entries, once per path (this is
to help scripts so that they do not have to run "sed | uniq" on
output from "show-files --unmerged", just to get the list of
unmerged files).
The earlier machine readable output format had another form:
X filename <NUL>
to show deleted files. This has been removed; these paths now
give the diff-cache compatible "-<mode> <sha1> <path>" output.
I resisted the temptation to change those tabs between columns
into spaces. Linus, what do you think? I do not think Cogito
cares and changing them into spaces would certainly make them
more readable by humans.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
show-diff.c | 44 +++++++++++++++++++++++++++++++++-----------
1 files changed, 33 insertions(+), 11 deletions(-)
--- k/show-diff.c
+++ l/show-diff.c
@@ -6,7 +6,8 @@
#include "cache.h"
#include "diff.h"
-static const char *show_diff_usage = "show-diff [-q] [-s] [-z] [paths...]";
+static const char *show_diff_usage =
+"show-diff [-q] [-s] [-r] [-z] [paths...]";
static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
{
@@ -23,10 +24,17 @@ static int matches_pathspec(struct cache
return 0;
}
+static void show_file(int pfx, struct cache_entry *ce, int NUL_terminate)
+{
+ printf("%c%o\t%s\t%s\t%s%c", pfx, ntohl(ce->ce_mode), "blob",
+ sha1_to_hex(ce->sha1), ce->name, NUL_terminate ? 0 : '\n');
+}
+
int main(int argc, char **argv)
{
int silent = 0;
int silent_on_nonexisting_files = 0;
+ int rational = 0;
int machine_readable = 0;
int reverse = 0;
int entries = read_cache();
@@ -39,8 +47,12 @@ int main(int argc, char **argv)
silent_on_nonexisting_files = silent = 1;
else if (!strcmp(argv[1], "-q"))
silent_on_nonexisting_files = 1;
+ else if (!strcmp(argv[1], "-r"))
+ /* diff-cache and diff-tree compatible */
+ rational = 1;
else if (!strcmp(argv[1], "-z"))
- machine_readable = 1;
+ /* machine readable implies rational */
+ rational = machine_readable = 1;
else
usage(show_diff_usage);
argv++; argc--;
@@ -64,11 +76,16 @@ int main(int argc, char **argv)
continue;
if (ce_stage(ce)) {
+ /* machine-readble == rational in most cases,
+ * but rational does not care about unmerged.
+ * In some cases we want the list of unmerged
+ * files and running sort -u on show-files -z
+ * --unmerged for that is a pain.
+ */
if (machine_readable)
printf("U %s%c", ce->name, 0);
- else
- printf("%s: Unmerged\n",
- ce->name);
+ else if (!rational)
+ printf("%s: unmerged\n", ce->name);
while (i < entries &&
!strcmp(ce->name, active_cache[i]->name))
i++;
@@ -79,8 +96,10 @@ int main(int argc, char **argv)
if (stat(ce->name, &st) < 0) {
if (errno == ENOENT && silent_on_nonexisting_files)
continue;
- if (machine_readable)
- printf("X %s%c", ce->name, 0);
+ if (rational) {
+ /* deleted */
+ show_file('-', ce, machine_readable);
+ }
else {
printf("%s: %s\n", ce->name, strerror(errno));
if (errno == ENOENT)
@@ -91,10 +110,13 @@ int main(int argc, char **argv)
changed = cache_match_stat(ce, &st);
if (!changed)
continue;
- if (!machine_readable)
- printf("%s: %s\n", ce->name, sha1_to_hex(ce->sha1));
- else {
- printf("%s %s%c", sha1_to_hex(ce->sha1), ce->name, 0);
+ if (rational) {
+ static char *no_sha1_hex =
+ "0000000000000000000000000000000000000000";
+ printf("*%o->%o\t%s\t%s->%s\t%s%c",
+ ntohl(ce->ce_mode), st.st_mode,
+ "blob", sha1_to_hex(ce->sha1), no_sha1_hex,
+ ce->name, (machine_readable ? 0 : '\n'));
continue;
}
if (silent)
next prev parent reply other threads:[~2005-04-26 22:22 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1113400651.20848.135.camel@hades.cambridge.redhat.com>
2005-04-24 5:09 ` [GIT PATCH] Selective diff-tree Linus Torvalds
2005-04-24 6:25 ` David Woodhouse
2005-04-24 17:15 ` Linus Torvalds
2005-04-24 7:40 ` Junio C Hamano
2005-04-24 17:20 ` Linus Torvalds
2005-04-25 5:12 ` [PATCH 0/2] diff-tree/diff-cache helper Junio C Hamano
2005-04-25 5:15 ` [PATCH 1/2] Split external diff command interface to a separate file Junio C Hamano
2005-04-25 5:17 ` [PATCH 2/2] Introduce diff-tree-helper Junio C Hamano
2005-04-26 1:38 ` [PATCH 0/2] diff-tree/diff-cache helper Linus Torvalds
2005-04-26 2:08 ` Nicolas Pitre
2005-04-26 7:39 ` Junio C Hamano
2005-04-26 7:57 ` [PATCH] Diff-tree-helper take two Junio C Hamano
2005-04-26 22:27 ` Junio C Hamano [this message]
2005-04-26 22:40 ` [PATCH] Add -r flag to show-diff for diff-cache/diff-tree like output Linus Torvalds
2005-04-26 23:05 ` Junio C Hamano
2005-04-26 23:44 ` Linus Torvalds
2005-04-27 0:05 ` Junio C Hamano
2005-04-27 0:22 ` Linus Torvalds
2005-04-26 23:45 ` [PATCH] diff-cache/tree compatible output for show-diff (take 2) Junio C Hamano
2005-04-27 0:20 ` Linus Torvalds
2005-04-27 0:29 ` Linus Torvalds
[not found] ` <Pine.LNX.4.58.0504261750030.18901@ppc970.osdl.org>
2005-04-27 1:09 ` Linus Torvalds
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vy8b5mawy.fsf_-_@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).