Postgres recursive CTE on single table

Or is it even better to write an IMMUTABLE FUNCTION?

My git_commit table is append-only as Git objects are never changed. The function will always return the same ancestor tree for a specific oid.