Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH 4/5] blame.c: move code to output metainfo into a separate function.
Date: Thu, 05 Oct 2006 14:06:42 -0700	[thread overview]
Message-ID: <7vbqoqcw0t.fsf@assigned-by-dhcp.cox.net> (raw)

This does not change any behaviour, but just separates out the
code to emit the initial part of the output of each line into a
separate function, since I'll be mucking with it further.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 blame.c |   76 +++++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/blame.c b/blame.c
index bf4a1a1..47471e8 100644
--- a/blame.c
+++ b/blame.c
@@ -750,6 +750,42 @@ static int find_orig_linenum(struct util
 	return 0;
 }
 
+static void emit_meta(struct commit *c, int lno,
+		      int sha1_len, int compatibility,
+		      int show_name, int show_number, int show_raw_time,
+		      int longest_file, int longest_author,
+		      int max_digits, int max_orig_digits)
+{
+	struct util_info *u;
+	int lineno;
+	struct commit_info ci;
+
+	u = c->util;
+	lineno = find_orig_linenum(u, lno);
+
+	get_commit_info(c, &ci);
+	fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
+	if (compatibility) {
+		printf("\t(%10s\t%10s\t%d)", ci.author,
+		       format_time(ci.author_time, ci.author_tz,
+				   show_raw_time),
+		       lno + 1);
+	}
+	else {
+		if (show_name)
+			printf(" %-*.*s", longest_file, longest_file,
+			       u->pathname);
+		if (show_number)
+			printf(" %*d", max_orig_digits,
+			       lineno);
+		printf(" (%-*.*s %10s %*d) ",
+		       longest_author, longest_author, ci.author,
+		       format_time(ci.author_time, ci.author_tz,
+				   show_raw_time),
+		       max_digits, lno + 1);
+	}
+}
+
 int main(int argc, const char **argv)
 {
 	int i;
@@ -877,6 +913,10 @@ int main(int argc, const char **argv)
 	prepare_revision_walk(&rev);
 	process_commits(&rev, filename, &initial);
 
+	for (i = 0; i < num_blame_lines; i++)
+		if (!blame_lines[i])
+			blame_lines[i] = initial;
+
 	buf = blame_contents;
 	max_digits = lineno_width(num_blame_lines);
 
@@ -886,8 +926,6 @@ int main(int argc, const char **argv)
 	for (i = 0; i < num_blame_lines; i++) {
 		struct commit *c = blame_lines[i];
 		struct util_info *u;
-		if (!c)
-			c = initial;
 		u = c->util;
 
 		if (!show_name && strcmp(filename, u->pathname))
@@ -904,35 +942,11 @@ int main(int argc, const char **argv)
 	max_orig_digits = lineno_width(longest_file_lines);
 
 	for (i = 0; i < num_blame_lines; i++) {
-		struct commit *c = blame_lines[i];
-		struct util_info *u;
-		int lineno;
-		if (!c)
-			c = initial;
-		u = c->util;
-		lineno = find_orig_linenum(u, i);
-
-		get_commit_info(c, &ci);
-		fwrite(sha1_to_hex(c->object.sha1), sha1_len, 1, stdout);
-		if (compatibility) {
-			printf("\t(%10s\t%10s\t%d)", ci.author,
-			       format_time(ci.author_time, ci.author_tz,
-					   show_raw_time),
-			       i+1);
-		}
-		else {
-			if (show_name)
-				printf(" %-*.*s", longest_file, longest_file,
-				       u->pathname);
-			if (show_number)
-				printf(" %*d", max_orig_digits,
-				       lineno);
-			printf(" (%-*.*s %10s %*d) ",
-			       longest_author, longest_author, ci.author,
-			       format_time(ci.author_time, ci.author_tz,
-					   show_raw_time),
-			       max_digits, i+1);
-		}
+		emit_meta(blame_lines[i], i,
+			  sha1_len, compatibility,
+			  show_name, show_number, show_raw_time,
+			  longest_file, longest_author,
+			  max_digits, max_orig_digits);
 
 		if (i == num_blame_lines - 1) {
 			fwrite(buf, blame_len - (buf - blame_contents),
-- 
1.4.2.3.g866f3

                 reply	other threads:[~2006-10-05 21:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=7vbqoqcw0t.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --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