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

Function log_ref_setup

refs/files-backend.c:1859–1915  ·  view source on GitHub ↗

* Create a reflog for a ref. If force_create = 0, only create the * reflog for certain refs (those for which should_autocreate_reflog * returns non-zero). Otherwise, create it regardless of the reference * name. If the logfile already existed or was created, return 0 and * set *logfd to the file descriptor opened for appending to the file. * If no logfile exists and we decided not to create o

Source from the content-addressed store, hash-verified

1857 * return -1.
1858 */
1859static int log_ref_setup(struct files_ref_store *refs,
1860 const char *refname, int force_create,
1861 int *logfd, struct strbuf *err)
1862{
1863 enum log_refs_config log_refs_cfg = refs->log_all_ref_updates;
1864 struct strbuf logfile_sb = STRBUF_INIT;
1865 char *logfile;
1866
1867 if (log_refs_cfg == LOG_REFS_UNSET)
1868 log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
1869
1870 files_reflog_path(refs, &logfile_sb, refname);
1871 logfile = strbuf_detach(&logfile_sb, NULL);
1872
1873 if (force_create || should_autocreate_reflog(log_refs_cfg, refname)) {
1874 if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) {
1875 if (errno == ENOENT)
1876 strbuf_addf(err, "unable to create directory for '%s': "
1877 "%s", logfile, strerror(errno));
1878 else if (errno == EISDIR)
1879 strbuf_addf(err, "there are still logs under '%s'",
1880 logfile);
1881 else
1882 strbuf_addf(err, "unable to append to '%s': %s",
1883 logfile, strerror(errno));
1884
1885 goto error;
1886 }
1887 } else {
1888 *logfd = open(logfile, O_APPEND | O_WRONLY);
1889 if (*logfd < 0) {
1890 if (errno == ENOENT || errno == EISDIR) {
1891 /*
1892 * The logfile doesn't already exist,
1893 * but that is not an error; it only
1894 * means that we won't write log
1895 * entries to it.
1896 */
1897 ;
1898 } else {
1899 strbuf_addf(err, "unable to append to '%s': %s",
1900 logfile, strerror(errno));
1901 goto error;
1902 }
1903 }
1904 }
1905
1906 if (*logfd >= 0)
1907 adjust_shared_perm(the_repository, logfile);
1908
1909 free(logfile);
1910 return 0;
1911
1912error:
1913 free(logfile);
1914 return -1;
1915}
1916

Callers 2

files_create_reflogFunction · 0.85
files_log_ref_writeFunction · 0.85

Calls 7

is_bare_repositoryFunction · 0.85
files_reflog_pathFunction · 0.85
strbuf_detachFunction · 0.85
should_autocreate_reflogFunction · 0.85
raceproof_create_fileFunction · 0.85
strbuf_addfFunction · 0.85
adjust_shared_permFunction · 0.85

Tested by

no test coverage detected