[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Unified context diff...

From: Sander Striker <striker_at_apache.org>
Date: 2002-04-27 14:14:13 CEST

Hi,

I just committed the unified context diff output stuff for files.
You can now create your own diff (actually a "diff -u" with three
lines of context). Some sample source is at the end of the mail.

Enjoy!

Sander

---
#include <apr.h>
#include <apr_general.h>
#include <apr_file_io.h>
#include "svn_pools.h"
#include "svn_diff.h"
static
svn_error_t *
do_diff(apr_file_t *output_file,
        const char *original, const char *modified,
        svn_boolean_t *has_changes,
        apr_pool_t *pool)
{
  svn_diff_t *diff;
  SVN_ERR(svn_diff_file(&diff, original, modified, pool));
  *has_changes = svn_diff_contains_diffs(diff);
  SVN_ERR(svn_diff_file_output_unified(output_file, diff,
                                       original, modified,
                                       NULL, NULL, pool));
  return NULL;
}
int main(int argc, char *argv[])
{
  apr_pool_t *pool;
  apr_file_t *output_file;
  int rc;
  apr_initialize();
  pool = svn_pool_create(NULL);
  apr_file_open_stdout(&output_file, pool);
  if (argc == 3)
    {
      svn_boolean_t has_changes;
      svn_error_t *svn_err;
      svn_err = do_diff(output_file, argv[1], argv[2], &has_changes, pool);
      if (svn_err == NULL)
        {
          rc = has_changes ? 1 : 0;
        }
      else
        {
          svn_handle_error(svn_err, stdout, FALSE);
          rc = 2;
        }
    }
  else
    {
      apr_file_printf(output_file, "Usage: %s <file1> <file2>\n", argv[0]);
      rc = 2;
    }
  apr_terminate();
  return rc;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Apr 27 14:08:18 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.