Ticket #2863: mc.dviewer_mergeother.diff

File mc.dviewer_mergeother.diff, 10.1 KB (added by szaszg, 12 years ago)
  • lib/keybind.c

    diff --git a/lib/keybind.c b/lib/keybind.c
    index 7957769..eedea6b 100644
    a b static name_keymap_t command_names[] = { 
    353353    {"HunkPrev", CK_HunkPrev}, 
    354354    {"EditOther", CK_EditOther}, 
    355355    {"Merge", CK_Merge}, 
     356    {"MergeOther", CK_MergeOther}, 
    356357#endif /* USE_DIFF_VIEW */ 
    357358 
    358359    {NULL, CK_IgnoreKey} 
  • lib/keybind.h

    diff --git a/lib/keybind.h b/lib/keybind.h
    index 1258b44..5bfb81b 100644
    a b enum 
    328328    CK_HunkNext, 
    329329    CK_HunkPrev, 
    330330    CK_EditOther, 
    331     CK_Merge 
     331    CK_Merge, 
     332    CK_MergeOther 
    332333}; 
    333334 
    334335/*** structures declarations (and typedefs of structures)*****************************************/ 
  • src/diffviewer/internal.h

    diff --git a/src/diffviewer/internal.h b/src/diffviewer/internal.h
    index bdd2c29..60e7e21 100644
    a b typedef struct WDiff 
    8484    char *label[2]; 
    8585    FBUF *f[2]; 
    8686    const char *backup_sufix; 
    87     gboolean merged; 
     87    gboolean merged[2]; 
    8888    GArray *a[2]; 
    8989    GPtrArray *hdiff; 
    9090    int ndiff;                  /* number of hunks */ 
  • src/diffviewer/ydiff.c

    diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c
    index 538751a..8146ec9 100644
    a b get_current_hunk (WDiff * dview, int *start_line1, int *end_line1, int *start_li 
    20612061} 
    20622062 
    20632063static void 
    2064 dview_remove_hunk (WDiff * dview, FILE * merge_file, int from1, int to1) 
     2064dview_remove_hunk (WDiff * dview, FILE * merge_file, int from1, int to1, int other) 
    20652065{ 
    20662066    int line; 
    20672067    char buf[BUF_10K]; 
    20682068    FILE *f0; 
    2069     f0 = fopen (dview->file[0], "r"); 
     2069    f0 = fopen (dview->file[other], "r"); 
    20702070    line = 0; 
    20712071    while (fgets (buf, sizeof (buf), f0) != NULL && line < from1 - 1) 
    20722072    { 
    dview_remove_hunk (WDiff * dview, FILE * merge_file, int from1, int to1) 
    20832083} 
    20842084 
    20852085static void 
    2086 dview_add_hunk (WDiff * dview, FILE * merge_file, int from1, int from2, int to2) 
     2086dview_add_hunk (WDiff * dview, FILE * merge_file, int from1, int from2, int to2, int other) 
    20872087{ 
    20882088    int line; 
    20892089    char buf[BUF_10K]; 
    20902090    FILE *f0; 
    20912091    FILE *f1; 
    2092     f0 = fopen (dview->file[0], "r"); 
    2093     f1 = fopen (dview->file[1], "r"); 
     2092    f0 = fopen (dview->file[other], "r"); 
     2093    f1 = fopen (dview->file[1-other], "r"); 
    20942094    line = 0; 
    20952095    while (fgets (buf, sizeof (buf), f0) != NULL && line < from1 - 1) 
    20962096    { 
    dview_add_hunk (WDiff * dview, FILE * merge_file, int from1, int from2, int to2) 
    21132113} 
    21142114 
    21152115static void 
    2116 dview_replace_hunk (WDiff * dview, FILE * merge_file, int from1, int to1, int from2, int to2) 
     2116dview_replace_hunk (WDiff * dview, FILE * merge_file, int from1, int to1, int from2, int to2, int other) 
    21172117{ 
    21182118    int line1, line2; 
    21192119    char buf[BUF_10K]; 
    21202120    FILE *f0; 
    21212121    FILE *f1; 
    2122     f0 = fopen (dview->file[0], "r"); 
    2123     f1 = fopen (dview->file[1], "r"); 
     2122    f0 = fopen (dview->file[other], "r"); 
     2123    f1 = fopen (dview->file[1-other], "r"); 
    21242124    line1 = 0; 
    21252125    while (fgets (buf, sizeof (buf), f0) != NULL && line1 < from1 - 1) 
    21262126    { 
    dview_replace_hunk (WDiff * dview, FILE * merge_file, int from1, int to1, int fr 
    21452145} 
    21462146 
    21472147static void 
    2148 do_merge_hunk (WDiff * dview) 
     2148do_merge_hunk (WDiff * dview, int other) 
    21492149{ 
    21502150    int from1, to1, from2, to2; 
    21512151    int res; 
    21522152    int hunk; 
    21532153 
    2154     hunk = get_current_hunk (dview, &from1, &to1, &from2, &to2); 
     2154    if (other) 
     2155        hunk = get_current_hunk (dview, &from2, &to2, &from1, &to1); 
     2156    else 
     2157        hunk = get_current_hunk (dview, &from1, &to1, &from2, &to2); 
    21552158    if (hunk > 0) 
    21562159    { 
    21572160        int merge_file_fd; 
    21582161        FILE *merge_file; 
    21592162        vfs_path_t *merge_file_name_vpath = NULL; 
    21602163 
    2161         if (!dview->merged) 
     2164        if (!dview->merged[other]) 
    21622165        { 
    2163             dview->merged = mc_util_make_backup_if_possible (dview->file[0], "~~~"); 
    2164             if (!dview->merged) 
     2166            dview->merged[other] = mc_util_make_backup_if_possible (dview->file[other], "~~~"); 
     2167            if (!dview->merged[other]) 
    21652168            { 
    21662169                message (D_ERROR, MSG_ERROR, 
    21672170                         _("Cannot create backup file\n%s%s\n%s"), 
    2168                          dview->file[0], "~~~", unix_error_string (errno)); 
     2171                         dview->file[other], "~~~", unix_error_string (errno)); 
    21692172                return; 
    21702173            } 
    21712174 
    do_merge_hunk (WDiff * dview) 
    21842187        switch (hunk) 
    21852188        { 
    21862189        case DIFF_DEL: 
    2187             dview_remove_hunk (dview, merge_file, from1, to1); 
     2190            if (other) 
     2191                dview_add_hunk (dview, merge_file, from1, from2, to2, other); 
     2192            else 
     2193                dview_remove_hunk (dview, merge_file, from1, to1, other); 
    21882194            break; 
    21892195        case DIFF_ADD: 
    2190             dview_add_hunk (dview, merge_file, from1, from2, to2); 
     2196            if (other) 
     2197                dview_remove_hunk (dview, merge_file, from1, to1, other); 
     2198            else 
     2199                dview_add_hunk (dview, merge_file, from1, from2, to2, other); 
    21912200            break; 
    21922201        case DIFF_CHG: 
    2193             dview_replace_hunk (dview, merge_file, from1, to1, from2, to2); 
     2202            dview_replace_hunk (dview, merge_file, from1, to1, from2, to2, other); 
    21942203            break; 
    21952204        } 
    21962205        fflush (merge_file); 
    21972206        fclose (merge_file); 
    2198         res = rewrite_backup_content (merge_file_name_vpath, dview->file[0]); 
     2207        res = rewrite_backup_content (merge_file_name_vpath, dview->file[other]); 
    21992208        mc_unlink (merge_file_name_vpath); 
    22002209        vfs_path_free (merge_file_name_vpath); 
    22012210    } 
    dview_init (WDiff * dview, const char *args, const char *file1, const char *file 
    23882397    dview->label[1] = g_strdup (label2); 
    23892398    dview->f[0] = f[0]; 
    23902399    dview->f[1] = f[1]; 
     2400    dview->merged[0] = 0; 
     2401    dview->merged[1] = 0; 
    23912402    dview->hdiff = NULL; 
    23922403    dview->dsrc = dsrc; 
    23932404    dview->converter = str_cnv_from_term; 
    dview_status (const WDiff * dview, int ord, int width, int c) 
    27222733    tty_gotoyx (0, c); 
    27232734    get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs); 
    27242735 
    2725     filename_width = width - 22; 
     2736    filename_width = width - 24; 
    27262737    if (filename_width < 8) 
    27272738        filename_width = 8; 
    27282739 
    dview_status (const WDiff * dview, int ord, int width, int c) 
    27312742    vfs_path_free (vpath); 
    27322743    buf = str_term_trim (path, filename_width); 
    27332744    if (ord == 0) 
    2734         tty_printf ("%-*s %6d+%-4d Col %-4d ", filename_width, buf, linenum, lineofs, 
     2745        tty_printf ("%s%-*s %6d+%-4d Col %-4d ", dview->merged[ord] ? "* " : " ", filename_width, buf, linenum, lineofs, 
    27352746                    dview->skip_cols); 
    27362747    else 
    2737         tty_printf ("%-*s %6d+%-4d Dif %-4d ", filename_width, buf, linenum, lineofs, dview->ndiff); 
     2748        tty_printf ("%s%-*s %6d+%-4d Dif %-4d ", dview->merged[ord] ? "* " : " ", filename_width, buf, linenum, lineofs, dview->ndiff); 
    27382749    g_free (path); 
    27392750} 
    27402751 
    static gboolean 
    28752886dview_save (WDiff * dview) 
    28762887{ 
    28772888    gboolean res = TRUE; 
    2878     if (!dview->merged) 
    2879         return res; 
    2880     res = mc_util_unlink_backup_if_possible (dview->file[0], "~~~"); 
    2881     dview->merged = !res; 
     2889    if (dview->merged[0]) { 
     2890        res = mc_util_unlink_backup_if_possible (dview->file[0], "~~~"); 
     2891        dview->merged[0] = !res; 
     2892    } 
     2893    if (dview->merged[1]) { 
     2894        res = mc_util_unlink_backup_if_possible (dview->file[1], "~~~"); 
     2895        dview->merged[1] = !res; 
     2896    } 
    28822897    return res; 
    28832898} 
    28842899 
    dview_ok_to_exit (WDiff * dview) 
    29542969    gboolean res = TRUE; 
    29552970    int act; 
    29562971 
    2957     if (!dview->merged) 
     2972    if (!dview->merged[0] && !dview->merged[1]) 
    29582973        return res; 
    29592974 
    29602975    act = query_dialog (_("Quit"), !mc_global.midnight_shutdown ? 
    2961                         _("File was modified. Save with exit?") : 
    2962                         _("Midnight Commander is being shut down.\nSave modified file?"), 
     2976                        _("File(s) was modified. Save with exit?") : 
     2977                        _("Midnight Commander is being shut down.\nSave modified file(s)?"), 
    29632978                        D_NORMAL, 2, _("&Yes"), _("&No")); 
    29642979 
    29652980    /* Esc is No */ 
    dview_ok_to_exit (WDiff * dview) 
    29782993    case 1:                    /* No */ 
    29792994        if (mc_util_restore_from_backup_if_possible (dview->file[0], "~~~")) 
    29802995            res = mc_util_unlink_backup_if_possible (dview->file[0], "~~~"); 
     2996        if (mc_util_restore_from_backup_if_possible (dview->file[1], "~~~")) 
     2997            res = mc_util_unlink_backup_if_possible (dview->file[1], "~~~"); 
    29812998        /* fall through */ 
    29822999    default: 
    29833000        res = TRUE; 
    dview_execute_cmd (WDiff * dview, unsigned long command) 
    30613078        dview_edit (dview, dview->ord); 
    30623079        break; 
    30633080    case CK_Merge: 
    3064         do_merge_hunk (dview); 
     3081        do_merge_hunk (dview, 0); 
     3082        dview_redo (dview); 
     3083        break; 
     3084    case CK_MergeOther: 
     3085        do_merge_hunk (dview, 1); 
    30653086        dview_redo (dview); 
    30663087        break; 
    30673088    case CK_EditOther: 
    static char * 
    32753296dview_get_title (const Dlg_head * h, size_t len) 
    32763297{ 
    32773298    const WDiff *dview = (const WDiff *) find_widget_type (h, dview_callback); 
    3278     const char *modified = dview->merged ? " (*) " : "     "; 
     3299    const char *modified = " (*) "; 
     3300    const char *notmodified = "     "; 
    32793301    size_t len1; 
    32803302    GString *title; 
    32813303 
    dview_get_title (const Dlg_head * h, size_t len) 
    32833305 
    32843306    title = g_string_sized_new (len); 
    32853307    g_string_append (title, _("Diff:")); 
    3286     g_string_append (title, modified); 
     3308    g_string_append (title, dview->merged[0] ? modified : notmodified); 
    32873309    g_string_append (title, str_term_trim (dview->label[0], len1)); 
    32883310    g_string_append (title, " | "); 
     3311    g_string_append (title, dview->merged[1] ? modified : notmodified); 
    32893312    g_string_append (title, str_term_trim (dview->label[1], len1)); 
    32903313 
    32913314    return g_string_free (title, FALSE); 
  • src/keybind-defaults.c

    diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
    index 75ae855..9d3ae1b 100644
    a b static const global_keymap_ini_t default_diff_keymap[] = { 
    525525    {"Edit", "f4"}, 
    526526    {"EditOther", "f14"}, 
    527527    {"Merge", "f5"}, 
     528    {"MergeOther", "f15"}, 
    528529    {"Search", "f7"}, 
    529530    {"SearchContinue", "f17"}, 
    530531    {"Options", "f9"},