Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-16 02:10:07 +0400
committerRussell Belfer <rb@github.com>2013-10-16 02:10:07 +0400
commit10672e3e455eba2d4ca983070ed427caeeb24a6f (patch)
treee812af06091362849e9ecd279c5547e401cb0862 /examples/diff.c
parent3ff1d123736e5686fb9ec16e65828d5b8ffa2b30 (diff)
Diff API cleanup
This lays groundwork for separating formatting options from diff creation options. This groups the formatting flags separately from the diff list creation flags and reorders the options. This also tweaks some APIs to further separate code that uses patches from code that just looks at git_diffs.
Diffstat (limited to 'examples/diff.c')
-rw-r--r--examples/diff.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/examples/diff.c b/examples/diff.c
index 3200b53c8..2542f4269 100644
--- a/examples/diff.c
+++ b/examples/diff.c
@@ -114,12 +114,6 @@ static void usage(const char *message, const char *arg)
exit(1);
}
-enum {
- FORMAT_PATCH = 0,
- FORMAT_COMPACT = 1,
- FORMAT_RAW = 2
-};
-
int main(int argc, char *argv[])
{
git_repository *repo = NULL;
@@ -127,7 +121,8 @@ int main(int argc, char *argv[])
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
git_diff *diff;
- int i, color = -1, format = FORMAT_PATCH, cached = 0;
+ int i, color = -1, cached = 0;
+ git_diff_format_t format = GIT_DIFF_FORMAT_PATCH;
char *a, *treeish1 = NULL, *treeish2 = NULL;
const char *dir = ".";
@@ -148,13 +143,15 @@ int main(int argc, char *argv[])
}
else if (!strcmp(a, "-p") || !strcmp(a, "-u") ||
!strcmp(a, "--patch"))
- format = FORMAT_PATCH;
+ format = GIT_DIFF_FORMAT_PATCH;
else if (!strcmp(a, "--cached"))
cached = 1;
+ else if (!strcmp(a, "--name-only"))
+ format = GIT_DIFF_FORMAT_NAME_ONLY;
else if (!strcmp(a, "--name-status"))
- format = FORMAT_COMPACT;
+ format = GIT_DIFF_FORMAT_NAME_STATUS;
else if (!strcmp(a, "--raw"))
- format = FORMAT_RAW;
+ format = GIT_DIFF_FORMAT_RAW;
else if (!strcmp(a, "--color"))
color = 0;
else if (!strcmp(a, "--no-color"))
@@ -238,17 +235,7 @@ int main(int argc, char *argv[])
if (color >= 0)
fputs(colors[0], stdout);
- switch (format) {
- case FORMAT_PATCH:
- check(git_diff_print_patch(diff, printer, &color), "Displaying diff");
- break;
- case FORMAT_COMPACT:
- check(git_diff_print_compact(diff, printer, &color), "Displaying diff");
- break;
- case FORMAT_RAW:
- check(git_diff_print_raw(diff, printer, &color), "Displaying diff");
- break;
- }
+ check(git_diff_print(diff, format, printer, &color), "Displaying diff");
if (color >= 0)
fputs(colors[0], stdout);