MCPcopy Create free account
hub / github.com/git/git / notes_copy_from_stdin

Function notes_copy_from_stdin

builtin/notes.c:360–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358}
359
360static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
361{
362 struct strbuf buf = STRBUF_INIT;
363 struct notes_rewrite_cfg *c = NULL;
364 struct notes_tree *t = NULL;
365 int ret = 0;
366 const char *msg = "Notes added by 'git notes copy'";
367
368 if (rewrite_cmd) {
369 c = init_copy_notes_for_rewrite(rewrite_cmd);
370 if (!c)
371 return 0;
372 } else {
373 init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
374 t = &default_notes_tree;
375 }
376
377 while (strbuf_getline_lf(&buf, stdin) != EOF) {
378 struct object_id from_obj, to_obj;
379 struct string_list split = STRING_LIST_INIT_NODUP;
380 int err;
381
382 string_list_split_in_place_f(&split, buf.buf, " ", -1,
383 STRING_LIST_SPLIT_TRIM);
384 if (split.nr < 2)
385 die(_("malformed input line: '%s'."), buf.buf);
386 if (repo_get_oid(the_repository, split.items[0].string, &from_obj))
387 die(_("failed to resolve '%s' as a valid ref."),
388 split.items[0].string);
389 if (repo_get_oid(the_repository, split.items[1].string, &to_obj))
390 die(_("failed to resolve '%s' as a valid ref."),
391 split.items[1].string);
392
393 if (rewrite_cmd)
394 err = copy_note_for_rewrite(c, &from_obj, &to_obj);
395 else
396 err = copy_note(t, &from_obj, &to_obj, force,
397 combine_notes_overwrite);
398
399 if (err) {
400 error(_("failed to copy notes from '%s' to '%s'"),
401 split.items[0].string, split.items[1].string);
402 ret = 1;
403 }
404
405 string_list_clear(&split, 0);
406 }
407
408 if (!rewrite_cmd) {
409 commit_notes(the_repository, t, msg);
410 free_notes(t);
411 } else {
412 finish_copy_notes_for_rewrite(the_repository, c, msg);
413 }
414 strbuf_release(&buf);
415 return ret;
416}
417

Callers 1

copyFunction · 0.85

Calls 14

init_notesFunction · 0.85
strbuf_getline_lfFunction · 0.85
repo_get_oidFunction · 0.85
copy_note_for_rewriteFunction · 0.85
copy_noteFunction · 0.85
errorFunction · 0.85
string_list_clearFunction · 0.85
commit_notesFunction · 0.85
free_notesFunction · 0.85

Tested by

no test coverage detected