Merge branch 'ph/strbuf'

* ph/strbuf: (44 commits)
  Make read_patch_file work on a strbuf.
  strbuf_read_file enhancement, and use it.
  strbuf change: be sure ->buf is never ever NULL.
  double free in builtin-update-index.c
  Clean up stripspace a bit, use strbuf even more.
  Add strbuf_read_file().
  rerere: Fix use of an empty strbuf.buf
  Small cache_tree_write refactor.
  Make builtin-rerere use of strbuf nicer and more efficient.
  Add strbuf_cmp.
  strbuf_setlen(): do not barf on setting length of an empty buffer to 0
  sq_quote_argv and add_to_string rework with strbuf's.
  Full rework of quote_c_style and write_name_quoted.
  Rework unquote_c_style to work on a strbuf.
  strbuf API additions and enhancements.
  nfv?asprintf are broken without va_copy, workaround them.
  Fix the expansion pattern of the pseudo-static path buffer.
  builtin-for-each-ref.c::copy_name() - do not overstep the buffer.
  builtin-apply.c: fix a tiny leak introduced during xmemdupz() conversion.
  Use xmemdupz() in many places.
  ...
This commit is contained in:
Junio C Hamano
2007-10-03 03:06:02 -07:00
59 changed files with 1799 additions and 2501 deletions

View File

@ -87,7 +87,6 @@ static int used_atom_cnt, sort_atom_limit, need_tagged;
static int parse_atom(const char *atom, const char *ep)
{
const char *sp;
char *n;
int i, at;
sp = atom;
@ -129,10 +128,7 @@ static int parse_atom(const char *atom, const char *ep)
(sizeof *used_atom) * used_atom_cnt);
used_atom_type = xrealloc(used_atom_type,
(sizeof(*used_atom_type) * used_atom_cnt));
n = xmalloc(ep - atom + 1);
memcpy(n, atom, ep - atom);
n[ep-atom] = 0;
used_atom[at] = n;
used_atom[at] = xmemdupz(atom, ep - atom);
used_atom_type[at] = valid_atom[i].cmp_type;
return at;
}
@ -316,46 +312,28 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un
static const char *copy_line(const char *buf)
{
const char *eol = strchr(buf, '\n');
char *line;
int len;
if (!eol)
return "";
len = eol - buf;
line = xmalloc(len + 1);
memcpy(line, buf, len);
line[len] = 0;
return line;
return xmemdupz(buf, eol - buf);
}
static const char *copy_name(const char *buf)
{
const char *eol = strchr(buf, '\n');
const char *eoname = strstr(buf, " <");
char *line;
int len;
if (!(eoname && eol && eoname < eol))
return "";
len = eoname - buf;
line = xmalloc(len + 1);
memcpy(line, buf, len);
line[len] = 0;
return line;
const char *cp;
for (cp = buf; *cp && *cp != '\n'; cp++) {
if (!strncmp(cp, " <", 2))
return xmemdupz(buf, cp - buf);
}
return "";
}
static const char *copy_email(const char *buf)
{
const char *email = strchr(buf, '<');
const char *eoemail = strchr(email, '>');
char *line;
int len;
if (!email || !eoemail)
return "";
eoemail++;
len = eoemail - email;
line = xmalloc(len + 1);
memcpy(line, email, len);
line[len] = 0;
return line;
return xmemdupz(email, eoemail + 1 - email);
}
static void grab_date(const char *buf, struct atom_value *v, const char *atomname)