Add typedefs for internal structs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
diff --git a/src/blame.c b/src/blame.c
index b7886aa..3b9d3db 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -221,7 +221,7 @@ static git_blame_hunk *split_hunk_in_vector(
* To allow quick access to the contents of nth line in the
* final image, prepare an index in the scoreboard.
*/
-static int prepare_lines(struct scoreboard *sb)
+static int prepare_lines(git_blame__scoreboard *sb)
{
const char *buf = sb->final_buf;
git_off_t len = sb->final_buf_size;
@@ -242,7 +242,7 @@ static int prepare_lines(struct scoreboard *sb)
return sb->num_lines;
}
-static git_blame_hunk* hunk_from_entry(struct blame_entry *e)
+static git_blame_hunk* hunk_from_entry(git_blame__entry *e)
{
git_blame_hunk *h = new_hunk(
e->lno+1, e->num_lines, e->s_lno+1, e->suspect->path);
@@ -255,10 +255,10 @@ static int walk_and_mark(git_blame *blame)
{
int error;
- struct scoreboard sb = {0};
- struct blame_entry *ent = NULL;
+ git_blame__scoreboard sb = {0};
+ git_blame__entry *ent = NULL;
git_blob *blob = NULL;
- struct origin *o;
+ git_blame__origin *o;
if ((error = git_commit_lookup(&sb.final, blame->repository, &blame->options.newest_commit)) < 0 ||
(error = git_object_lookup_bypath((git_object**)&blob, (git_object*)sb.final, blame->path, GIT_OBJ_BLOB)) < 0)
@@ -287,8 +287,8 @@ static int walk_and_mark(git_blame *blame)
cleanup:
for (ent = sb.ent; ent; ) {
- struct blame_entry *e = ent->next;
- struct origin *o = ent->suspect;
+ git_blame__entry *e = ent->next;
+ git_blame__origin *o = ent->suspect;
git_vector_insert(&blame->hunks, hunk_from_entry(ent));
diff --git a/src/blame_git.c b/src/blame_git.c
index 02628c4..8fd06da 100644
--- a/src/blame_git.c
+++ b/src/blame_git.c
@@ -11,13 +11,15 @@
/*
* Locate an existing origin or create a new one.
*/
-int get_origin(struct origin **out, struct scoreboard *sb, git_commit *commit, const char *path)
+int get_origin(git_blame__origin **out, git_blame__scoreboard *sb, git_commit *commit, const char *path)
{
- struct blame_entry *e;
+ git_blame__entry *e;
- for (e = sb->ent; e; e = e->next)
- if (e->suspect->commit == commit && !strcmp(e->suspect->path, path))
+ for (e = sb->ent; e; e = e->next) {
+ if (e->suspect->commit == commit && !strcmp(e->suspect->path, path)) {
*out = origin_incref(e->suspect);
+ }
+ }
return make_origin(out, commit, path);
}
@@ -27,10 +29,11 @@ int get_origin(struct origin **out, struct scoreboard *sb, git_commit *commit, c
* get_origin() to obtain shared, refcounted copy instead of calling
* this function directly.
*/
-int make_origin(struct origin **out, git_commit *commit, const char *path)
+int make_origin(git_blame__origin **out, git_commit *commit, const char *path)
{
int error = 0;
- struct origin *o;
+ git_blame__origin *o;
+
o = git__calloc(1, sizeof(*o) + strlen(path) + 1);
GITERR_CHECK_ALLOC(o);
o->commit = commit;
@@ -38,22 +41,23 @@ int make_origin(struct origin **out, git_commit *commit, const char *path)
strcpy(o->path, path);
if (!(error = git_object_lookup_bypath((git_object**)&o->blob, (git_object*)commit,
- path, GIT_OBJ_BLOB)))
+ path, GIT_OBJ_BLOB))) {
*out = o;
- else
+ } else {
origin_decref(o);
+ }
return error;
}
struct blame_chunk_cb_data {
- struct scoreboard *sb;
- struct origin *target;
- struct origin *parent;
- long plno;
+ git_blame__scoreboard *sb;
+ git_blame__origin *target;
+ git_blame__origin *parent;
long tlno;
+ long plno;
};
-static bool same_suspect(struct origin *a, struct origin *b)
+static bool same_suspect(git_blame__origin *a, git_blame__origin *b)
{
if (a == b)
return true;
@@ -63,9 +67,9 @@ static bool same_suspect(struct origin *a, struct origin *b)
}
/* Find the line number of the last line the target is suspected for */
-static int find_last_in_target(struct scoreboard *sb, struct origin *target)
+static int find_last_in_target(git_blame__scoreboard *sb, git_blame__origin *target)
{
- struct blame_entry *e;
+ git_blame__entry *e;
int last_in_target = -1;
for (e=sb->ent; e; e=e->next) {
@@ -91,8 +95,8 @@ static int find_last_in_target(struct scoreboard *sb, struct origin *target)
* Split e into potentially three parts; before this chunk, the chunk
* to be blamed for the parent, and after that portion.
*/
-static void split_overlap(struct blame_entry *split, struct blame_entry *e,
- int tlno, int plno, int same, struct origin *parent)
+static void split_overlap(git_blame__entry *split, git_blame__entry *e,
+ int tlno, int plno, int same, git_blame__origin *parent)
{
int chunk_end_lno;
@@ -134,9 +138,9 @@ static void split_overlap(struct blame_entry *split, struct blame_entry *e,
* Link in a new blame entry to the scoreboard. Entries that cover the same
* line range have been removed from the scoreboard previously.
*/
-static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e)
+static void add_blame_entry(git_blame__scoreboard *sb, git_blame__entry *e)
{
- struct blame_entry *ent, *prev = NULL;
+ git_blame__entry *ent, *prev = NULL;
origin_incref(e->suspect);
@@ -161,9 +165,9 @@ static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e)
* a malloced blame_entry that is already on the linked list of the scoreboard.
* The origin of dst loses a refcnt while the origin of src gains one.
*/
-static void dup_entry(struct blame_entry *dst, struct blame_entry *src)
+static void dup_entry(git_blame__entry *dst, git_blame__entry *src)
{
- struct blame_entry *p, *n;
+ git_blame__entry *p, *n;
p = dst->prev;
n = dst->next;
@@ -179,9 +183,9 @@ static void dup_entry(struct blame_entry *dst, struct blame_entry *src)
* split_overlap() divided an existing blame e into up to three parts in split.
* Adjust the linked list of blames in the scoreboard to reflect the split.
*/
-static void split_blame(struct scoreboard *sb, struct blame_entry *split, struct blame_entry *e)
+static void split_blame(git_blame__scoreboard *sb, git_blame__entry *split, git_blame__entry *e)
{
- struct blame_entry *new_entry;
+ git_blame__entry *new_entry;
if (split[0].suspect && split[2].suspect) {
/* The first part (reuse storage for the existing entry e */
@@ -189,12 +193,12 @@ static void split_blame(struct scoreboard *sb, struct blame_entry *split, struct
/* The last part -- me */
new_entry = git__malloc(sizeof(*new_entry));
- memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
+ memcpy(new_entry, &(split[2]), sizeof(git_blame__entry));
add_blame_entry(sb, new_entry);
/* ... and the middle part -- parent */
new_entry = git__malloc(sizeof(*new_entry));
- memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
+ memcpy(new_entry, &(split[1]), sizeof(git_blame__entry));
add_blame_entry(sb, new_entry);
} else if (!split[0].suspect && !split[2].suspect) {
/*
@@ -206,13 +210,13 @@ static void split_blame(struct scoreboard *sb, struct blame_entry *split, struct
/* me and then parent */
dup_entry(e, &split[0]);
new_entry = git__malloc(sizeof(*new_entry));
- memcpy(new_entry, &(split[1]), sizeof(struct blame_entry));
+ memcpy(new_entry, &(split[1]), sizeof(git_blame__entry));
add_blame_entry(sb, new_entry);
} else {
/* parent and then me */
dup_entry(e, &split[1]);
new_entry = git__malloc(sizeof(*new_entry));
- memcpy(new_entry, &(split[2]), sizeof(struct blame_entry));
+ memcpy(new_entry, &(split[2]), sizeof(git_blame__entry));
add_blame_entry(sb, new_entry);
}
}
@@ -221,7 +225,7 @@ static void split_blame(struct scoreboard *sb, struct blame_entry *split, struct
* After splitting the blame, the origins used by the on-stack blame_entry
* should lose one refcnt each.
*/
-static void decref_split(struct blame_entry *split)
+static void decref_split(git_blame__entry *split)
{
int i;
for (i=0; i<3; i++)
@@ -232,9 +236,9 @@ static void decref_split(struct blame_entry *split)
* Helper for blame_chunk(). blame_entry e is known to overlap with the patch
* hunk; split it and pass blame to the parent.
*/
-static void blame_overlap(struct scoreboard *sb, struct blame_entry *e, int tlno, int plno, int same, struct origin *parent)
+static void blame_overlap(git_blame__scoreboard *sb, git_blame__entry *e, int tlno, int plno, int same, git_blame__origin *parent)
{
- struct blame_entry split[3] = {{0}};
+ git_blame__entry split[3] = {{0}};
split_overlap(split, e, tlno, plno, same, parent);
if (split[1].suspect)
@@ -247,9 +251,9 @@ static void blame_overlap(struct scoreboard *sb, struct blame_entry *e, int tlno
* e and its parent. Find and split the overlap, and pass blame to the
* overlapping part to the parent.
*/
-static void blame_chunk(struct scoreboard *sb, int tlno, int plno, int same, struct origin *target, struct origin *parent)
+static void blame_chunk(git_blame__scoreboard *sb, int tlno, int plno, int same, git_blame__origin *target, git_blame__origin *parent)
{
- struct blame_entry *e;
+ git_blame__entry *e;
for (e = sb->ent; e; e = e->next) {
if (e->guilty || !same_suspect(e->suspect, target))
@@ -328,7 +332,7 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, void *cb_data)
return xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);
}
-static void fill_origin_blob(struct origin *o, mmfile_t *file)
+static void fill_origin_blob(git_blame__origin *o, mmfile_t *file)
{
memset(file, 0, sizeof(*file));
if (o->blob) {
@@ -337,9 +341,9 @@ static void fill_origin_blob(struct origin *o, mmfile_t *file)
}
}
-static int pass_blame_to_parent(struct scoreboard *sb,
- struct origin *target,
- struct origin *parent)
+static int pass_blame_to_parent(git_blame__scoreboard *sb,
+ git_blame__origin *target,
+ git_blame__origin *parent)
{
int last_in_target;
mmfile_t file_p, file_o;
@@ -365,10 +369,10 @@ static int paths_on_dup(void **old, void *new)
git__free(new);
return -1;
}
-static struct origin* find_origin(struct scoreboard *sb, git_commit *parent,
- struct origin *origin)
+static git_blame__origin* find_origin(git_blame__scoreboard *sb, git_commit *parent,
+ git_blame__origin *origin)
{
- struct origin *porigin = NULL;
+ git_blame__origin *porigin = NULL;
git_diff_list *difflist = NULL;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_tree *otree=NULL, *ptree=NULL;
@@ -429,10 +433,10 @@ cleanup:
* The blobs of origin and porigin exactly match, so everything origin is
* suspected for can be blamed on the parent.
*/
-static void pass_whole_blame(struct scoreboard *sb,
- struct origin *origin, struct origin *porigin)
+static void pass_whole_blame(git_blame__scoreboard *sb,
+ git_blame__origin *origin, git_blame__origin *porigin)
{
- struct blame_entry *e;
+ git_blame__entry *e;
if (!porigin->blob)
git_object_lookup((git_object**)&porigin->blob, sb->blame->repository, git_blob_id(origin->blob),
@@ -446,12 +450,12 @@ static void pass_whole_blame(struct scoreboard *sb,
}
}
-static void pass_blame(struct scoreboard *sb, struct origin *origin, uint32_t opt)
+static void pass_blame(git_blame__scoreboard *sb, git_blame__origin *origin, uint32_t opt)
{
git_commit *commit = origin->commit;
int i, num_sg;
- struct origin *sg_buf[16];
- struct origin *porigin, **sg_origin = sg_buf;
+ git_blame__origin *sg_buf[16];
+ git_blame__origin *porigin, **sg_origin = sg_buf;
GIT_UNUSED(opt);
@@ -498,7 +502,7 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, uint32_t op
}
for (i=0; i<num_sg; i++) {
- struct origin *porigin = sg_origin[i];
+ git_blame__origin *porigin = sg_origin[i];
if (!porigin)
continue;
if (!origin->previous) {
@@ -526,14 +530,14 @@ finish:
* Origin is refcounted and usually we keep the blob contents to be
* reused.
*/
-struct origin *origin_incref(struct origin *o)
+git_blame__origin *origin_incref(git_blame__origin *o)
{
if (o)
o->refcnt++;
return o;
}
-void origin_decref(struct origin *o)
+void origin_decref(git_blame__origin *o)
{
if (o && --o->refcnt <= 0) {
if (o->previous)
@@ -544,11 +548,11 @@ void origin_decref(struct origin *o)
}
}
-void assign_blame(struct scoreboard *sb, uint32_t opt)
+void assign_blame(git_blame__scoreboard *sb, uint32_t opt)
{
while (true) {
- struct blame_entry *ent;
- struct origin *suspect = NULL;
+ git_blame__entry *ent;
+ git_blame__origin *suspect = NULL;
/* Find a suspect to break down */
for (ent = sb->ent; !suspect && ent; ent = ent->next)
@@ -574,9 +578,9 @@ void assign_blame(struct scoreboard *sb, uint32_t opt)
}
}
-void coalesce(struct scoreboard *sb)
+void coalesce(git_blame__scoreboard *sb)
{
- struct blame_entry *ent, *next;
+ git_blame__entry *ent, *next;
for (ent=sb->ent; ent && (next = ent->next); ent = next) {
if (same_suspect(ent->suspect, next->suspect) &&
diff --git a/src/blame_git.h b/src/blame_git.h
index 6af804d..7d229c6 100644
--- a/src/blame_git.h
+++ b/src/blame_git.h
@@ -9,22 +9,22 @@
/*
* One blob in a commit that is being suspected
*/
-struct origin {
+typedef struct git_blame__origin {
int refcnt;
- struct origin *previous;
+ struct git_blame__origin *previous;
git_commit *commit;
git_blob *blob;
char path[];
-};
+} git_blame__origin;
/*
- * Each group of lines is described by a blame_entry; it can be split
+ * Each group of lines is described by a git_blame__entry; it can be split
* as we pass blame to the parents. They form a linked list in the
* scoreboard structure, sorted by the target line number.
*/
-struct blame_entry {
- struct blame_entry *prev;
- struct blame_entry *next;
+typedef struct git_blame__entry {
+ struct git_blame__entry *prev;
+ struct git_blame__entry *next;
/* the first line of this group in the final image;
* internally all line numbers are 0 based.
@@ -35,7 +35,7 @@ struct blame_entry {
int num_lines;
/* the commit that introduced this group into the final image */
- struct origin *suspect;
+ git_blame__origin *suspect;
/* true if the suspect is truly guilty; false while we have not
* checked if the group came from one of its parents.
@@ -59,12 +59,12 @@ struct blame_entry {
/* Whether this entry has been tracked to a boundary commit.
*/
bool is_boundary;
-};
+} git_blame__entry;
/*
* The current state of the blame assignment.
*/
-struct scoreboard {
+typedef struct git_blame__scoreboard {
/* the final commit (i.e. where we started digging from) */
git_commit *final;
const char *path;
@@ -78,20 +78,20 @@ struct scoreboard {
git_off_t final_buf_size;
/* linked list of blames */
- struct blame_entry *ent;
+ git_blame__entry *ent;
/* look-up a line in the final buffer */
int num_lines;
git_blame *blame;
-};
+} git_blame__scoreboard;
-int get_origin(struct origin **out, struct scoreboard *sb, git_commit *commit, const char *path);
-int make_origin(struct origin **out, git_commit *commit, const char *path);
-struct origin *origin_incref(struct origin *o);
-void origin_decref(struct origin *o);
-void assign_blame(struct scoreboard *sb, uint32_t flags);
-void coalesce(struct scoreboard *sb);
+int get_origin(git_blame__origin **out, git_blame__scoreboard *sb, git_commit *commit, const char *path);
+int make_origin(git_blame__origin **out, git_commit *commit, const char *path);
+git_blame__origin *origin_incref(git_blame__origin *o);
+void origin_decref(git_blame__origin *o);
+void assign_blame(git_blame__scoreboard *sb, uint32_t flags);
+void coalesce(git_blame__scoreboard *sb);
#endif