Re: git and time
- From
Junio C Hamano <junkio@cox.net>
- Date
- Sep 28, 2006, 16:05 UTC
- Message-ID
- <7vodt0vux0.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <Pine.LNX.4.64.0609281029300.9349@xanadu.home>
Nicolas Pitre <nico@cam.org> writes:
Show 22 quoted lines
>> Nicolas Pitre <nico@cam.org> writes: >> >> > 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
donecase "$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