From: Junio C Hamano Date: Wed, 20 Sep 2006 15:53:12 GMT Subject: Re: [PATCH] cvsimport move over to using git for each ref to read refs Message-ID: <7vodtak00n.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <4511173D.7020702@shadowen.org> Andy Whitcroft writes: > I guess we could teach for-each-ref to output this as well? Perhaps > something like authorstamp? I think you can work with "author" or "committer" to grab the whole raw line. About the quoting and parsing, language specific quoting mode is meant for git-for-each-ref to produce a string that can be eval'ed in the host language. Think of the command as a tool to write a short program for you. The original is like this: # Get the last import timestamps opendir(D,"$git_dir/refs/heads"); while(defined(my $head = readdir(D))) { next if $head =~ /^\./; open(F,"$git_dir/refs/heads/$head") or die "Bad head branch: $head: $!\n"; chomp(my $ftag = ); close(F); open(F,"git-cat-file commit $ftag |"); while() { next unless /^author\s.*\s(\d+)\s[-+]\d{4}$/; $branch_date{$head} = $1; last; } close(F); } closedir(D); The purpose of the loop is to grab all branch heads, and grab author timestamp for all of them, _and_ stash that in %branch_date hash indexed by head name. You would want to have something like this executed for each branch: $refname = %(refname); $authorline = %(author); $authorline =~ /^author\s.*\s(\d+)\s[-+]\d{4}$/; $branch_date{$refname} = $1; So, you have the tool to write such a program for you, by doing something like this: my $template = ' $refname = %(refname); $authorline = %(author); $authorline =~ /^author\s.*\s(\d+)\s[-+]\d{4}$/; $branch_date{$refname} = $1; '; my @cmd = ('git-for-each-ref', '--perl', "--format=$template"); open I, '-|', @cmd, 'refs/heads'; my $script = join('',); close I; my ($refname, $authorline); eval "$script"; The language specific quoting flag --perl affects how %() are interpolated into the generated program text as literals. That's why there is no quote around %(refname) or %(author) in the example above when defining the $template.