Subject: Re: [PATCH] reset: Libify reset_index_file and print_new_head_line

From: Jonathan Nieder <[email-masked]>
Date: Fri, 10 Jun 2011 05:35:32 -0500

Hi Ram,

Ramkumar Ramachandra wrote:

>  This patch lays the foundation for libifying reset by starting with
>  two "easy" methods.  I'll be using print_new_head_line in the
>  sequencer series while implementing --abort.

It should be easier to review this one with a caller in mind to give
an indication about whether the API is right.  More generally, the
excitement of patches exposing new library code comes when you can see
the header with a pleasant API, ideally followed by an example or two
to see how it plays out in practice.  See "git log --grep=API junio/pu"
for a few recent examples of this.

> --- /dev/null
> +++ b/reset.c
> @@ -0,0 +1,81 @@
> +#include "builtin.h"
> +#include "refs.h"
> +#include "diff.h"
> +#include "diffcore.h"
> +#include "tree.h"
> +#include "branch.h"
> +#include "tree.h"
> +#include "unpack-trees.h"
> +#include "reset.h"

Are these all needed?  E.g., where is diffcore used?

> --- /dev/null
> +++ b/reset.h
> @@ -0,0 +1,11 @@
> +#ifndef RESET_H
> +#define RESET_H
> +
> +#include "commit.h"

We can avoid unnecessarily rebuilding (if COMPUTE_HEADER_DEPENDENCIES
is set) for callers that do not use commit.h when commit.h changes by
just declaring

	struct commit;

Leaving out the declaration altogether would _almost_ work but the
declaration is needed for type in the function declaration and a later
definition of "struct commit" to refer to the same type.

Actually more important than the above is avoiding mutual dependencies
between header files, but the above makes for a more entertaining
story about why to avoid unnecessary #includes.

> +
> +enum reset_type { MIXED, SOFT, HARD, MERGE, KEEP, NONE };

The names of these identifiers (especially KEEP, MERGE, and NONE)
would have a good chance to colliding with other uses after being
exposed into a global namespace like this, no?

Maybe RESET_MIXED, RESET_SOFT, etc could avoid this while still not
being too verbose.

> +
> +int reset_index_file(const unsigned char *sha1, int reset_type, int quiet);
> +void print_new_head_line(struct commit *commit);

Warning: trivia ahead.

For some odd reason I still remember a patch from Stefan Beyer:
http://thread.gmane.org/gmane.comp.version-control.git/92023
which was probably too invasive to apply but made the whole codebase
oddly more pleasant when I tried it.  It simply added "extern" at the
start of function prototypes in header files that lacked it.

Sorry I don't have any more substantial comments on this one at the
moment.  Still, hope that helps.