builtin-blame.c: move prepare_final() into a separate function.
After parsing the command line, we have a long loop to compute the commit object to start annotating from. Move the logic to a separate function, so that later patches become easier to read. It also makes fill_origin_blob() return void; the check is always done on !file->ptr, and nobody looks at the return value from the function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Apr 2, 2008 at 22:17 UTC
f6c07d7d475ffaa67b817beb2635fd73a5e0e962
1 file changed
+33
-23
builtin-blame.c
+33
-23
@@ -91,7 +91,7 @@ struct origin {
91
* Given an origin, prepare mmfile_t structure to be used by the
92
* diff machinery
93
*/
94
-static char *fill_origin_blob(struct origin *o, mmfile_t *file)
94
+static void fill_origin_blob(struct origin *o, mmfile_t *file)
95
{
96
if (!o->file.ptr) {
97
enum object_type type;
@@ -106,7 +106,6 @@ static char *fill_origin_blob(struct origin *o, mmfile_t *file)
106
}
107
else
108
*file = o->file;
109
- return file->ptr;
109
}
110
111
/*
@@ -2006,6 +2005,10 @@ static int git_blame_config(const char *var, const char *value)
2005
return git_default_config(var, value);
2006
}
2007
2008
+/*
2009
+ * Prepare a dummy commit that represents the work tree (or staged) item.
2010
+ * Note that annotating work tree item never works in the reverse.
2011
+ */
2012
static struct commit *fake_working_tree_commit(const char *path, const char *contents_from)
2013
{
2014
struct commit *commit;
@@ -2122,6 +2125,33 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2125
return commit;
2126
}
2127
2128
+static const char *prepare_final(struct scoreboard *sb, struct rev_info *revs)
2129
+{
2130
+ int i;
2131
+ const char *final_commit_name = NULL;
2132
+
2133
+ /*
2134
+ * There must be one and only one positive commit in the
2135
+ * revs->pending array.
2136
+ */
2137
+ for (i = 0; i < revs->pending.nr; i++) {
2138
+ struct object *obj = revs->pending.objects[i].item;
2139
+ if (obj->flags & UNINTERESTING)
2140
+ continue;
2141
+ while (obj->type == OBJ_TAG)
2142
+ obj = deref_tag(obj, NULL, 0);
2143
+ if (obj->type != OBJ_COMMIT)
2144
+ die("Non commit %s?", revs->pending.objects[i].name);
2145
+ if (sb->final)
2146
+ die("More than one commit to dig from %s and %s?",
2147
+ revs->pending.objects[i].name,
2148
+ final_commit_name);
2149
+ sb->final = (struct commit *) obj;
2150
+ final_commit_name = revs->pending.objects[i].name;
2151
+ }
2152
+ return final_commit_name;
2153
+}
2154
+
2155
int cmd_blame(int argc, const char **argv, const char *prefix)
2156
{
2157
struct rev_info revs;
@@ -2327,27 +2357,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2357
setup_revisions(unk, argv, &revs, NULL);
2358
memset(&sb, 0, sizeof(sb));
2359
2330
- /*
2331
- * There must be one and only one positive commit in the
2332
- * revs->pending array.
2333
- */
2334
- for (i = 0; i < revs.pending.nr; i++) {
2335
- struct object *obj = revs.pending.objects[i].item;
2336
- if (obj->flags & UNINTERESTING)
2337
- continue;
2338
- while (obj->type == OBJ_TAG)
2339
- obj = deref_tag(obj, NULL, 0);
2340
- if (obj->type != OBJ_COMMIT)
2341
- die("Non commit %s?",
2342
- revs.pending.objects[i].name);
2343
- if (sb.final)
2344
- die("More than one commit to dig from %s and %s?",
2345
- revs.pending.objects[i].name,
2346
- final_commit_name);
2347
- sb.final = (struct commit *) obj;
2348
- final_commit_name = revs.pending.objects[i].name;
2349
- }
2350
-
2360
+ final_commit_name = prepare_final(&sb, &revs);
2361
if (!sb.final) {
2362
/*
2363
* "--not A B -- path" without anything positive;