reset: Libify reset_index_file and print_new_head_line
PATCH 1/1 reset: Libify reset_index_file and print_new_head_line
Move the two methods from builtin/reset.c to reset.c, create a reset.h to expose them, and notify the Makefile about these two new files. No behavior change has been introduced.
---
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.
Makefile | 2 + builtin/reset.c | 74 +------------------------------------------------- reset.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ reset.h | 11 +++++++ 4 files changed, 95 insertions(+), 73 deletions(-) create mode 100644 reset.c create mode 100644 reset.h
Makefile +2 -0
@@ -548,6 +548,7 @@ LIB_H += reflog-walk.h LIB_H += refs.h LIB_H += remote.h LIB_H += rerere.h +LIB_H += reset.h LIB_H += resolve-undo.h LIB_H += revision.h LIB_H += run-command.h
@@ -649,6 +650,7 @@ LIB_OBJS += refs.o LIB_OBJS += remote.o LIB_OBJS += replace_object.o LIB_OBJS += rerere.o +LIB_OBJS += reset.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o LIB_OBJS += run-command.o
builtin/reset.c +1 -73
92 lines not on this page · raw message
reset.c new file +81 -0
81 lines not on this page · raw message
reset.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef RESET_H +#define RESET_H + +#include "commit.h" + +enum reset_type {MIXED ,SOFT ,HARD ,MERGE ,KEEP ,NONE }; + +int reset_index_file (const unsigned char *sha1,int reset_type,int quiet); +void print_new_head_line (struct commit *commit); + +#endif
Signature · 1 line
1.7.5.GIT
Hi Ram,
Quoted 3 lines · Ramkumar Ramachandra
This patch lays the foundation for libifying reset by starting with two "easy" methods. I'll be using
print_new_head_linein 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.
reset.c line 9
Quoted 12 lines
reset.c new file +9
-0@@ -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?
reset.h line 4
Quoted 7 lines
reset.h new file +4
-0@@ -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.
reset.h line 6
Quoted 2 lines
reset.h new file +2
-0+ +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.
reset.h line 9
Quoted 3 lines
reset.h new file +3
-0+ +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.
PATCH v2 1/1 reset: Libify reset_index_file and print_new_head_line
Move the two methods from builtin/reset.c to reset.c, create a reset.h to expose them, and notify the Makefile about these two new files. No behavior change has been introduced.
--- Makefile | 2 + builtin/reset.c | 114 ++++++++++-------------------------------------------- reset.c | 76 ++++++++++++++++++++++++++++++++++++ reset.h | 11 +++++ 4 files changed, 110 insertions(+), 93 deletions(-) create mode 100644 reset.c create mode 100644 reset.h
Makefile +2 -0
@@ -548,6 +548,7 @@ LIB_H += reflog-walk.h LIB_H += refs.h LIB_H += remote.h LIB_H += rerere.h +LIB_H += reset.h LIB_H += resolve-undo.h LIB_H += revision.h LIB_H += run-command.h
@@ -649,6 +650,7 @@ LIB_OBJS += refs.o LIB_OBJS += remote.o LIB_OBJS += replace_object.o LIB_OBJS += rerere.o +LIB_OBJS += reset.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o LIB_OBJS += run-command.o
builtin/reset.c +21 -93
189 lines not on this page · raw message
reset.c new file +76 -0
76 lines not on this page · raw message
reset.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef RESET_H +#define RESET_H + +struct commit ; +enum reset_type {RESET_MIXED ,RESET_SOFT ,RESET_HARD ,RESET_MERGE , +RESET_KEEP ,RESET_NONE }; + +extern int reset_index_file (const unsigned char *sha1,int reset_type,int quiet); +extern void print_new_head_line (struct commit *commit); + +#endif
Signature · 1 line
1.7.4.1
Hi Jonathan,
Quoted 6 lines · Jonathan Nieder
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.
Yes, I know. Unfortunately, I don't have those callers ready -- most of that work is in the form of RFC patches in the sequencer series. I wanted to post this in the same spirit as Junio's rerere series (which I initiated, but messed up quite badly).
Quoted 6 lines
Quoted 6 lines
reset.c new file +3
-0@@ -0,0 +1,81 @@ +#include "builtin.h" +#include "refs.h" +#include "diff.h"
Quoted 8 lines
reset.c line 9
Quoted 6 lines
reset.c new file +6
-0+#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?
Pruned, thanks.
Quoted 12 lines
reset.h line 4
Quoted 7 lines
reset.h new file +4
-0@@ -0,0 +1,11 @@ +#ifndef RESET_H +#define RESET_H + +#include "commit.h" We can avoid unnecessarily rebuilding (if
COMPUTE_HEADER_DEPENDENCIESis set) for callers that do not usecommit.hwhencommit.hchanges by just declaring
Quoted 1 line
struct commit;
Thanks for the tip.
Quoted 8 lines
reset.h line 6
Quoted 1 line
reset.h new file +1
-0+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.
I should have got this right the first time. Anyway, fixed now.
Quoted 10 lines
reset.h line 9
Quoted 2 lines
reset.h new file +2
-0+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.
Good tip. We can atleast use "extern" for the new functions that we write to avoid massive code churns.
Your review has been very helpful, as always. Thanks.
-- Ram