* Prepare a dummy commit that represents the work tree (or staged) item. * Note that annotating work tree item never works in the reverse. */
| 186 | * Note that annotating work tree item never works in the reverse. |
| 187 | */ |
| 188 | static struct commit *fake_working_tree_commit(struct repository *r, |
| 189 | struct diff_options *opt, |
| 190 | const char *path, |
| 191 | const char *contents_from, |
| 192 | struct object_id *oid) |
| 193 | { |
| 194 | struct commit *commit; |
| 195 | struct blame_origin *origin; |
| 196 | struct commit_list **parent_tail, *parent; |
| 197 | struct strbuf buf = STRBUF_INIT; |
| 198 | const char *ident; |
| 199 | time_t now; |
| 200 | int len; |
| 201 | struct cache_entry *ce; |
| 202 | unsigned mode; |
| 203 | struct strbuf msg = STRBUF_INIT; |
| 204 | |
| 205 | repo_read_index(r); |
| 206 | time(&now); |
| 207 | commit = alloc_commit_node(r); |
| 208 | commit->object.parsed = 1; |
| 209 | commit->date = now; |
| 210 | parent_tail = &commit->parents; |
| 211 | |
| 212 | parent_tail = append_parent(r, parent_tail, oid); |
| 213 | append_merge_parents(r, parent_tail); |
| 214 | verify_working_tree_path(r, commit, path); |
| 215 | |
| 216 | origin = make_origin(commit, path); |
| 217 | |
| 218 | if (contents_from) |
| 219 | ident = fmt_ident("External file (--contents)", "external.file", |
| 220 | WANT_BLANK_IDENT, NULL, 0); |
| 221 | else |
| 222 | ident = fmt_ident("Not Committed Yet", "not.committed.yet", |
| 223 | WANT_BLANK_IDENT, NULL, 0); |
| 224 | strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n"); |
| 225 | for (parent = commit->parents; parent; parent = parent->next) |
| 226 | strbuf_addf(&msg, "parent %s\n", |
| 227 | oid_to_hex(&parent->item->object.oid)); |
| 228 | strbuf_addf(&msg, |
| 229 | "author %s\n" |
| 230 | "committer %s\n\n" |
| 231 | "Version of %s from %s\n", |
| 232 | ident, ident, path, |
| 233 | (!contents_from ? path : |
| 234 | (!strcmp(contents_from, "-") ? "standard input" : contents_from))); |
| 235 | set_commit_buffer_from_strbuf(r, commit, &msg); |
| 236 | |
| 237 | if (!contents_from || strcmp("-", contents_from)) { |
| 238 | struct stat st; |
| 239 | const char *read_from; |
| 240 | char *buf_ptr; |
| 241 | unsigned long buf_len; |
| 242 | |
| 243 | if (contents_from) { |
| 244 | if (stat(contents_from, &st) < 0) |
| 245 | die_errno("Cannot stat '%s'", contents_from); |
no test coverage detected