[gnumeric] ssdiff: fix exit code.



commit 5b6db232593fd44ff24f78b47fad4d0577f7b0f1
Author: Morten Welinder <terra gnome org>
Date:   Fri Mar 17 13:31:44 2017 -0400

    ssdiff: fix exit code.
    
    In order to match plain diff, exit 2 on error, 1 of diffs, 0 if no diff.

 ChangeLog    |    2 ++
 NEWS         |    1 +
 doc/ssdiff.1 |    3 +++
 src/ssdiff.c |   33 ++++++++++++++++++++++++++-------
 4 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d7215db..39f1fec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2017-03-17  Morten Welinder  <terra gnome org>
 
+       * src/ssdiff.c (main): Exit 2 on error, 1 of diffs, 0 if no diff.
+
        * src/style-conditions.c (gnm_style_conditions_equal): Add new
        relax_sheet argument.
 
diff --git a/NEWS b/NEWS
index be0b3ea..e024f9d 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Morten:
        * Fix issues with sheet-local names.
        * ssdiff improvements with hyperlinks, input messages,
          conditional formats, and validations.
+       * Make exit code from ssdiff follow diff's.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.33
diff --git a/doc/ssdiff.1 b/doc/ssdiff.1
index 95f8ab8..f528534 100644
--- a/doc/ssdiff.1
+++ b/doc/ssdiff.1
@@ -42,6 +42,9 @@ To compare an old version of a file with a newer file, run:
 \fBssdiff\fR \fIold.gnumeric\fR \fInew.gnumeric\fR
 .PP
 
+The exit code will be 0 if no differences were found, 1 if differences
+were found, and 2 in case of trouble.
+
 .\".SH FILES
 .\".SH ENVIRONMENT
 .\".SH DIAGNOSTICS
diff --git a/src/ssdiff.c b/src/ssdiff.c
index a3fc0c4..f0c8ad7 100644
--- a/src/ssdiff.c
+++ b/src/ssdiff.c
@@ -128,6 +128,8 @@ struct GnmDiffState_ {
 
        const GnmDiffActions *actions;
 
+       gboolean diff_found;
+
        GsfOutput *output;
 
        /* The following for xml mode.  */
@@ -867,17 +869,21 @@ diff_sheets_cells (GnmDiffState *state, Sheet *old_sheet, Sheet *new_sheet)
                        else if (order > 0)
                                co = NULL;
                        else {
-                               if (compare_corresponding_cells (co, cn))
+                               if (compare_corresponding_cells (co, cn)) {
+                                       state->diff_found = TRUE;
                                        state->actions->cell_changed (state, co, cn);
+                               }
                                io++, in++;
                                continue;
                        }
                }
 
                if (co) {
+                       state->diff_found = TRUE;
                        state->actions->cell_changed (state, co, NULL);
                        io++;
                } else if (cn) {
+                       state->diff_found = TRUE;
                        state->actions->cell_changed (state, NULL, cn);
                        in++;
                } else
@@ -890,9 +896,11 @@ diff_sheets_cells (GnmDiffState *state, Sheet *old_sheet, Sheet *new_sheet)
 
 #define DO_INT(field,attr)                                             \
        do {                                                            \
-               if (old_sheet->field != new_sheet->field)               \
+               if (old_sheet->field != new_sheet->field) {             \
+                       state->diff_found = TRUE;                       \
                        state->actions->sheet_attr_int_changed          \
                                (state, attr, old_sheet->field, new_sheet->field); \
+               }                                                       \
 } while (0)
 
 static void
@@ -901,12 +909,16 @@ diff_sheets_attrs (GnmDiffState *state, Sheet *old_sheet, Sheet *new_sheet)
        GnmSheetSize const *os = gnm_sheet_get_size (old_sheet);
        GnmSheetSize const *ns = gnm_sheet_get_size (new_sheet);
 
-       if (os->max_cols != ns->max_cols)
+       if (os->max_cols != ns->max_cols) {
+               state->diff_found = TRUE;
                state->actions->sheet_attr_int_changed
                        (state, "Cols", os->max_cols, ns->max_cols);
-       if (os->max_rows != ns->max_rows)
+       }
+       if (os->max_rows != ns->max_rows) {
+               state->diff_found = TRUE;
                state->actions->sheet_attr_int_changed
                        (state, "Rows", os->max_rows, ns->max_rows);
+       }
 
        DO_INT (display_formulas, "DisplayFormulas");
        DO_INT (hide_zero, "HideZero");
@@ -940,6 +952,8 @@ cb_diff_sheets_styles_2 (G_GNUC_UNUSED gpointer key,
        if (gnm_style_find_differences (data->old_style, sr->style, TRUE) == 0)
                return;
 
+       data->state->diff_found = TRUE;
+
        data->state->actions->style_changed (data->state, &r,
                                             data->old_sheet, data->new_sheet,
                                             data->old_style, sr->style);
@@ -1053,8 +1067,10 @@ diff (char const *oldfilename, char const *newfilename,
                }
        }
 
-       if (sheet_order_changed)
+       if (sheet_order_changed) {
+               state.diff_found = TRUE;
                state.actions->sheet_order_changed (&state);
+       }
 
        state.actions->diff_end (&state);
 
@@ -1070,10 +1086,13 @@ out:
 
        gnm_pop_C_locale (locale);
 
+       if (res == 0)
+               res = state.diff_found ? 1 : 0;
+
        return res;
 
 error:
-       res = 1;
+       res = 2;
        goto out;
 }
 
@@ -1159,7 +1178,7 @@ main (int argc, char const **argv)
                g_printerr (_("Usage: %s [OPTION...] %s\n"),
                            g_get_prgname (),
                            _("OLDFILE NEWFILE"));
-               res = 1;
+               res = 2;
        }
 
        /* Release cached string. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]