Merge branch 'jc/refactor-diff-stdin' into maint · jaredwy/git@106ef55 · GitHub
Skip to content

Commit 106ef55

Browse files
committed
Merge branch 'jc/refactor-diff-stdin' into maint
"git diff", "git status" and anything that internally uses the comparison machinery was utterly broken when the difference involved a file with "-" as its name. This was due to the way "git diff --no-index" was incorrectly bolted on to the system, making any comparison that involves a file "-" at the root level incorrectly read from the standard input. * jc/refactor-diff-stdin: diff-index.c: "git diff" has no need to read blob from the standard input diff-index.c: unify handling of command line paths diff-index.c: do not pretend paths are pathspecs
2 parents 07873ca + 4682d85 commit 106ef55

4 files changed

Lines changed: 67 additions & 50 deletions

File tree

diff-no-index.c

Lines changed: 53 additions & 30 deletions

diff.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,22 +2619,6 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
26192619
return 0;
26202620
}
26212621

2622-
static int populate_from_stdin(struct diff_filespec *s)
2623-
{
2624-
struct strbuf buf = STRBUF_INIT;
2625-
size_t size = 0;
2626-
2627-
if (strbuf_read(&buf, 0, 0) < 0)
2628-
return error("error while reading from stdin %s",
2629-
strerror(errno));
2630-
2631-
s->should_munmap = 0;
2632-
s->data = strbuf_detach(&buf, &size);
2633-
s->size = size;
2634-
s->should_free = 1;
2635-
return 0;
2636-
}
2637-
26382622
static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
26392623
{
26402624
int len;
@@ -2684,9 +2668,6 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
26842668
struct stat st;
26852669
int fd;
26862670

2687-
if (!strcmp(s->path, "-"))
2688-
return populate_from_stdin(s);
2689-
26902671
if (lstat(s->path, &st) < 0) {
26912672
if (errno == ENOENT) {
26922673
err_empty:
@@ -3048,7 +3029,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
30483029
if (DIFF_FILE_VALID(one)) {
30493030
if (!one->sha1_valid) {
30503031
struct stat st;
3051-
if (!strcmp(one->path, "-")) {
3032+
if (one->is_stdin) {
30523033
hashcpy(one->sha1, null_sha1);
30533034
return;
30543035
}

diffcore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct diff_filespec {
4343
unsigned should_free : 1; /* data should be free()'ed */
4444
unsigned should_munmap : 1; /* data should be munmap()'ed */
4545
unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
46+
unsigned is_stdin : 1;
4647
#define DIRTY_SUBMODULE_UNTRACKED 1
4748
#define DIRTY_SUBMODULE_MODIFIED 2
4849
unsigned has_more_entries : 1; /* only appear in combined diff */

t/t7501-commit.sh

Lines changed: 12 additions & 0 deletions

0 commit comments

Comments
 (0)