[tools] improve recording latest commit id in gen-tarball.py