Browse Source

[PATCH] Reworked external diff interface.

This introduces three public functions for diff-cache and friends can
use to call out to the GIT_EXTERNAL_DIFF program when they wish to.

A normal "add/remove/change" entry is turned into 7-parameter process
invocation of GIT_EXTERNAL_DIFF program as before.  In addition, the
program can now be called with a single parameter when diff-cache and
friends want to report an unmerged path. 

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
maint
Junio C Hamano 20 years ago committed by Linus Torvalds
parent
commit
77eb272046
  1. 91
      diff.c
  2. 19
      diff.h

91
diff.c

@ -194,13 +194,15 @@ void run_external_diff(const char *name,
int pid, status; int pid, status;
static int atexit_asked = 0; static int atexit_asked = 0;


prepare_temp_file(name, &temp[0], one); if (one && two) {
prepare_temp_file(name, &temp[1], two); prepare_temp_file(name, &temp[0], one);
if (! atexit_asked && prepare_temp_file(name, &temp[1], two);
(temp[0].name == temp[0].tmp_path || if (! atexit_asked &&
temp[1].name == temp[1].tmp_path)) { (temp[0].name == temp[0].tmp_path ||
atexit_asked = 1; temp[1].name == temp[1].tmp_path)) {
atexit(remove_tempfile); atexit_asked = 1;
atexit(remove_tempfile);
}
} }


fflush(NULL); fflush(NULL);
@ -209,16 +211,23 @@ void run_external_diff(const char *name,
die("unable to fork"); die("unable to fork");
if (!pid) { if (!pid) {
const char *pgm = external_diff(); const char *pgm = external_diff();
if (pgm) if (pgm) {
execlp(pgm, pgm, if (one && two)
name, execlp(pgm, pgm,
temp[0].name, temp[0].hex, temp[0].mode, name,
temp[1].name, temp[1].hex, temp[1].mode, temp[0].name, temp[0].hex, temp[0].mode,
NULL); temp[1].name, temp[1].hex, temp[1].mode,
NULL);
else
execlp(pgm, pgm, name, NULL);
}
/* /*
* otherwise we use the built-in one. * otherwise we use the built-in one.
*/ */
builtin_diff(name, temp); if (one && two)
builtin_diff(name, temp);
else
printf("* Unmerged path %s\n", name);
exit(0); exit(0);
} }
if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status)) if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status))
@ -227,41 +236,55 @@ void run_external_diff(const char *name,
remove_tempfile(); remove_tempfile();
} }


void show_diff_empty(const struct cache_entry *ce, int reverse) void diff_addremove(int addremove, unsigned mode,
const unsigned char *sha1,
const char *base, const char *path)
{ {
char concatpath[PATH_MAX];
struct diff_spec spec[2], *one, *two; struct diff_spec spec[2], *one, *two;


memcpy(spec[0].u.sha1, ce->sha1, 20); memcpy(spec[0].u.sha1, sha1, 20);
spec[0].mode = ntohl(ce->ce_mode); spec[0].mode = mode;
spec[0].sha1_valid = spec[0].file_valid = 1; spec[0].sha1_valid = spec[0].file_valid = 1;
spec[1].file_valid = 0; spec[1].file_valid = 0;


if (reverse) { if (addremove == '+') {
one = spec + 1; two = spec; one = spec + 1; two = spec;
} else { } else {
one = spec; two = one + 1; one = spec; two = one + 1;
} }
run_external_diff(ce->name, one, two); if (path) {
strcpy(concatpath, base);
strcat(concatpath, "/");
strcat(concatpath, path);
}
run_external_diff(path ? concatpath : base, one, two);
} }


void show_differences(const struct cache_entry *ce, int reverse) void diff_change(unsigned old_mode, unsigned new_mode,
{ const unsigned char *old_sha1,
struct diff_spec spec[2], *one, *two; const unsigned char *new_sha1,

const char *base, const char *path) {
memcpy(spec[0].u.sha1, ce->sha1, 20); char concatpath[PATH_MAX];
spec[0].mode = ntohl(ce->ce_mode); struct diff_spec spec[2];

memcpy(spec[0].u.sha1, old_sha1, 20);
spec[0].mode = old_mode;
memcpy(spec[1].u.sha1, new_sha1, 20);
spec[1].mode = new_mode;
spec[0].sha1_valid = spec[0].file_valid = 1; spec[0].sha1_valid = spec[0].file_valid = 1;
spec[1].sha1_valid = spec[1].file_valid = 1;


spec[1].u.name = ce->name; /* the name we stated */ if (path) {
spec[1].sha1_valid = 0; strcpy(concatpath, base);
spec[1].file_valid = 1; strcat(concatpath, "/");

strcat(concatpath, path);
if (reverse) {
one = spec + 1; two = spec;
} else {
one = spec; two = one + 1;
} }
run_external_diff(path ? concatpath : base, &spec[0], &spec[1]);
}


run_external_diff(ce->name, one, two); void diff_unmerge(const char *path)
{
run_external_diff(path, NULL, NULL);
} }

19
diff.h

@ -4,11 +4,20 @@
#ifndef DIFF_H #ifndef DIFF_H
#define DIFF_H #define DIFF_H


/* These two are for backward compatibility with show-diff; extern void diff_addremove(int addremove,
* new users should not use them. unsigned mode,
*/ const unsigned char *sha1,
extern void show_differences(const struct cache_entry *ce, int reverse); const char *base,
extern void show_diff_empty(const struct cache_entry *ce, int reverse); const char *path);

extern void diff_change(unsigned mode1, unsigned mode2,
const unsigned char *sha1,
const unsigned char *sha2,
const char *base, const char *path);

extern void diff_unmerge(const char *path);

/* These are for diff-tree-helper */


struct diff_spec { struct diff_spec {
union { union {

Loading…
Cancel
Save