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

Function write_out_one_reject

apply.c:4716–4802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4714}
4715
4716static int write_out_one_reject(struct apply_state *state, struct patch *patch)
4717{
4718 FILE *rej;
4719 char *namebuf;
4720 struct fragment *frag;
4721 int fd, cnt = 0;
4722 struct strbuf sb = STRBUF_INIT;
4723
4724 for (cnt = 0, frag = patch->fragments; frag; frag = frag->next) {
4725 if (!frag->rejected)
4726 continue;
4727 cnt++;
4728 }
4729
4730 if (!cnt) {
4731 if (state->apply_verbosity > verbosity_normal)
4732 say_patch_name(stderr,
4733 _("Applied patch %s cleanly."), patch);
4734 return 0;
4735 }
4736
4737 /* This should not happen, because a removal patch that leaves
4738 * contents are marked "rejected" at the patch level.
4739 */
4740 if (!patch->new_name)
4741 die(_("internal error"));
4742
4743 /* Say this even without --verbose */
4744 strbuf_addf(&sb, Q_("Applying patch %%s with %d reject...",
4745 "Applying patch %%s with %d rejects...",
4746 cnt),
4747 cnt);
4748 if (state->apply_verbosity > verbosity_silent)
4749 say_patch_name(stderr, sb.buf, patch);
4750 strbuf_release(&sb);
4751
4752 namebuf = xstrfmt("%s.rej", patch->new_name);
4753
4754 fd = open(namebuf, O_CREAT | O_EXCL | O_WRONLY, 0666);
4755 if (fd < 0) {
4756 if (errno != EEXIST) {
4757 error_errno(_("cannot open %s"), namebuf);
4758 goto error;
4759 }
4760 if (unlink(namebuf)) {
4761 error_errno(_("cannot unlink '%s'"), namebuf);
4762 goto error;
4763 }
4764 fd = open(namebuf, O_CREAT | O_EXCL | O_WRONLY, 0666);
4765 if (fd < 0) {
4766 error_errno(_("cannot open %s"), namebuf);
4767 goto error;
4768 }
4769 }
4770 rej = fdopen(fd, "w");
4771 if (!rej) {
4772 error_errno(_("cannot open %s"), namebuf);
4773 close(fd);

Callers 1

write_out_resultsFunction · 0.85

Calls 7

say_patch_nameFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_releaseFunction · 0.85
xstrfmtFunction · 0.85
error_errnoFunction · 0.85
fprintf_lnFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected