git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] contacts: validate hunk length earlier

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 9, 2013, 21:39 UTC
Message-ID
<1376084396-53617-2-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1376084396-53617-1-git-send-email-sunshine@sunshineco.com>

Rather than calling get_blame() with a zero-length hunk only to have it rejected immediately, perform hunk-length validation earlier in order to avoid calling get_blame() unnecessarily.

This is a preparatory step to simplify later patches which reduce the number of git-blame invocations by collecting together all lines to blame within a single file at a particular revision. By validating the blame range early, the subsequent patch can more easily avoid adding empty ranges at collection time.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 contrib/contacts/git-contacts | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
index d80f7d1..4fbb2ef 100755
--- a/contrib/contacts/git-contacts
+++ b/contrib/contacts/git-contacts
@@ -60,8 +60,6 @@ sub import_commits {
 
 sub get_blame {
 	my ($commits, $source, $start, $len, $from) = @_;
-	$len = 1 unless defined($len);
-	return if $len == 0;
 	open my $f, '-|',
 		qw(git blame --porcelain -C), '-L', "$start,+$len",
 		'--since', $since, "$from^", '--', $source or die;
@@ -90,7 +88,8 @@ sub scan_patches {
 		} elsif (/^--- /) {
 			die "Cannot parse hunk source: $_\n";
 		} elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
-			get_blame($commits, $source, $1, $2, $id);
+			my $len = defined($2) ? $2 : 1;
+			get_blame($commits, $source, $1, $len, $id) if $len;
 		}
 	}
 }
-- 
1.8.4.rc2.460.ga591f4a
Previous: Eric SunshineNext: Eric Sunshine
Message 2 of 5 in “optimize git-contacts”
  1. 0/3 optimize git-contactsEric Sunshine, Aug 9, 2013
  2. 1/3 contacts: validate hunk length earlierEric Sunshine, Aug 9, 2013
  3. 2/3 contacts: gather all blame sources prior to invoking git-blameEric Sunshine, Aug 9, 2013
  4. 3/3 contacts: reduce git-blame invocationsEric Sunshine, Aug 9, 2013
  5. Junio C HamanoAug 13, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.