Re: [PATCH 1/4] gitweb: notes feature

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jakub Narebski
Date: Saturday, February 6, 2010 - 6:38 pm

On Sun, 7 Feb 2010, Jakub Narebski wrote:


FYI, here is how you can parse raw tree output from 'git cat-file --batch',
assuming that you have plain-ASCII filenames ('use bytes;' would probably
be needed):

-- 8< --
sub decode_tree {
	my $contents = shift;

	# ...

	while (my @entry = decode_tree_entry($contents)) {

		# ...

		my $len = tree_entry_len(@entry);
		contents = substr($contents, $len);
		last unless $contents;
	}

	# ...
}

sub tree_entry_len {
	my ($mode_str, $filename) = @_;

	# length of mode string + separator + 20 bytes of SHA-1
	# + length of filename (in bytes) + terminating NUL ('\0')
	length($mode_str)+1 + length($filename)+1 + 20;
}

sub decode_tree_entry {
	my $buf = shift;

	$buf =~ s/^([0-7]+) //;
	my ($mode_str) = $1;
	my ($filename, $sha1_str) = unpack('Z*H[40]', $buf);

	return ($mode_str, $filename, $sha1_str);
}
-- >8 --

-- 
Jakub Narebski
Poland
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/4] gitweb: preliminary notes support, Giuseppe Bilotta, (Thu Feb 4, 9:18 am)
[PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Thu Feb 4, 9:18 am)
[PATCH 2/4] gitweb: show notes in shortlog view, Giuseppe Bilotta, (Thu Feb 4, 9:18 am)
[PATCH 3/4] gitweb: show notes in log, Giuseppe Bilotta, (Thu Feb 4, 9:18 am)
[PATCH 4/4] gitweb: show notes in commit(diff) view, Giuseppe Bilotta, (Thu Feb 4, 9:18 am)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Thu Feb 4, 9:33 am)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Thu Feb 4, 9:46 am)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Thu Feb 4, 10:21 am)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Thu Feb 4, 1:08 pm)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Thu Feb 4, 2:03 pm)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Thu Feb 4, 2:07 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Thu Feb 4, 4:20 pm)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Thu Feb 4, 4:38 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Thu Feb 4, 5:44 pm)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Thu Feb 4, 5:55 pm)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Fri Feb 5, 1:42 am)
Re: [PATCH 1/4] gitweb: notes feature, Johan Herland, (Fri Feb 5, 3:36 am)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Fri Feb 5, 9:10 am)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Fri Feb 5, 2:31 pm)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Fri Feb 5, 3:31 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Fri Feb 5, 4:44 pm)
Re: [PATCH 2/4] gitweb: show notes in shortlog view, Jakub Narebski, (Fri Feb 5, 5:18 pm)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Sat Feb 6, 1:16 am)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Sat Feb 6, 2:02 am)
Re: [PATCH 2/4] gitweb: show notes in shortlog view, Giuseppe Bilotta, (Sat Feb 6, 2:24 am)
Re: [PATCH 3/4] gitweb: show notes in log, Jakub Narebski, (Sat Feb 6, 5:57 am)
Re: [PATCH 3/4] gitweb: show notes in log, Giuseppe Bilotta, (Sat Feb 6, 6:14 am)
Re: [PATCH 4/4] gitweb: show notes in commit(diff) view, Jakub Narebski, (Sat Feb 6, 6:16 am)
Re: [PATCH 4/4] gitweb: show notes in commit(diff) view, Giuseppe Bilotta, (Sat Feb 6, 7:15 am)
Re: [PATCH 4/4] gitweb: show notes in commit(diff) view, Jakub Narebski, (Sat Feb 6, 7:34 am)
Re: [PATCH 4/4] gitweb: show notes in commit(diff) view, Giuseppe Bilotta, (Sat Feb 6, 9:13 am)
Re: [PATCH 3/4] gitweb: show notes in log, Jakub Narebski, (Sat Feb 6, 2:47 pm)
Re: [PATCH 4/4] gitweb: show notes in commit(diff) view, Jakub Narebski, (Sat Feb 6, 2:50 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sat Feb 6, 3:14 pm)
Re: [PATCH 4/4] gitweb: show notes in commit(diff) view, Giuseppe Bilotta, (Sat Feb 6, 3:17 pm)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Sat Feb 6, 3:58 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sat Feb 6, 6:20 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sat Feb 6, 6:38 pm)
Re: [PATCH 1/4] gitweb: notes feature, Johan Herland, (Sat Feb 6, 6:48 pm)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Sun Feb 7, 3:57 am)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sun Feb 7, 4:08 am)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sun Feb 7, 4:11 am)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Sun Feb 7, 4:14 am)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sun Feb 7, 5:41 am)
Re: [PATCH 1/4] gitweb: notes feature, Junio C Hamano, (Sun Feb 7, 11:38 am)
Re: [PATCH 1/4] gitweb: notes feature, Giuseppe Bilotta, (Sun Feb 7, 1:11 pm)
Re: [PATCH 1/4] gitweb: notes feature, Jakub Narebski, (Sun Feb 7, 2:08 pm)