Skip to content

Commit

Permalink
standardize brace placement in struct definitions
Browse files Browse the repository at this point in the history
In a struct definitions, unlike functions, the prevailing style is for
the opening brace to go on the same line as the struct name, like so:

 struct foo {
	int bar;
	char *baz;
 };

Indeed, grepping for 'struct [a-z_]* {$' yields about 5 times as many
matches as 'struct [a-z_]*$'.

Linus sayeth:

 Heretic people all over the world have claimed that this inconsistency
 is ...  well ...  inconsistent, but all right-thinking people know that
 (a) K&R are _right_ and (b) K&R are right.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Mar 16, 2011
1 parent c6c8d0b commit 9cba13c
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 88 deletions.
3 changes: 1 addition & 2 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ static const char * const builtin_add_usage[] = {
static int patch_interactive, add_interactive, edit_interactive;
static int take_worktree_changes;

struct update_callback_data
{
struct update_callback_data {
int flags;
int add_errors;
};
Expand Down
3 changes: 1 addition & 2 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,8 +1312,7 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
/*
* Information on commits, used for output.
*/
struct commit_info
{
struct commit_info {
const char *author;
const char *author_mail;
unsigned long author_time;
Expand Down
3 changes: 1 addition & 2 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ enum work_type {WORK_SHA1, WORK_FILE};
* threads. The producer adds struct work_items to 'todo' and the
* consumers pick work items from the same array.
*/
struct work_item
{
struct work_item {
enum work_type type;
char *name;

Expand Down
6 changes: 2 additions & 4 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
static const char index_pack_usage[] =
"git index-pack [-v] [-o <index-file>] [ --keep | --keep=<msg> ] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";

struct object_entry
{
struct object_entry {
struct pack_idx_entry idx;
unsigned long size;
unsigned int hdr_size;
Expand Down Expand Up @@ -44,8 +43,7 @@ struct base_data {
#define FLAG_LINK (1u<<20)
#define FLAG_CHECKED (1u<<21)

struct delta_entry
{
struct delta_entry {
union delta_base base;
int obj_no;
};
Expand Down
3 changes: 1 addition & 2 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ enum cmit_fmt {
CMIT_FMT_UNSPECIFIED
};

struct pretty_print_context
{
struct pretty_print_context {
int abbrev;
const char *subject;
const char *after_subject;
Expand Down
3 changes: 1 addition & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ static int zlib_compression_seen;

const char *config_exclusive_filename = NULL;

struct config_item
{
struct config_item {
struct config_item *next;
char *name;
char *value;
Expand Down
6 changes: 2 additions & 4 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,16 +606,14 @@ static void diff_words_append(char *line, unsigned long len,
buffer->text.ptr[buffer->text.size] = '\0';
}

struct diff_words_style_elem
{
struct diff_words_style_elem {
const char *prefix;
const char *suffix;
const char *color; /* NULL; filled in by the setup code if
* color is enabled */
};

struct diff_words_style
{
struct diff_words_style {
enum diff_words_type type;
struct diff_words_style_elem new, old, ctx;
const char *newline;
Expand Down
42 changes: 14 additions & 28 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,83 +166,72 @@ Format of STDIN stream:
#define DEPTH_BITS 13
#define MAX_DEPTH ((1<<DEPTH_BITS)-1)

struct object_entry
{
struct object_entry {
struct pack_idx_entry idx;
struct object_entry *next;
uint32_t type : TYPE_BITS,
pack_id : PACK_ID_BITS,
depth : DEPTH_BITS;
};

struct object_entry_pool
{
struct object_entry_pool {
struct object_entry_pool *next_pool;
struct object_entry *next_free;
struct object_entry *end;
struct object_entry entries[FLEX_ARRAY]; /* more */
};

struct mark_set
{
struct mark_set {
union {
struct object_entry *marked[1024];
struct mark_set *sets[1024];
} data;
unsigned int shift;
};

struct last_object
{
struct last_object {
struct strbuf data;
off_t offset;
unsigned int depth;
unsigned no_swap : 1;
};

struct mem_pool
{
struct mem_pool {
struct mem_pool *next_pool;
char *next_free;
char *end;
uintmax_t space[FLEX_ARRAY]; /* more */
};

struct atom_str
{
struct atom_str {
struct atom_str *next_atom;
unsigned short str_len;
char str_dat[FLEX_ARRAY]; /* more */
};

struct tree_content;
struct tree_entry
{
struct tree_entry {
struct tree_content *tree;
struct atom_str *name;
struct tree_entry_ms
{
struct tree_entry_ms {
uint16_t mode;
unsigned char sha1[20];
} versions[2];
};

struct tree_content
{
struct tree_content {
unsigned int entry_capacity; /* must match avail_tree_content */
unsigned int entry_count;
unsigned int delta_depth;
struct tree_entry *entries[FLEX_ARRAY]; /* more */
};

struct avail_tree_content
{
struct avail_tree_content {
unsigned int entry_capacity; /* must match tree_content */
struct avail_tree_content *next_avail;
};

struct branch
{
struct branch {
struct branch *table_next_branch;
struct branch *active_next_branch;
const char *name;
Expand All @@ -254,16 +243,14 @@ struct branch
unsigned char sha1[20];
};

struct tag
{
struct tag {
struct tag *next_tag;
const char *name;
unsigned int pack_id;
unsigned char sha1[20];
};

struct hash_list
{
struct hash_list {
struct hash_list *next;
unsigned char sha1[20];
};
Expand All @@ -274,8 +261,7 @@ typedef enum {
WHENSPEC_NOW
} whenspec_type;

struct recent_command
{
struct recent_command {
struct recent_command *prev;
struct recent_command *next;
char *buf;
Expand Down
3 changes: 1 addition & 2 deletions fetch-pack.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef FETCH_PACK_H
#define FETCH_PACK_H

struct fetch_pack_args
{
struct fetch_pack_args {
const char *uploadpack;
int unpacklimit;
int depth;
Expand Down
3 changes: 1 addition & 2 deletions generate-cmdlist.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh

echo "/* Automatically generated by $0 */
struct cmdname_help
{
struct cmdname_help {
char name[16];
char help[80];
};
Expand Down
15 changes: 5 additions & 10 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ static int helper_status;

static struct object_list *objects;

struct repo
{
struct repo {
char *url;
char *path;
int path_len;
Expand All @@ -108,8 +107,7 @@ enum transfer_state {
COMPLETE
};

struct transfer_request
{
struct transfer_request {
struct object *obj;
char *url;
char *dest;
Expand All @@ -127,17 +125,15 @@ struct transfer_request

static struct transfer_request *request_queue_head;

struct xml_ctx
{
struct xml_ctx {
char *name;
int len;
char *cdata;
void (*userFunc)(struct xml_ctx *ctx, int tag_closed);
void *userData;
};

struct remote_lock
{
struct remote_lock {
char *url;
char *owner;
char *token;
Expand All @@ -156,8 +152,7 @@ struct remote_lock
/* Flags that remote_ls passes to callback functions */
#define IS_DIR (1u << 0)

struct remote_ls_ctx
{
struct remote_ls_ctx {
char *path;
void (*userFunc)(struct remote_ls_ctx *ls);
void *userData;
Expand Down
6 changes: 2 additions & 4 deletions http-walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "walker.h"
#include "http.h"

struct alt_base
{
struct alt_base {
char *base;
int got_indices;
struct packed_git *packs;
Expand All @@ -18,8 +17,7 @@ enum object_request_state {
COMPLETE
};

struct object_request
{
struct object_request {
struct walker *walker;
unsigned char sha1[20];
struct alt_base *repo;
Expand Down
15 changes: 5 additions & 10 deletions http.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@
#define NO_CURL_IOCTL
#endif

struct slot_results
{
struct slot_results {
CURLcode curl_result;
long http_code;
};

struct active_request_slot
{
struct active_request_slot {
CURL *curl;
FILE *local;
int in_use;
Expand All @@ -62,8 +60,7 @@ struct active_request_slot
struct active_request_slot *next;
};

struct buffer
{
struct buffer {
struct strbuf buf;
size_t posn;
};
Expand Down Expand Up @@ -149,8 +146,7 @@ extern int http_fetch_ref(const char *base, struct ref *ref);
extern int http_get_info_packs(const char *base_url,
struct packed_git **packs_head);

struct http_pack_request
{
struct http_pack_request {
char *url;
struct packed_git *target;
struct packed_git **lst;
Expand All @@ -166,8 +162,7 @@ extern int finish_http_pack_request(struct http_pack_request *preq);
extern void release_http_pack_request(struct http_pack_request *preq);

/* Helpers for fetching object */
struct http_object_request
{
struct http_object_request {
char *url;
char tmpfile[PATH_MAX];
int localfile;
Expand Down
12 changes: 4 additions & 8 deletions merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ struct rename_df_conflict_info {
* Since we want to write the index eventually, we cannot reuse the index
* for these (temporary) data.
*/
struct stage_data
{
struct
{
struct stage_data {
struct {
unsigned mode;
unsigned char sha[20];
} stages[4];
Expand Down Expand Up @@ -403,8 +401,7 @@ static void make_room_for_directories_of_df_conflicts(struct merge_options *o,
}
}

struct rename
{
struct rename {
struct diff_filepair *pair;
struct stage_data *src_entry;
struct stage_data *dst_entry;
Expand Down Expand Up @@ -717,8 +714,7 @@ static void update_file(struct merge_options *o,

/* Low level file merging, update and removal */

struct merge_file_info
{
struct merge_file_info {
unsigned char sha[20];
unsigned mode;
unsigned clean:1,
Expand Down
3 changes: 1 addition & 2 deletions pack-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include "pack.h"
#include "pack-revindex.h"

struct idx_entry
{
struct idx_entry {
off_t offset;
const unsigned char *sha1;
unsigned int nr;
Expand Down
Loading

0 comments on commit 9cba13c

Please sign in to comment.