[RFC PATCH v2 2/2] headers: include dependent headers

2014-09-06 Thread David Aguilar
Add dependent headers so that including a header does not
require including additional headers.

This makes it so that "gcc -c $header" succeeds for each header.

Signed-off-by: David Aguilar 
---
Addresses René's note to not include strbuf.h when cache.h is already
included.

 archive.h| 1 +
 argv-array.h | 2 ++
 attr.h   | 2 ++
 branch.h | 2 ++
 cache-tree.h | 1 +
 color.h  | 3 ++-
 column.h | 2 ++
 commit.h | 1 +
 compat/bswap.h   | 7 +++
 compat/precompose_utf8.h | 8 +++-
 convert.h| 3 +++
 credential.h | 1 +
 csum-file.h  | 2 ++
 delta.h  | 2 ++
 diff.h   | 2 +-
 diffcore.h   | 2 ++
 dir.h| 2 ++
 ewah/ewok.h  | 2 ++
 ewah/ewok_rlw.h  | 2 ++
 exec_cmd.h   | 2 ++
 fsck.h   | 2 ++
 gpg-interface.h  | 2 ++
 graph.h  | 2 ++
 hashmap.h| 2 ++
 help.h   | 2 ++
 khash.h  | 3 +++
 kwset.h  | 2 ++
 line-log.h   | 1 +
 list-objects.h   | 2 ++
 ll-merge.h   | 2 ++
 mailmap.h| 3 +++
 merge-recursive.h| 2 ++
 notes-cache.h| 1 +
 notes-merge.h| 3 +++
 notes-utils.h| 1 +
 notes.h  | 1 +
 object.h | 2 ++
 pack-bitmap.h| 2 ++
 pack-objects.h   | 2 ++
 pack-revindex.h  | 2 ++
 parse-options.h  | 2 ++
 patch-ids.h  | 3 +++
 pathspec.h   | 2 ++
 progress.h   | 2 ++
 quote.h  | 3 ++-
 reachable.h  | 2 ++
 reflog-walk.h| 1 +
 refs.h   | 4 
 remote.h | 1 +
 resolve-undo.h   | 2 ++
 send-pack.h  | 4 
 sequencer.h  | 3 +++
 sha1-lookup.h| 2 ++
 shortlog.h   | 2 ++
 sideband.h   | 2 ++
 strbuf.h | 2 ++
 submodule.h  | 6 --
 tag.h| 1 +
 tree-walk.h  | 2 ++
 tree.h   | 1 +
 unicode_width.h  | 3 +++
 unpack-trees.h   | 2 ++
 url.h| 2 ++
 urlmatch.h   | 2 ++
 utf8.c   | 7 ---
 utf8.h   | 9 +
 vcs-svn/fast_export.h| 5 +++--
 vcs-svn/repo_tree.h  | 3 ++-
 vcs-svn/svndiff.h| 5 +++--
 wt-status.h  | 1 +
 xdiff/xdiffi.h   | 2 ++
 xdiff/xemit.h| 1 +
 xdiff/xprepare.h | 2 ++
 xdiff/xutils.h   | 2 ++
 74 files changed, 159 insertions(+), 22 deletions(-)

diff --git a/archive.h b/archive.h
index 4a791e1..b2ca5bf 100644
--- a/archive.h
+++ b/archive.h
@@ -1,6 +1,7 @@
 #ifndef ARCHIVE_H
 #define ARCHIVE_H
 
+#include "cache.h"
 #include "pathspec.h"
 
 struct archiver_args {
diff --git a/argv-array.h b/argv-array.h
index c65e6e8..7d877af 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -1,6 +1,8 @@
 #ifndef ARGV_ARRAY_H
 #define ARGV_ARRAY_H
 
+#include "git-compat-util.h"
+
 extern const char *empty_argv[];
 
 struct argv_array {
diff --git a/attr.h b/attr.h
index 8b08d33..34e63f8 100644
--- a/attr.h
+++ b/attr.h
@@ -1,6 +1,8 @@
 #ifndef ATTR_H
 #define ATTR_H
 
+#include "cache.h"
+
 /* An attribute is a pointer to this opaque structure */
 struct git_attr;
 
diff --git a/branch.h b/branch.h
index 64173ab..d5fdcc6 100644
--- a/branch.h
+++ b/branch.h
@@ -3,6 +3,8 @@
 
 /* Functions for acting on the information about branches. */
 
+#include "cache.h"
+
 /*
  * Creates a new branch, where head is the branch currently checked
  * out, name is the new branch name, start_name is the name of the
diff --git a/cache-tree.h b/cache-tree.h
index b47ccec..30b0775 100644
--- a/cache-tree.h
+++ b/cache-tree.h
@@ -3,6 +3,7 @@
 
 #include "tree.h"
 #include "tree-walk.h"
+#include "cache.h"
 
 struct cache_tree;
 struct cache_tree_sub {
diff --git a/color.h b/color.h
index 9a8495b..6b50a0f 100644
--- a/color.h
+++ b/color.h
@@ -1,7 +1,8 @@
 #ifndef COLOR_H
 #define COLOR_H
 
-struct strbuf;
+#include "git-compat-util.h"
+#include "strbuf.h"
 
 /*  2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */
 /* "\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\0" */
diff --git a/column.h b/column.h
index 0a61917..5d094b4 100644
--- a/column.h
+++ b/column.h
@@ -1,6 +1,8 @@
 #ifndef COLUMN_H
 #define COLUMN_H
 
+#include "string-list.h"
+
 #define COL_LAYOUT_MASK   0x000F
 #define COL_ENABLE_MASK   0x0030   /* always, never or auto */
 #define COL_PARSEOPT  0x0040   /* --column is given from cmdline */
diff --git a/commit.h b/commit.h
index aa8c3ca..1fe0731 100644
--- a/commit.h
+++ b/commit.h
@@ -7,6 +7,7 @@
 #include "decorate.h"
 #include "gpg-interface.h"
 #include "string-list.h"
+#include "cache.h"
 
 struct commit_list {
struct 

Re: [RFC PATCH v2 2/2] headers: include dependent headers

2014-09-06 Thread René Scharfe
Am 07.09.2014 um 02:30 schrieb David Aguilar:
> Add dependent headers so that including a header does not
> require including additional headers.
> 
> This makes it so that "gcc -c $header" succeeds for each header.
> 
> Signed-off-by: David Aguilar 
> ---
> Addresses René's note to not include strbuf.h when cache.h is already
> included.

Perhaps squash this in in order to catch two more cases and also
avoid including git-compat-util.h if we already have cache.h:

diff --git a/builtin.h b/builtin.h
index df40fce..0419af3 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,7 +1,6 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
-#include "git-compat-util.h"
 #include "cache.h"
 #include "commit.h"
 
diff --git a/commit.h b/commit.h
index 1fe0731..dddc876 100644
--- a/commit.h
+++ b/commit.h
@@ -3,7 +3,6 @@
 
 #include "object.h"
 #include "tree.h"
-#include "strbuf.h"
 #include "decorate.h"
 #include "gpg-interface.h"
 #include "string-list.h"
diff --git a/dir.h b/dir.h
index 727160e..6b1 100644
--- a/dir.h
+++ b/dir.h
@@ -3,7 +3,6 @@
 
 /* See Documentation/technical/api-directory-listing.txt */
 
-#include "strbuf.h"
 #include "pathspec.h"
 #include "cache.h"
 
diff --git a/khash.h b/khash.h
index 89f9579..fc8b1bf 100644
--- a/khash.h
+++ b/khash.h
@@ -26,7 +26,6 @@
 #ifndef __AC_KHASH_H
 #define __AC_KHASH_H
 
-#include "git-compat-util.h"
 #include "cache.h"
 
 #define AC_VERSION_KHASH_H "0.2.8"

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH v2 2/2] headers: include dependent headers

2014-09-07 Thread Jonathan Nieder
David Aguilar wrote:

> Add dependent headers so that including a header does not
> require including additional headers.

I agree with this goal, modulo the compat-util.h caveat.  Thanks
for working on it.

[...]
> --- a/archive.h
> +++ b/archive.h
> @@ -1,6 +1,7 @@
>  #ifndef ARCHIVE_H
>  #define ARCHIVE_H
>  
> +#include "cache.h"
>  #include "pathspec.h"
>  
>  struct archiver_args {

I'm less happy about the way of achieving that goal.  Here's an
alternative.  Advantages:

 * (fully expanded) headers stay small

 * fewer other headers included as a side-effect of including one
   header, so callers are more likely to remember to #include the
   headers defining things they need (which makes later refactoring
   easier)

 * circular header dependencies are harder to produce

If this seems like a good direction to go in, I can finish the patch
later today (or I don't mind if someone else takes care of it).  This
is just to give the idea --- I stopped at dir.h.

Sensible?
Jonathan

diff --git i/archive.h w/archive.h
index 4a791e1..11f4d42 100644
--- i/archive.h
+++ w/archive.h
@@ -3,6 +3,9 @@
 
 #include "pathspec.h"
 
+enum object_type;
+
+
 struct archiver_args {
const char *base;
size_t baselen;
diff --git i/attr.h w/attr.h
index 8b08d33..c971ef2 100644
--- i/attr.h
+++ w/attr.h
@@ -1,6 +1,8 @@
 #ifndef ATTR_H
 #define ATTR_H
 
+struct index_state;
+
 /* An attribute is a pointer to this opaque structure */
 struct git_attr;
 
diff --git i/branch.h w/branch.h
index 64173ab..ed63209 100644
--- i/branch.h
+++ w/branch.h
@@ -1,6 +1,9 @@
 #ifndef BRANCH_H
 #define BRANCH_H
 
+enum branch_track;
+struct strbuf;
+
 /* Functions for acting on the information about branches. */
 
 /*
diff --git i/cache-tree.h w/cache-tree.h
index b47ccec..c22e2ec 100644
--- i/cache-tree.h
+++ w/cache-tree.h
@@ -1,8 +1,12 @@
 #ifndef CACHE_TREE_H
 #define CACHE_TREE_H
 
-#include "tree.h"
-#include "tree-walk.h"
+struct traverse_info;
+struct index_state;
+struct name_entry;
+struct tree;
+struct string_list;
+struct strbuf;
 
 struct cache_tree;
 struct cache_tree_sub {
diff --git i/column.h w/column.h
index 0a61917..8211386 100644
--- i/column.h
+++ w/column.h
@@ -1,6 +1,9 @@
 #ifndef COLUMN_H
 #define COLUMN_H
 
+struct option;
+struct string_list;
+
 #define COL_LAYOUT_MASK   0x000F
 #define COL_ENABLE_MASK   0x0030   /* always, never or auto */
 #define COL_PARSEOPT  0x0040   /* --column is given from cmdline */
@@ -26,7 +29,6 @@ struct column_options {
const char *nl;
 };
 
-struct option;
 extern int parseopt_column_callback(const struct option *, const char *, int);
 extern int git_column_config(const char *var, const char *value,
 const char *command, unsigned int *colopts);
diff --git i/commit.h w/commit.h
index aa8c3ca..d2fd182 100644
--- i/commit.h
+++ w/commit.h
@@ -1,13 +1,18 @@
 #ifndef COMMIT_H
 #define COMMIT_H
 
+#include "cache.h"
 #include "object.h"
-#include "tree.h"
-#include "strbuf.h"
-#include "decorate.h"
-#include "gpg-interface.h"
+#include "trace.h"
 #include "string-list.h"
 
+struct reflog_walk_info;
+struct rev_info;
+struct ref;
+struct signature_check;
+struct sha1_array;
+struct strbuf;
+
 struct commit_list {
struct commit *item;
struct commit_list *next;
@@ -151,7 +156,6 @@ struct userformat_want {
 };
 
 extern int has_non_ascii(const char *text);
-struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
 extern const char *logmsg_reencode(const struct commit *commit,
   char **commit_encoding,
   const char *output_encoding);
@@ -231,8 +235,6 @@ extern struct commit_list *get_octopus_merge_bases(struct 
commit_list *in);
 /* largest positive number a signed 32-bit integer can contain */
 #define INFINITE_DEPTH 0x7fff
 
-struct sha1_array;
-struct ref;
 extern int register_shallow(const unsigned char *sha1);
 extern int unregister_shallow(const unsigned char *sha1);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
diff --git i/convert.h w/convert.h
index 0c2143c..e623527 100644
--- i/convert.h
+++ w/convert.h
@@ -4,6 +4,8 @@
 #ifndef CONVERT_H
 #define CONVERT_H
 
+struct strbuf;
+
 enum safe_crlf {
SAFE_CRLF_FALSE = 0,
SAFE_CRLF_FAIL = 1,
diff --git i/csum-file.h w/csum-file.h
index bb543d5..9e29e35 100644
--- i/csum-file.h
+++ w/csum-file.h
@@ -1,6 +1,8 @@
 #ifndef CSUM_FILE_H
 #define CSUM_FILE_H
 
+#include "cache.h"
+
 struct progress;
 
 /* A SHA1-protected file */
diff --git i/diffcore.h w/diffcore.h
index c876dac..96fc827 100644
--- i/diffcore.h
+++ w/diffcore.h
@@ -4,6 +4,9 @@
 #ifndef DIFFCORE_H
 #define DIFFCORE_H
 
+struct userdiff_driver;
+struct diff_options;
+
 /* This header file is internal between diff.c and its diff transformers
  * (e.g. diffcore-rename, diffcore-pickaxe).  Never include this header
  * in anything else.
@@ -22,8 +25,6 @@
 
 #define MINIMUM_BREAK_SIZE 400 /* do not 

Re: [RFC PATCH v2 2/2] headers: include dependent headers

2014-09-07 Thread Johannes Sixt
Am 07.09.2014 21:49, schrieb Jonathan Nieder:
> +enum object_type;

Enum forward declarations are a relatively new C feature. They certainly
don't exist pre-C99.

-- Hannes

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH v2 2/2] headers: include dependent headers

2014-09-07 Thread Jonathan Nieder
Johannes Sixt wrote:
> Am 07.09.2014 21:49, schrieb Jonathan Nieder:

>> +enum object_type;
>
> Enum forward declarations are a relatively new C feature. They certainly
> don't exist pre-C99.

Good catch.  That makes

diff --git i/archive.h w/archive.h
index 4a791e1..b2ca5bf 100644
--- i/archive.h
+++ w/archive.h
@@ -1,6 +1,7 @@
 #ifndef ARCHIVE_H
 #define ARCHIVE_H
 
+#include "cache.h"
 #include "pathspec.h"
 
 struct archiver_args {
diff --git i/attr.h w/attr.h
index 8b08d33..c971ef2 100644
--- i/attr.h
+++ w/attr.h
@@ -1,6 +1,8 @@
 #ifndef ATTR_H
 #define ATTR_H
 
+struct index_state;
+
 /* An attribute is a pointer to this opaque structure */
 struct git_attr;
 
diff --git i/branch.h w/branch.h
index 64173ab..5ce6e21 100644
--- i/branch.h
+++ w/branch.h
@@ -1,6 +1,8 @@
 #ifndef BRANCH_H
 #define BRANCH_H
 
+#include "cache.h"
+
 /* Functions for acting on the information about branches. */
 
 /*
diff --git i/cache-tree.h w/cache-tree.h
index b47ccec..c22e2ec 100644
--- i/cache-tree.h
+++ w/cache-tree.h
@@ -1,8 +1,12 @@
 #ifndef CACHE_TREE_H
 #define CACHE_TREE_H
 
-#include "tree.h"
-#include "tree-walk.h"
+struct traverse_info;
+struct index_state;
+struct name_entry;
+struct tree;
+struct string_list;
+struct strbuf;
 
 struct cache_tree;
 struct cache_tree_sub {
diff --git i/column.h w/column.h
index 0a61917..8211386 100644
--- i/column.h
+++ w/column.h
@@ -1,6 +1,9 @@
 #ifndef COLUMN_H
 #define COLUMN_H
 
+struct option;
+struct string_list;
+
 #define COL_LAYOUT_MASK   0x000F
 #define COL_ENABLE_MASK   0x0030   /* always, never or auto */
 #define COL_PARSEOPT  0x0040   /* --column is given from cmdline */
@@ -26,7 +29,6 @@ struct column_options {
const char *nl;
 };
 
-struct option;
 extern int parseopt_column_callback(const struct option *, const char *, int);
 extern int git_column_config(const char *var, const char *value,
 const char *command, unsigned int *colopts);
diff --git i/commit.h w/commit.h
index aa8c3ca..097fc9e 100644
--- i/commit.h
+++ w/commit.h
@@ -1,13 +1,17 @@
 #ifndef COMMIT_H
 #define COMMIT_H
 
+#include "cache.h"
 #include "object.h"
-#include "tree.h"
-#include "strbuf.h"
-#include "decorate.h"
-#include "gpg-interface.h"
+#include "trace.h"
 #include "string-list.h"
 
+struct reflog_walk_info;
+struct rev_info;
+struct ref;
+struct signature_check;
+struct sha1_array;
+
 struct commit_list {
struct commit *item;
struct commit_list *next;
@@ -151,7 +155,6 @@ struct userformat_want {
 };
 
 extern int has_non_ascii(const char *text);
-struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
 extern const char *logmsg_reencode(const struct commit *commit,
   char **commit_encoding,
   const char *output_encoding);
@@ -231,8 +234,6 @@ extern struct commit_list *get_octopus_merge_bases(struct 
commit_list *in);
 /* largest positive number a signed 32-bit integer can contain */
 #define INFINITE_DEPTH 0x7fff
 
-struct sha1_array;
-struct ref;
 extern int register_shallow(const unsigned char *sha1);
 extern int unregister_shallow(const unsigned char *sha1);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
diff --git i/convert.h w/convert.h
index 0c2143c..e623527 100644
--- i/convert.h
+++ w/convert.h
@@ -4,6 +4,8 @@
 #ifndef CONVERT_H
 #define CONVERT_H
 
+struct strbuf;
+
 enum safe_crlf {
SAFE_CRLF_FALSE = 0,
SAFE_CRLF_FAIL = 1,
diff --git i/csum-file.h w/csum-file.h
index bb543d5..9e29e35 100644
--- i/csum-file.h
+++ w/csum-file.h
@@ -1,6 +1,8 @@
 #ifndef CSUM_FILE_H
 #define CSUM_FILE_H
 
+#include "cache.h"
+
 struct progress;
 
 /* A SHA1-protected file */
diff --git i/diffcore.h w/diffcore.h
index c876dac..96fc827 100644
--- i/diffcore.h
+++ w/diffcore.h
@@ -4,6 +4,9 @@
 #ifndef DIFFCORE_H
 #define DIFFCORE_H
 
+struct userdiff_driver;
+struct diff_options;
+
 /* This header file is internal between diff.c and its diff transformers
  * (e.g. diffcore-rename, diffcore-pickaxe).  Never include this header
  * in anything else.
@@ -22,8 +25,6 @@
 
 #define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
 
-struct userdiff_driver;
-
 struct diff_filespec {
unsigned char sha1[20];
char *path;
diff --git i/object.h w/object.h
index 5e8d8ee..e61b290 100644
--- i/object.h
+++ w/object.h
@@ -1,6 +1,8 @@
 #ifndef OBJECT_H
 #define OBJECT_H
 
+#include "cache.h"
+
 struct object_list {
struct object *item;
struct object_list *next;
diff --git i/tree-walk.h w/tree-walk.h
index ae7fb3a..d7612cf 100644
--- i/tree-walk.h
+++ w/tree-walk.h
@@ -1,6 +1,8 @@
 #ifndef TREE_WALK_H
 #define TREE_WALK_H
 
+struct strbuf;
+
 struct name_entry {
const unsigned char *sha1;
const char *path;
diff --git i/tree.h w/tree.h
index d84ac63..ef84153 100644
--- i/tree.h
+++ w/tree.h
@@ -3,6 +3,9 @@
 
 #include "object.h"
 
+struct pathspec;
+
+
 extern const char *tr

Re: [RFC PATCH v2 2/2] headers: include dependent headers

2014-09-07 Thread David Aguilar
On Sun, Sep 07, 2014 at 12:49:18PM -0700, Jonathan Nieder wrote:
> David Aguilar wrote:
> 
> > Add dependent headers so that including a header does not
> > require including additional headers.
> 
> I agree with this goal, modulo the compat-util.h caveat.  Thanks
> for working on it.
> 
> [...]
> > --- a/archive.h
> > +++ b/archive.h
> > @@ -1,6 +1,7 @@
> >  #ifndef ARCHIVE_H
> >  #define ARCHIVE_H
> >  
> > +#include "cache.h"
> >  #include "pathspec.h"
> >  
> >  struct archiver_args {
> 
> I'm less happy about the way of achieving that goal.  Here's an
> alternative.  Advantages:
> 
>  * (fully expanded) headers stay small
> 
>  * fewer other headers included as a side-effect of including one
>header, so callers are more likely to remember to #include the
>headers defining things they need (which makes later refactoring
>easier)
> 
>  * circular header dependencies are harder to produce
> 
> If this seems like a good direction to go in, I can finish the patch
> later today

Yes, please, that would be sweet.

Would you mind squashing in your sug to patch 1/2 as well when resending?
It seems like a nice improvement all around.

RE: pre-compiled headers -- that might be a nice follow-up to
this series. I'm not very familiar with Windows so I don't know
if it would be doable on mingw, cygwin, and msvc et al. but if
it helps other platforms then it could be a nice feature.

Thanks Jonathan,
-- 
David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html