Skip to content

Commit c00e1c5

Browse files
committed
Merge branch 'es/checkout-index-temp'
"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
2 parents 42618bc + 74c4de5 commit c00e1c5

File tree

2 files changed

+213
-203
lines changed

2 files changed

+213
-203
lines changed

builtin/checkout-index.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
1818

1919
static struct checkout state;
2020

21-
static void write_tempfile_record(const char *name, int prefix_length)
21+
static void write_tempfile_record(const char *name, const char *prefix)
2222
{
2323
int i;
2424

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

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

4040
for (i = 0; i < 4; i++) {
4141
topath[i][0] = 0;
4242
}
4343
}
4444

45-
static int checkout_file(const char *name, int prefix_length)
45+
static int checkout_file(const char *name, const char *prefix)
4646
{
4747
int namelen = strlen(name);
4848
int pos = cache_name_pos(name, namelen);
@@ -71,7 +71,7 @@ static int checkout_file(const char *name, int prefix_length)
7171

7272
if (did_checkout) {
7373
if (to_tempfile)
74-
write_tempfile_record(name, prefix_length);
74+
write_tempfile_record(name, prefix);
7575
return errs > 0 ? -1 : 0;
7676
}
7777

@@ -106,15 +106,15 @@ static void checkout_all(const char *prefix, int prefix_length)
106106
if (last_ce && to_tempfile) {
107107
if (ce_namelen(last_ce) != ce_namelen(ce)
108108
|| memcmp(last_ce->name, ce->name, ce_namelen(ce)))
109-
write_tempfile_record(last_ce->name, prefix_length);
109+
write_tempfile_record(last_ce->name, prefix);
110110
}
111111
if (checkout_entry(ce, &state,
112112
to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
113113
errs++;
114114
last_ce = ce;
115115
}
116116
if (last_ce && to_tempfile)
117-
write_tempfile_record(last_ce->name, prefix_length);
117+
write_tempfile_record(last_ce->name, prefix);
118118
if (errs)
119119
/* we have already done our error reporting.
120120
* exit with the same code as die().
@@ -248,7 +248,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
248248
if (read_from_stdin)
249249
die("git checkout-index: don't mix '--stdin' and explicit filenames");
250250
p = prefix_path(prefix, prefix_length, arg);
251-
checkout_file(p, prefix_length);
251+
checkout_file(p, prefix);
252252
if (p < arg || p > arg + strlen(arg))
253253
free((char *)p);
254254
}
@@ -268,7 +268,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
268268
strbuf_swap(&buf, &nbuf);
269269
}
270270
p = prefix_path(prefix, prefix_length, buf.buf);
271-
checkout_file(p, prefix_length);
271+
checkout_file(p, prefix);
272272
if (p < buf.buf || p > buf.buf + buf.len)
273273
free((char *)p);
274274
}

0 commit comments

Comments
 (0)