bug-cvs
[Top][All Lists]
Advanced

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

cvs rdiff -B feature for binary files


From: karl
Subject: cvs rdiff -B feature for binary files
Date: Sun, 21 Apr 2002 10:33:08 -0400 (EDT)

Enclosed is a patch that implements a new option -B to rdiff.  This
tells it not to output the contents of binary files, only the headers.
This is useful because diffs of arbitrary binary files cannot be parsed
by other tools.

In particular, I wrote a tool to show the history of changes made on a
branch since a given date, which uses rdiff.  (I'm happy to share the
tool if anyone wants it.)  It needs -B to get the right output.

It's also necessary to always get the time of the second file in the
diff, so the right time can be shown for removed files.

I posted this before, for 1.11 and 1.11.1, but apparently it never
made it into the sources.  Hope you'll accept it this time.

Thanks,
karl


*** ./ORIG/patch.c      Tue Aug  7 11:35:32 2001
--- ./patch.c   Sat Apr 20 19:46:08 2002
*************** static int force_tag_match = 1;
*** 29,32 ****
--- 29,33 ----
  static int patch_short = 0;
  static int toptwo_diffs = 0;
+ static int binary_file_info = 0;
  static char *options = NULL;
  static char *rev1 = NULL;
*************** static const char *const patch_usage[] =
*** 53,56 ****
--- 54,58 ----
      "\t-t\tTop two diffs - last change made to the file.\n",
      "\t-D date\tDate.\n",
+     "\t-B\tShow headers for binary files.\n",
      "\t-r rev\tRevision - symbolic or numeric.\n",
      "\t-V vers\tUse RCS Version \"vers\" for keyword expansion.\n",
*************** patch (argc, argv)
*** 74,78 ****
  
      optind = 0;
!     while ((c = getopt (argc, argv, "+V:k:cuftsQqlRD:r:")) != -1)
      {
        switch (c)
--- 76,80 ----
  
      optind = 0;
!     while ((c = getopt (argc, argv, "+V:k:cuftsQqlRBD:r:")) != -1)
      {
        switch (c)
*************** patch (argc, argv)
*** 104,107 ****
--- 106,112 ----
                patch_short = 1;
                break;
+           case 'B':
+               binary_file_info = 1;
+               break;
            case 'D':
                if (rev2 != NULL || date2 != NULL)
*************** patch (argc, argv)
*** 208,211 ****
--- 213,218 ----
        if (unidiff)
            send_arg("-u");
+       if (binary_file_info)
+           send_arg("-B");
  
        if (rev1)
*************** patch_fileproc (callerdat, finfo)
*** 390,393 ****
--- 397,402 ----
      FILE *fp;
      int line_length;
+     time_t file2_time = -1;
+     char *diff_options;
  
      line1 = NULL;
*************** patch_fileproc (callerdat, finfo)
*** 417,420 ****
--- 426,430 ----
        if (vers_head != NULL && RCS_isdead (rcsfile, vers_head))
        {
+           file2_time = RCS_getrevtime (rcsfile, vers_head, date2, 1);
            free (vers_head);
            vers_head = NULL;
*************** patch_fileproc (callerdat, finfo)
*** 576,587 ****
            goto out;
        }
!       if ((t.actime = t.modtime = RCS_getrevtime (rcsfile, vers_head,
!                                                   (char *) 0, 0)) != -1)
!           /* I believe this timestamp only affects the dates in our diffs,
!              and therefore should be on the server, not the client.  */
!           (void) utime (tmpfile2, &t);
      }
  
!     switch (diff_exec (tmpfile1, tmpfile2, NULL, NULL, unidiff ? "-u" : "-c", 
tmpfile3))
      {
        case -1:                        /* fork/wait failure */
--- 586,609 ----
            goto out;
        }
!       /* Always get file2_time so we can put the right timestamp in
!          the header even if the file was removed.  */
!       file2_time = RCS_getrevtime (rcsfile, vers_head, (char *) 0, 0);
      }
  
!     /* Set mod time on file2 */
!     if (file2_time != -1)
!     {
!         t.actime = t.modtime = file2_time;
!         /* I believe this timestamp only affects the dates in our diffs,
!            and therefore should be on the server, not the client.  */
!         (void) utime (tmpfile2, &t);
!     }
! 
!     if (unidiff)
!       diff_options = binary_file_info ? "-u --text" : "-u";
!     else
!       diff_options = binary_file_info ? "-c --text" : "-c";
!     
!     switch (diff_exec (tmpfile1, tmpfile2, NULL, NULL, diff_options, 
tmpfile3))
      {
        case -1:                        /* fork/wait failure */
*************** failed to read diff file header %s for %
*** 708,714 ****
  
            /* spew the rest of the diff out */
!           while ((line_length
!                   = getline (&line1, &line1_chars_allocated, fp))
!                  >= 0)
                cvs_output (line1, 0);
            if (line_length < 0 && !feof (fp))
--- 730,738 ----
  
            /* spew the rest of the diff out */
!           line_length = 0;
!           if (!binary_file_info)
!             while ((line_length
!                     = getline (&line1, &line1_chars_allocated, fp))
!                    >= 0)
                cvs_output (line1, 0);
            if (line_length < 0 && !feof (fp))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]