Re: [PATCH 3/5] sequencer: sequencer state is useless without todo
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 16, 2011, 07:38 UTC
- Message-ID
- <7vhb24qzxy.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <CALkWK0kOrGzjcGNcf2qPahJSgkvCsQwSrEfAA3wj6PqnMzDBVQ@mail.gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
> I noticed that sha1_to_hex() also operates like this.
A function to externalize our internal representation like sha1_to_hex() is not such a big problem in practice, as the lifetime of its result is inherently much shorter.
Anybody sane with a datum that eventually needs to be externalized will keep it in its internal representation as long as possible, and then call such an internal-to-external function just before it becomes absolutely necessary to externalize it (e.g. calling printf(), packet_write(), etc). This is because the whole point of having an internal representation (e.g. when our code talks about an object name, we always use "unsigned char[20]") is so that all of our functions can use that representation to pass it around. It would be insane to call such a function earlier than necessary, having to pass external representation around.
On the other hand, resolve_ref() is an interface to canonicalize external representation into a form suitable to be kept and passed around as its internal representation. The lifetime of its result fundamentally has to be a lot longer than that of functions that work in the opposite direction, e.g. sha1_to_hex().