Merge branch 'bp/log-ref-write-fd-with-strbuf'
authorJunio C Hamano <gitster@pobox.com>
Tue, 24 Jul 2018 21:50:47 +0000 (14:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Jul 2018 21:50:47 +0000 (14:50 -0700)
Code clean-up.

* bp/log-ref-write-fd-with-strbuf:
convert log_ref_write_fd() to use strbuf

1  2 
refs.c
refs/refs-internal.h
diff --combined refs.c
index 3b4508a97aa23fa4a16bb64137b01c16b2b4b59d,50fe5c5d2cfcccc168231525979fa0b0fa63acf2..08fb5a99148ab903f8c049479d227392b78775f7
--- 1/refs.c
--- 2/refs.c
+++ b/refs.c
@@@ -9,7 -9,6 +9,7 @@@
  #include "iterator.h"
  #include "refs.h"
  #include "refs/refs-internal.h"
 +#include "object-store.h"
  #include "object.h"
  #include "tag.h"
  #include "submodule.h"
@@@ -787,25 -786,21 +787,21 @@@ int delete_ref(const char *msg, const c
                               old_oid, flags);
  }
  
int copy_reflog_msg(char *buf, const char *msg)
void copy_reflog_msg(struct strbuf *sb, const char *msg)
  {
-       char *cp = buf;
        char c;
        int wasspace = 1;
  
-       *cp++ = '\t';
+       strbuf_addch(sb, '\t');
        while ((c = *msg++)) {
                if (wasspace && isspace(c))
                        continue;
                wasspace = isspace(c);
                if (wasspace)
                        c = ' ';
-               *cp++ = c;
+               strbuf_addch(sb, c);
        }
-       while (buf < cp && isspace(cp[-1]))
-               cp--;
-       *cp++ = '\n';
-       return cp - buf;
+       strbuf_rtrim(sb);
  }
  
  int should_autocreate_reflog(const char *refname)
diff --combined refs/refs-internal.h
index 54bde5089a13bb15584048cf5b18348175790285,17a526078f6987f2962703bd177912a45f830897..04425d6d1e45e2401454e7b89b0ed4b3959926de
@@@ -1,8 -1,6 +1,8 @@@
  #ifndef REFS_REFS_INTERNAL_H
  #define REFS_REFS_INTERNAL_H
  
 +#include "iterator.h"
 +
  /*
   * Data structures and functions for the internal use of the refs
   * module. Code outside of the refs module should use only the public
@@@ -93,11 -91,10 +93,10 @@@ enum peel_status 
  enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
  
  /*
-  * Copy the reflog message msg to buf, which has been allocated sufficiently
-  * large, while cleaning up the whitespaces.  Especially, convert LF to space,
-  * because reflog file is one line per entry.
+  * Copy the reflog message msg to sb while cleaning up the whitespaces.
+  * Especially, convert LF to space, because reflog file is one line per entry.
   */
int copy_reflog_msg(char *buf, const char *msg);
void copy_reflog_msg(struct strbuf *sb, const char *msg);
  
  /**
   * Information needed for a single ref update. Set new_oid to the new