Thread (1 message) 1 message, 1 author, 2016-06-15
  • (off-list ancestor, not in this archive)
  • Re: git and time · Junio C Hamano <hidden> · 2016-06-15

Re: git and time

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:42

Nicolas Pitre [off-list ref] writes:
quoted
Nicolas Pitre [off-list ref] writes:
quoted
SYNOPSIS

	git-local-arrival <committish>

DESCRIPTION

	The command displays the time when given commit appeared in the 
	local repository.
This should be certainly doable, but local-arrival may not be
interesting if the repository has more than one branches.  Maybe

	git-local-arrival <committish> [<branch>]

which defaults to the current branch?
Indeed.  I didn't mention it initially because it is really easy to do 
once you have it working for the current branch.  The technical 
challenge is about making it efficient to find out which reflog entry 
with a path to given commit is the oldest.
Perhaps bisect it like this.  This assumes you never rewind the
branch in question and the tip already contains the commit in
question.

-- >8 --

#!/bin/sh

. git-sh-setup
commit=`git rev-parse "$1"` &&
branch="${2-`git symbolic-ref HEAD`} || exit

contains () {
	contains=`git merge-base --all $1 $commit`
	case "$LF$contains$LF" in
	*"$LF$contains$LF"*)
		: ;;
	*)
		false ;;
	esac
}

LF='
'
script='{
	s/	.*//
	p
}' ;# strip things after TAB if a TAB exists
reflog="$GIT_DIR/logs/refs/heads/$branch";
lo=1;
hi=`wc -l <$reflog`
ld=$hi
while expr "$lo" \< "$hi" >/dev/null
do
	mi=`expr \( $hi \+ $lo \) / 2`
	line=`sed -ne "$mi$script" "$reflog"`
	to=`expr "$line" : '[^ ]* \([^ ]*\) '`
	if contains $to
	then
		ld=$hi
		hi=$mi
	else
		lo=`expr "$mi" + 1`
	fi
done

case "$ld" in	
'')
	echo >&2 Oops
	exit 1;;
?*)	
	line=`sed -ne "$ld$script" "$reflog"`
	time=`expr "$line" : '.*> \([0-9]*\) '`
	zone=`expr "$line" : '.*> [0-9]* \(.[0-9][0-9][0-9][0-9]\)$'`
	echo "$time $zone"
esac
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help