git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] reset: Libify reset_index_file and print_new_head_line

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 10, 2011, 10:35 UTC
Message-ID
<20110610103532.GA32119@elie>
In-Reply-To
<1307546728-11202-1-git-send-email-artagnon@gmail.com>
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.

Show 12 quoted lines
> --- /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?
Show 7 quoted lines
> --- /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.

Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 2 of 4 in “reset: Libify reset_index_file and print_new_head_line”
  1. reset: Libify reset_index_file and print_new_head_lineRamkumar Ramachandra, Jun 8, 2011
  2. Jonathan NiederJun 10, 2011
  3. Ramkumar RamachandraJun 11, 2011
  4. reset: Libify reset_index_file and print_new_head_lineRamkumar Ramachandra, Jun 11, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.