dump_marks(): reimplement using fdopen_lock_file()

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Oct 1, 2014 at 13:14 UTC f70f0565b3a905ba90af3446475afec2e8aa0d2a
1 file changed +2 -19
fast-import.c
+2 -19
@@ -1794,20 +1794,18 @@ static void dump_marks_helper(FILE *f,
1794 static void dump_marks(void)
1795 {
1796 static struct lock_file mark_lock;
1797 - int mark_fd;
1797 FILE *f;
1798
1799 if (!export_marks_file)
1800 return;
1801
1803 - mark_fd = hold_lock_file_for_update(&mark_lock, export_marks_file, 0);
1804 - if (mark_fd < 0) {
1802 + if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
1803 failure |= error("Unable to write marks file %s: %s",
1804 export_marks_file, strerror(errno));
1805 return;
1806 }
1807
1810 - f = fdopen(mark_fd, "w");
1808 + f = fdopen_lock_file(&mark_lock, "w");
1809 if (!f) {
1810 int saved_errno = errno;
1811 rollback_lock_file(&mark_lock);
@@ -1816,22 +1814,7 @@ static void dump_marks(void)
1814 return;
1815 }
1816
1819 - /*
1820 - * Since the lock file was fdopen()'ed, it should not be close()'ed.
1821 - * Assign -1 to the lock file descriptor so that commit_lock_file()
1822 - * won't try to close() it.
1823 - */
1824 - mark_lock.fd = -1;
1825 -
1817 dump_marks_helper(f, 0, marks);
1827 - if (ferror(f) || fclose(f)) {
1828 - int saved_errno = errno;
1829 - rollback_lock_file(&mark_lock);
1830 - failure |= error("Unable to write marks file %s: %s",
1831 - export_marks_file, strerror(saved_errno));
1832 - return;
1833 - }
1834 -
1818 if (commit_lock_file(&mark_lock)) {
1819 failure |= error("Unable to commit marks file %s: %s",
1820 export_marks_file, strerror(errno));