[PATCH 00/41] Add and use error_errno() and warning_errno()

classic Classic list List threaded Threaded
145 messages Options
1234 ... 8
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/41] Add and use error_errno() and warning_errno()

Duy Nguyen
This is a spinoff from my worktree-move topic. This series adds
die_errno() companions, error_errno() and warning_errno(), and use them
where applicable to reduce the amount of typing (in future). Changes
are split by file (which explains the huge number of patches). I leave
builtin/apply.c and refs/files-backend.c untouched because they are
currently hot zones.

Nguyễn Thái Ngọc Duy (41):
  usage.c: move format processing out of die_errno()
  usage.c: add warning_errno() and error_errno()
  bisect.c: use die_errno() and warning_errno()
  builtin/am.c: use error_errno()
  builtin/branch.c: use error_errno()
  builtin/fetch.c: use error_errno()
  builtin/help.c: use warning_errno()
  builtin/mailsplit.c: use error_errno()
  builtin/merge-file.c: use error_errno()
  builtin/pack-objects.c: use die_errno() and warning_errno()
  builtin/rm.c: use warning_errno()
  builtin/update-index.c: use error_errno()
  builtin/upload-archive.c: use error_errno()
  builtin/worktree.c: use error_errno()
  check-racy.c: use error_errno()
  combine-diff.c: use error_errno()
  compat/win32/syslog.c: use warning_errno()
  config.c: use error_errno()
  connected.c: use error_errno()
  copy.c: use error_errno()
  credential-cache--daemon.c: use warning_errno()
  diff-no-index.c: use error_errno()
  editor.c: use error_errno()
  entry.c: use error_errno()
  fast-import.c: use error_errno()
  gpg-interface.c: use error_errno()
  grep.c: use error_errno()
  http.c: use error_errno() and warning_errno()
  ident.c: use warning_errno()
  mailmap.c: use error_errno()
  reachable.c: use error_errno()
  rerere.c: use error_errno() and warning_errno()
  run-command.c: use error_errno()
  sequencer.c: use error_errno()
  server-info.c: use error_errno()
  sha1_file.c: use {error,die,warning}_errno()
  transport-helper.c: use error_errno()
  unpack-trees.c: use error_errno()
  upload-pack.c: use error_errno()
  vcs-svn: use error_errno()
  wrapper.c: use warning_errno()

 bisect.c                   |  7 +++----
 builtin/am.c               | 11 +++++------
 builtin/branch.c           |  3 +--
 builtin/fetch.c            |  4 ++--
 builtin/help.c             |  8 ++++----
 builtin/mailsplit.c        | 10 +++++-----
 builtin/merge-file.c       | 10 +++++-----
 builtin/pack-objects.c     |  8 +++-----
 builtin/rm.c               |  2 +-
 builtin/update-index.c     |  8 ++++----
 builtin/upload-archive.c   |  3 +--
 builtin/worktree.c         |  2 +-
 check-racy.c               |  2 +-
 combine-diff.c             |  3 +--
 compat/win32/syslog.c      |  6 +++---
 config.c                   | 22 +++++++++-------------
 connected.c                |  9 +++------
 copy.c                     |  6 +++---
 credential-cache--daemon.c |  4 ++--
 diff-no-index.c            |  3 +--
 editor.c                   |  3 +--
 entry.c                    | 10 ++++------
 fast-import.c              | 10 +++++-----
 git-compat-util.h          |  2 ++
 gpg-interface.c            |  6 ++----
 grep.c                     |  4 ++--
 http.c                     | 10 ++++------
 ident.c                    |  8 +++-----
 mailmap.c                  |  3 +--
 reachable.c                |  3 +--
 rerere.c                   | 18 +++++++-----------
 run-command.c              | 15 +++++++--------
 sequencer.c                |  3 +--
 server-info.c              |  2 +-
 sha1_file.c                | 32 +++++++++++++-------------------
 transport-helper.c         |  6 +++---
 unpack-trees.c             |  6 ++----
 upload-pack.c              |  3 +--
 usage.c                    | 44 ++++++++++++++++++++++++++++++++++----------
 vcs-svn/line_buffer.c      |  4 ++--
 vcs-svn/sliding_window.c   |  2 +-
 vcs-svn/svndiff.c          |  4 ++--
 vcs-svn/svndump.c          |  4 ++--
 wrapper.c                  |  4 ++--
 44 files changed, 161 insertions(+), 176 deletions(-)

--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 01/41] usage.c: move format processing out of die_errno()

Duy Nguyen
fmt_with_err() will be shared with the coming error_errno() and
warning_errno().

Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 usage.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/usage.c b/usage.c
index 82ff131..0dba0c5 100644
--- a/usage.c
+++ b/usage.c
@@ -109,19 +109,12 @@ void NORETURN die(const char *err, ...)
  va_end(params);
 }
 
-void NORETURN die_errno(const char *fmt, ...)
+static const char *fmt_with_err(const char *fmt)
 {
- va_list params;
- char fmt_with_err[1024];
+ static char fmt_with_err[1024];
  char str_error[256], *err;
  int i, j;
 
- if (die_is_recursing()) {
- fputs("fatal: recursion detected in die_errno handler\n",
- stderr);
- exit(128);
- }
-
  err = strerror(errno);
  for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
  if ((str_error[j++] = err[i++]) != '%')
@@ -137,9 +130,21 @@ void NORETURN die_errno(const char *fmt, ...)
  }
  str_error[j] = 0;
  snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);
+ return fmt_with_err;
+}
+
+void NORETURN die_errno(const char *fmt, ...)
+{
+ va_list params;
+
+ if (die_is_recursing()) {
+ fputs("fatal: recursion detected in die_errno handler\n",
+ stderr);
+ exit(128);
+ }
 
  va_start(params, fmt);
- die_routine(fmt_with_err, params);
+ die_routine(fmt_with_err(fmt), params);
  va_end(params);
 }
 
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 02/41] usage.c: add warning_errno() and error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Similar to die_errno(), these functions will append strerror()
automatically.

Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 git-compat-util.h |  2 ++
 usage.c           | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/git-compat-util.h b/git-compat-util.h
index 1f8b5f3..49d4029 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -409,7 +409,9 @@ extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf,
 extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
 #ifndef NO_OPENSSL
 #ifdef APPLE_COMMON_CRYPTO
diff --git a/usage.c b/usage.c
index 0dba0c5..af1b7d1 100644
--- a/usage.c
+++ b/usage.c
@@ -148,6 +148,16 @@ void NORETURN die_errno(const char *fmt, ...)
  va_end(params);
 }
 
+int error_errno(const char *fmt, ...)
+{
+ va_list params;
+
+ va_start(params, fmt);
+ error_routine(fmt_with_err(fmt), params);
+ va_end(params);
+ return -1;
+}
+
 #undef error
 int error(const char *err, ...)
 {
@@ -159,6 +169,15 @@ int error(const char *err, ...)
  return -1;
 }
 
+void warning_errno(const char *warn, ...)
+{
+ va_list params;
+
+ va_start(params, warn);
+ warn_routine(fmt_with_err(warn), params);
+ va_end(params);
+}
+
 void warning(const char *warn, ...)
 {
  va_list params;
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 03/41] bisect.c: use die_errno() and warning_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 bisect.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/bisect.c b/bisect.c
index 7996c29..6d93edb 100644
--- a/bisect.c
+++ b/bisect.c
@@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
  /* Create file BISECT_ANCESTORS_OK. */
  fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
  if (fd < 0)
- warning("could not create file '%s': %s",
- filename, strerror(errno));
+ warning_errno("could not create file '%s'",
+      filename);
  else
  close(fd);
  done:
@@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
  *read_good = "good";
  return;
  } else {
- die("could not read file '%s': %s", filename,
- strerror(errno));
+ die_errno("could not read file '%s'", filename);
  }
  } else {
  strbuf_getline_lf(&str, fp);
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 04/41] builtin/am.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/am.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index d003939..3dfe70b 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
  in = fopen(*paths, "r");
 
  if (!in)
- return error(_("could not open '%s' for reading: %s"),
- *paths, strerror(errno));
+ return error_errno(_("could not open '%s' for reading"),
+   *paths);
 
  mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
 
  out = fopen(mail, "w");
  if (!out)
- return error(_("could not open '%s' for writing: %s"),
- mail, strerror(errno));
+ return error_errno(_("could not open '%s' for writing"),
+   mail);
 
  ret = fn(out, in, keep_cr);
 
@@ -857,8 +857,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
 
  fp = fopen(*paths, "r");
  if (!fp)
- return error(_("could not open '%s' for reading: %s"), *paths,
- strerror(errno));
+ return error_errno(_("could not open '%s' for reading"), *paths);
 
  while (!strbuf_getline_lf(&sb, fp)) {
  if (*sb.buf == '#')
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 05/41] builtin/branch.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/branch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 0adba62..6f1572d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -593,8 +593,7 @@ static int edit_branch_description(const char *branch_name)
     branch_name, comment_line_char);
  if (write_file_gently(git_path(edit_description), "%s", buf.buf)) {
  strbuf_release(&buf);
- return error(_("could not write branch description template: %s"),
-     strerror(errno));
+ return error_errno(_("could not write branch description template"));
  }
  strbuf_reset(&buf);
  if (launch_editor(git_path(edit_description), &buf, NULL)) {
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 06/41] builtin/fetch.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/fetch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/fetch.c b/builtin/fetch.c
index f8455bd..1582ca7 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 
  fp = fopen(filename, "a");
  if (!fp)
- return error(_("cannot open %s: %s\n"), filename, strerror(errno));
+ return error_errno(_("cannot open %s"), filename);
 
  if (raw_url)
  url = transport_anonymize_url(raw_url);
@@ -848,7 +848,7 @@ static int truncate_fetch_head(void)
  FILE *fp = fopen_for_writing(filename);
 
  if (!fp)
- return error(_("cannot open %s: %s\n"), filename, strerror(errno));
+ return error_errno(_("cannot open %s"), filename);
  fclose(fp);
  return 0;
 }
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 07/41] builtin/help.c: use warning_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/help.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/help.c b/builtin/help.c
index 3c55ce4..8848013 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page)
  path = "emacsclient";
  strbuf_addf(&man_page, "(woman \"%s\")", page);
  execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL);
- warning(_("failed to exec '%s': %s"), path, strerror(errno));
+ warning_errno(_("failed to exec '%s'"), path);
  }
 }
 
@@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page)
  path = "kfmclient";
  strbuf_addf(&man_page, "man:%s(1)", page);
  execlp(path, filename, "newTab", man_page.buf, (char *)NULL);
- warning(_("failed to exec '%s': %s"), path, strerror(errno));
+ warning_errno(_("failed to exec '%s'"), path);
  }
 }
 
@@ -157,7 +157,7 @@ static void exec_man_man(const char *path, const char *page)
  if (!path)
  path = "man";
  execlp(path, "man", page, (char *)NULL);
- warning(_("failed to exec '%s': %s"), path, strerror(errno));
+ warning_errno(_("failed to exec '%s'"), path);
 }
 
 static void exec_man_cmd(const char *cmd, const char *page)
@@ -165,7 +165,7 @@ static void exec_man_cmd(const char *cmd, const char *page)
  struct strbuf shell_cmd = STRBUF_INIT;
  strbuf_addf(&shell_cmd, "%s %s", cmd, page);
  execl(SHELL_PATH, SHELL_PATH, "-c", shell_cmd.buf, (char *)NULL);
- warning(_("failed to exec '%s': %s"), cmd, strerror(errno));
+ warning(_("failed to exec '%s'"), cmd);
 }
 
 static void add_man_viewer(const char *name)
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 08/41] builtin/mailsplit.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/mailsplit.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 104277a..4859ede 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)
  if ((dir = opendir(name)) == NULL) {
  if (errno == ENOENT)
  continue;
- error("cannot opendir %s (%s)", name, strerror(errno));
+ error_errno("cannot opendir %s", name);
  goto out;
  }
 
@@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir,
 
  f = fopen(file, "r");
  if (!f) {
- error("cannot open mail %s (%s)", file, strerror(errno));
+ error_errno("cannot open mail %s", file);
  goto out;
  }
 
  if (strbuf_getwholeline(&buf, f, '\n')) {
- error("cannot read mail %s (%s)", file, strerror(errno));
+ error_errno("cannot read mail %s", file);
  goto out;
  }
 
@@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
  int file_done = 0;
 
  if (!f) {
- error("cannot open mbox %s", file);
+ error_errno("cannot open mbox %s", file);
  goto out;
  }
 
@@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
  }
 
  if (stat(arg, &argstat) == -1) {
- error("cannot stat %s (%s)", arg, strerror(errno));
+ error_errno("cannot stat %s", arg);
  return 1;
  }
 
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 09/41] builtin/merge-file.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/merge-file.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 5544705..13e22a2 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
  usage_with_options(merge_file_usage, options);
  if (quiet) {
  if (!freopen("/dev/null", "w", stderr))
- return error("failed to redirect stderr to /dev/null: "
-     "%s", strerror(errno));
+ return error_errno("failed to redirect stderr to /dev/null");
  }
 
  if (prefix)
@@ -95,12 +94,13 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
  FILE *f = to_stdout ? stdout : fopen(fpath, "wb");
 
  if (!f)
- ret = error("Could not open %s for writing", filename);
+ ret = error_errno("Could not open %s for writing",
+  filename);
  else if (result.size &&
  fwrite(result.ptr, result.size, 1, f) != 1)
- ret = error("Could not write to %s", filename);
+ ret = error_errno("Could not write to %s", filename);
  else if (fclose(f))
- ret = error("Could not close %s", filename);
+ ret = error_errno("Could not close %s", filename);
  free(result.ptr);
  }
 
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 10/41] builtin/pack-objects.c: use die_errno() and warning_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/pack-objects.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a27de5b..e18e190 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -828,8 +828,7 @@ static void write_pack_file(void)
  * to preserve this property.
  */
  if (stat(pack_tmp_name, &st) < 0) {
- warning("failed to stat %s: %s",
- pack_tmp_name, strerror(errno));
+ warning_errno("failed to stat %s", pack_tmp_name);
  } else if (!last_mtime) {
  last_mtime = st.st_mtime;
  } else {
@@ -837,8 +836,7 @@ static void write_pack_file(void)
  utb.actime = st.st_atime;
  utb.modtime = --last_mtime;
  if (utime(pack_tmp_name, &utb) < 0)
- warning("failed utime() on %s: %s",
- pack_tmp_name, strerror(errno));
+ warning_errno("failed utime() on %s", pack_tmp_name);
  }
 
  strbuf_addf(&tmpname, "%s-", base_name);
@@ -2020,7 +2018,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
  ret = pthread_create(&p[i].thread, NULL,
      threaded_find_deltas, &p[i]);
  if (ret)
- die("unable to create thread: %s", strerror(ret));
+ die_errno("unable to create thread");
  active_threads++;
  }
 
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 11/41] builtin/rm.c: use warning_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/rm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 8829b09..13b9639 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)
 
  if (lstat(ce->name, &st) < 0) {
  if (errno != ENOENT && errno != ENOTDIR)
- warning("'%s': %s", ce->name, strerror(errno));
+ warning_errno("'%s'", ce->name);
  /* It already vanished from the working tree */
  continue;
  }
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 12/41] builtin/update-index.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
"err" is deleted because it just causes confusion when "errno" is also
used directly in process_lstat_error().

Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/update-index.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 1c94ca5..0c539ed 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -251,11 +251,11 @@ static int remove_one_path(const char *path)
  *    succeeds.
  *  - permission error. That's never ok.
  */
-static int process_lstat_error(const char *path, int err)
+static int process_lstat_error(const char *path)
 {
- if (err == ENOENT || err == ENOTDIR)
+ if (errno == ENOENT || errno == ENOTDIR)
  return remove_one_path(path);
- return error("lstat(\"%s\"): %s", path, strerror(errno));
+ return error_errno("lstat(\"%s\")", path);
 }
 
 static int add_one_path(const struct cache_entry *old, const char *path, int len, struct stat *st)
@@ -382,7 +382,7 @@ static int process_path(const char *path)
  * what to do about the pathname!
  */
  if (lstat(path, &st) < 0)
- return process_lstat_error(path, errno);
+ return process_lstat_error(path);
 
  if (S_ISDIR(st.st_mode))
  return process_directory(path, len, &st);
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 13/41] builtin/upload-archive.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/upload-archive.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index dbfe14f..2caedf1 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -104,8 +104,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
  pfd[1].events = POLLIN;
  if (poll(pfd, 2, -1) < 0) {
  if (errno != EINTR) {
- error("poll failed resuming: %s",
-      strerror(errno));
+ error_errno("poll failed resuming");
  sleep(1);
  }
  continue;
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 14/41] builtin/worktree.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 builtin/worktree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index d8e3795..331ecf6 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -110,7 +110,7 @@ static void prune_worktrees(void)
  if (ret < 0 && errno == ENOTDIR)
  ret = unlink(path.buf);
  if (ret)
- error(_("failed to remove: %s"), strerror(errno));
+ error_errno(_("failed to remove '%s'"), path.buf);
  }
  closedir(dir);
  if (!show_only)
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 15/41] check-racy.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 check-racy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/check-racy.c b/check-racy.c
index 00d92a1..24b6542 100644
--- a/check-racy.c
+++ b/check-racy.c
@@ -12,7 +12,7 @@ int main(int ac, char **av)
  struct stat st;
 
  if (lstat(ce->name, &st)) {
- error("lstat(%s): %s", ce->name, strerror(errno));
+ error_errno("lstat(%s)", ce->name);
  continue;
  }
 
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 16/41] combine-diff.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 combine-diff.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/combine-diff.c b/combine-diff.c
index 0e1d4b0..8f2313d 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1005,8 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
  struct strbuf buf = STRBUF_INIT;
 
  if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) {
- error("readlink(%s): %s", elem->path,
-      strerror(errno));
+ error_errno("readlink(%s)", elem->path);
  return;
  }
  result_size = buf.len;
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 17/41] compat/win32/syslog.c: use warning_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 compat/win32/syslog.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
index b905aea..1c2ae18 100644
--- a/compat/win32/syslog.c
+++ b/compat/win32/syslog.c
@@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...)
  va_end(ap);
 
  if (str_len < 0) {
- warning("vsnprintf failed: '%s'", strerror(errno));
+ warning_errno("vsnprintf failed:");
  return;
  }
 
  str = malloc(st_add(str_len, 1));
  if (!str) {
- warning("malloc failed: '%s'", strerror(errno));
+ warning_errno("malloc failed");
  return;
  }
 
@@ -45,7 +45,7 @@ void syslog(int priority, const char *fmt, ...)
  while ((pos = strstr(str, "%1")) != NULL) {
  str = realloc(str, st_add(++str_len, 1));
  if (!str) {
- warning("realloc failed: '%s'", strerror(errno));
+ warning_errno("realloc failed");
  return;
  }
  memmove(pos + 2, pos + 1, strlen(pos));
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 18/41] config.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 config.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/config.c b/config.c
index 10b5c95..80411e4 100644
--- a/config.c
+++ b/config.c
@@ -2012,7 +2012,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
  lock = xcalloc(1, sizeof(struct lock_file));
  fd = hold_lock_file_for_update(lock, config_filename, 0);
  if (fd < 0) {
- error("could not lock config file %s: %s", config_filename, strerror(errno));
+ error_errno("could not lock config file %s", config_filename);
  free(store.key);
  ret = CONFIG_NO_LOCK;
  goto out_free;
@@ -2026,8 +2026,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
  free(store.key);
 
  if ( ENOENT != errno ) {
- error("opening %s: %s", config_filename,
-      strerror(errno));
+ error_errno("opening %s", config_filename);
  ret = CONFIG_INVALID_FILE; /* same as "invalid config file" */
  goto out_free;
  }
@@ -2111,8 +2110,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
  if (contents == MAP_FAILED) {
  if (errno == ENODEV && S_ISDIR(st.st_mode))
  errno = EISDIR;
- error("unable to mmap '%s': %s",
-      config_filename, strerror(errno));
+ error_errno("unable to mmap '%s'", config_filename);
  ret = CONFIG_INVALID_FILE;
  contents = NULL;
  goto out_free;
@@ -2121,8 +2119,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
  in_fd = -1;
 
  if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
- error("chmod on %s failed: %s",
-      get_lock_file_path(lock), strerror(errno));
+ error_errno("chmod on %s failed", get_lock_file_path(lock));
  ret = CONFIG_NO_WRITE;
  goto out_free;
  }
@@ -2178,8 +2175,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
  }
 
  if (commit_lock_file(lock) < 0) {
- error("could not write config file %s: %s", config_filename,
-      strerror(errno));
+ error_errno("could not write config file %s", config_filename);
  ret = CONFIG_NO_WRITE;
  lock = NULL;
  goto out_free;
@@ -2330,8 +2326,8 @@ int git_config_rename_section_in_file(const char *config_filename,
  fstat(fileno(config_file), &st);
 
  if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
- ret = error("chmod on %s failed: %s",
-    get_lock_file_path(lock), strerror(errno));
+ ret = error_errno("chmod on %s failed",
+  get_lock_file_path(lock));
  goto out;
  }
 
@@ -2385,8 +2381,8 @@ int git_config_rename_section_in_file(const char *config_filename,
  fclose(config_file);
 unlock_and_out:
  if (commit_lock_file(lock) < 0)
- ret = error("could not write config file %s: %s",
-    config_filename, strerror(errno));
+ ret = error_errno("could not write config file %s",
+  config_filename);
 out:
  free(filename_buf);
  return ret;
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH 19/41] connected.c: use error_errno()

Duy Nguyen
In reply to this post by Duy Nguyen
Signed-off-by: Nguyễn Thái Ngọc Duy <[hidden email]>
---
 connected.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/connected.c b/connected.c
index 299c560..bf1b12e 100644
--- a/connected.c
+++ b/connected.c
@@ -86,17 +86,14 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
  memcpy(commit, sha1_to_hex(sha1), 40);
  if (write_in_full(rev_list.in, commit, 41) < 0) {
  if (errno != EPIPE && errno != EINVAL)
- error(_("failed write to rev-list: %s"),
-      strerror(errno));
+ error_errno(_("failed write to rev-list"));
  err = -1;
  break;
  }
  } while (!fn(cb_data, sha1));
 
- if (close(rev_list.in)) {
- error(_("failed to close rev-list's stdin: %s"), strerror(errno));
- err = -1;
- }
+ if (close(rev_list.in))
+ err = error_errno(_("failed to close rev-list's stdin"));
 
  sigchain_pop(SIGPIPE);
  return finish_command(&rev_list) || err;
--
2.8.0.rc0.210.gd302cd2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
1234 ... 8