Skip to content

Commit

Permalink
Merge branch 'es/checkout-index-temp'
Browse files Browse the repository at this point in the history
"git checkout-index --temp=$target $path" did not work correctly
for paths outside the current subdirectory in the project.

* es/checkout-index-temp:
  checkout-index: fix --temp relative path mangling
  t2004: demonstrate broken relative path printing
  t2004: standardize file naming in symlink test
  t2004: drop unnecessary write-tree/read-tree
  t2004: modernize style
  • Loading branch information
Junio C Hamano committed Jan 12, 2015
2 parents 42618bc + 74c4de5 commit c00e1c5
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 203 deletions.
16 changes: 8 additions & 8 deletions builtin/checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];

static struct checkout state;

static void write_tempfile_record(const char *name, int prefix_length)
static void write_tempfile_record(const char *name, const char *prefix)
{
int i;

Expand All @@ -35,14 +35,14 @@ static void write_tempfile_record(const char *name, int prefix_length)
fputs(topath[checkout_stage], stdout);

putchar('\t');
write_name_quoted(name + prefix_length, stdout, line_termination);
write_name_quoted_relative(name, prefix, stdout, line_termination);

for (i = 0; i < 4; i++) {
topath[i][0] = 0;
}
}

static int checkout_file(const char *name, int prefix_length)
static int checkout_file(const char *name, const char *prefix)
{
int namelen = strlen(name);
int pos = cache_name_pos(name, namelen);
Expand Down Expand Up @@ -71,7 +71,7 @@ static int checkout_file(const char *name, int prefix_length)

if (did_checkout) {
if (to_tempfile)
write_tempfile_record(name, prefix_length);
write_tempfile_record(name, prefix);
return errs > 0 ? -1 : 0;
}

Expand Down Expand Up @@ -106,15 +106,15 @@ static void checkout_all(const char *prefix, int prefix_length)
if (last_ce && to_tempfile) {
if (ce_namelen(last_ce) != ce_namelen(ce)
|| memcmp(last_ce->name, ce->name, ce_namelen(ce)))
write_tempfile_record(last_ce->name, prefix_length);
write_tempfile_record(last_ce->name, prefix);
}
if (checkout_entry(ce, &state,
to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
errs++;
last_ce = ce;
}
if (last_ce && to_tempfile)
write_tempfile_record(last_ce->name, prefix_length);
write_tempfile_record(last_ce->name, prefix);
if (errs)
/* we have already done our error reporting.
* exit with the same code as die().
Expand Down Expand Up @@ -248,7 +248,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
if (read_from_stdin)
die("git checkout-index: don't mix '--stdin' and explicit filenames");
p = prefix_path(prefix, prefix_length, arg);
checkout_file(p, prefix_length);
checkout_file(p, prefix);
if (p < arg || p > arg + strlen(arg))
free((char *)p);
}
Expand All @@ -268,7 +268,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
strbuf_swap(&buf, &nbuf);
}
p = prefix_path(prefix, prefix_length, buf.buf);
checkout_file(p, prefix_length);
checkout_file(p, prefix);
if (p < buf.buf || p > buf.buf + buf.len)
free((char *)p);
}
Expand Down
Loading

0 comments on commit c00e1c5

Please sign in to comment.