Skip to content

Commit 1f76a10

Browse files
committed
write_file(): drop caller-supplied LF from calls to create a one-liner file
All of the callsites covered by this change call write_file() or write_file_gently() to create a one-liner file. Drop the caller supplied LF and let these callees to append it as necessary. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e7ffa38 commit 1f76a10

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

builtin/init-db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static void separate_git_dir(const char *git_dir)
378378
die_errno(_("unable to move %s to %s"), src, git_dir);
379379
}
380380

381-
write_file(git_link, "gitdir: %s\n", git_dir);
381+
write_file(git_link, "gitdir: %s", git_dir);
382382
}
383383

384384
int init_db(const char *template_dir, unsigned int flags)

builtin/worktree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int add_worktree(const char *path, const char **child_argv)
213213
* after the preparation is over.
214214
*/
215215
strbuf_addf(&sb, "%s/locked", sb_repo.buf);
216-
write_file(sb.buf, "initializing\n");
216+
write_file(sb.buf, "initializing");
217217

218218
strbuf_addf(&sb_git, "%s/.git", path);
219219
if (safe_create_leading_directories_const(sb_git.buf))
@@ -223,8 +223,8 @@ static int add_worktree(const char *path, const char **child_argv)
223223

224224
strbuf_reset(&sb);
225225
strbuf_addf(&sb, "%s/gitdir", sb_repo.buf);
226-
write_file(sb.buf, "%s\n", real_path(sb_git.buf));
227-
write_file(sb_git.buf, "gitdir: %s/worktrees/%s\n",
226+
write_file(sb.buf, "%s", real_path(sb_git.buf));
227+
write_file(sb_git.buf, "gitdir: %s/worktrees/%s",
228228
real_path(get_git_common_dir()), name);
229229
/*
230230
* This is to keep resolve_ref() happy. We need a valid HEAD
@@ -241,10 +241,10 @@ static int add_worktree(const char *path, const char **child_argv)
241241
die(_("unable to resolve HEAD"));
242242
strbuf_reset(&sb);
243243
strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
244-
write_file(sb.buf, "%s\n", sha1_to_hex(rev));
244+
write_file(sb.buf, "%s", sha1_to_hex(rev));
245245
strbuf_reset(&sb);
246246
strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
247-
write_file(sb.buf, "../..\n");
247+
write_file(sb.buf, "../..");
248248

249249
fprintf_ln(stderr, _("Enter %s (identifier %s)"), path, name);
250250

daemon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ int main(int argc, char **argv)
13761376
sanitize_stdfds();
13771377

13781378
if (pid_file)
1379-
write_file(pid_file, "%"PRIuMAX"\n", (uintmax_t) getpid());
1379+
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
13801380

13811381
/* prepare argv for serving-processes */
13821382
cld_argv = xmalloc(sizeof (char *) * (argc + 2));

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static void update_linked_gitdir(const char *gitfile, const char *gitdir)
404404

405405
strbuf_addf(&path, "%s/gitfile", gitdir);
406406
if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
407-
write_file_gently(path.buf, "%s\n", gitfile);
407+
write_file_gently(path.buf, "%s", gitfile);
408408
strbuf_release(&path);
409409
}
410410

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
11031103

11041104
/* Update gitfile */
11051105
strbuf_addf(&file_name, "%s/.git", work_tree);
1106-
write_file(file_name.buf, "gitdir: %s\n",
1106+
write_file(file_name.buf, "gitdir: %s",
11071107
relative_path(git_dir, real_work_tree, &rel_path));
11081108

11091109
/* Update core.worktree setting */

transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static int write_one_ref(const char *name, const struct object_id *oid,
291291

292292
strbuf_addstr(buf, name);
293293
if (safe_create_leading_directories(buf->buf) ||
294-
write_file_gently(buf->buf, "%s\n", oid_to_hex(oid)))
294+
write_file_gently(buf->buf, "%s", oid_to_hex(oid)))
295295
return error("problems writing temporary file %s: %s",
296296
buf->buf, strerror(errno));
297297
strbuf_setlen(buf, len);

0 commit comments

Comments
 (0)