worktree.c: zero new 'struct worktree' on allocation

This keeps things a bit simpler when we add more fields, knowing that default values are always zero. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Nov 22, 2016 at 17:00 UTC f054996d8370c3213f8c8cbde908545ba6c0f854
1 file changed +2 -12
worktree.c
+2 -12
@@ -91,16 +91,11 @@ static struct worktree *get_main_worktree(void)
91 if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
92 goto done;
93
94 - worktree = xmalloc(sizeof(struct worktree));
94 + worktree = xcalloc(1, sizeof(*worktree));
95 worktree->path = strbuf_detach(&worktree_path, NULL);
96 - worktree->id = NULL;
96 worktree->is_bare = is_bare;
98 - worktree->head_ref = NULL;
97 worktree->is_detached = is_detached;
100 - worktree->is_current = 0;
98 add_head_info(&head_ref, worktree);
102 - worktree->lock_reason = NULL;
103 - worktree->lock_reason_valid = 0;
99
100 done:
101 strbuf_release(&path);
@@ -138,16 +133,11 @@ static struct worktree *get_linked_worktree(const char *id)
133 if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
134 goto done;
135
141 - worktree = xmalloc(sizeof(struct worktree));
136 + worktree = xcalloc(1, sizeof(*worktree));
137 worktree->path = strbuf_detach(&worktree_path, NULL);
138 worktree->id = xstrdup(id);
144 - worktree->is_bare = 0;
145 - worktree->head_ref = NULL;
139 worktree->is_detached = is_detached;
147 - worktree->is_current = 0;
140 add_head_info(&head_ref, worktree);
149 - worktree->lock_reason = NULL;
150 - worktree->lock_reason_valid = 0;
141
142 done:
143 strbuf_release(&path);