From: Pieter de Bie <pdebie@ai.rug.nl>
To: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
"Shawn O. Pearce" <spearce@spearce.org>,
Git Mailinglist <git@vger.kernel.org>
Cc: Pieter de Bie <pdebie@ai.rug.nl>
Subject: [PATCH] builtin-name-rev: refactor stdin handling to its own function
Date: Fri, 1 Aug 2008 13:16:12 +0200 [thread overview]
Message-ID: <1217589372-4151-1-git-send-email-pdebie@ai.rug.nl> (raw)
In-Reply-To: <alpine.DEB.1.00.0808011256330.9611@pacific.mpi-cbg.de.mpi-cbg.de>
Signed-off-by: Pieter de Bie <pdebie@ai.rug.nl>
---
On 1 aug 2008, at 09:23, Junio C Hamano wrote:
>Is it just me to find that this part is getting indented too deeply to be
>readable?
How about something like this then?
builtin-name-rev.c | 93 ++++++++++++++++++++++++++++------------------------
1 files changed, 50 insertions(+), 43 deletions(-)
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 0536af4..057172d 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -176,6 +176,52 @@ static char const * const name_rev_usage[] = {
NULL
};
+static void handle_stdin_line(char *p_start, int name_only)
+{
+ int forty = 0;
+ char *p;
+ for (p = p_start; *p; p++) {
+#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
+ if (!ishex(*p))
+ forty = 0;
+ else if (++forty == 40 && !ishex(*(p+1))) {
+ unsigned char sha1[40];
+ const char *name = NULL;
+ char c = *(p+1);
+
+ forty = 0;
+
+ *(p+1) = 0;
+ if (!get_sha1(p - 39, sha1)) {
+ struct object *o =
+ lookup_object(sha1);
+ if (o)
+ name = get_rev_name(o);
+ }
+ *(p+1) = c;
+
+ if (!name)
+ continue;
+
+ if (name_only) {
+ fwrite(p_start, p - p_start + 1 - 40,
+ 1, stdout);sssss
+ printf(name);
+ }
+ else {
+ fwrite(p_start, p - p_start + 1, 1, stdout);
+ printf(" (%s)", name);
+ }
+ p_start = p + 1;
+ }
+ }
+
+ /* flush */
+ if (p != p_start)
+ fwrite(p_start, p - p_start, 1, stdout);
+
+}
+
int cmd_name_rev(int argc, const char **argv, const char *prefix)
{
struct object_array revs = { 0, 0, NULL };
@@ -234,53 +280,14 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
if (transform_stdin) {
char buffer[2048];
- char *p, *p_start;
+ char *p_start;
while (!feof(stdin)) {
- int forty = 0;
- p = fgets(buffer, sizeof(buffer), stdin);
- if (!p)
+ p_start = fgets(buffer, sizeof(buffer), stdin);
+ if (!p_start)
break;
- for (p_start = p; *p; p++) {
-#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
- if (!ishex(*p))
- forty = 0;
- else if (++forty == 40 &&
- !ishex(*(p+1))) {
- unsigned char sha1[40];
- const char *name = NULL;
- char c = *(p+1);
-
- forty = 0;
-
- *(p+1) = 0;
- if (!get_sha1(p - 39, sha1)) {
- struct object *o =
- lookup_object(sha1);
- if (o)
- name = get_rev_name(o);
- }
- *(p+1) = c;
-
- if (!name)
- continue;
-
- if (data.name_only) {
- fwrite(p_start, p - p_start + 1 - 40, 1, stdout);
- printf(name);
- }
- else {
- fwrite(p_start, p - p_start + 1, 1, stdout);
- printf(" (%s)", name);
- }
- p_start = p + 1;
- }
- }
-
- /* flush */
- if (p_start != p)
- fwrite(p_start, p - p_start, 1, stdout);
+ handle_stdin_line(p_start, data.name_only);
}
} else if (all) {
int i, max;
--
1.6.0.rc1.214.g5f0bd
next prev parent reply other threads:[~2008-08-01 11:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-31 13:20 [PATCH] git-name-rev: allow --name-only in combination with --stdin Pieter de Bie
2008-08-01 7:23 ` Junio C Hamano
2008-08-01 10:57 ` Johannes Schindelin
2008-08-01 11:16 ` Pieter de Bie [this message]
2008-08-01 19:07 ` [PATCH] builtin-name-rev: refactor stdin handling to its own function Junio C Hamano
2008-08-02 18:12 ` [PATCH] git-name-rev: allow --name-only in combination with --stdin Junio C Hamano
2008-08-03 13:44 ` [PATCH] git-name-rev: don't use printf without format René Scharfe
2008-08-03 20:44 ` Junio C Hamano
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=1217589372-4151-1-git-send-email-pdebie@ai.rug.nl \
--to=pdebie@ai.rug.nl \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--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 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).