⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diff_file.c

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
                      const char *ancestor,                      const svn_diff_file_options_t *options,                      apr_pool_t *pool){  svn_diff__file_baton_t baton;  memset(&baton, 0, sizeof(baton));  baton.options = options;  baton.path[0] = original;  baton.path[1] = modified;  baton.path[2] = latest;  baton.path[3] = ancestor;  baton.pool = svn_pool_create(pool);  SVN_ERR(svn_diff_diff4(diff, &baton, &svn_diff__file_vtable, pool));  svn_pool_destroy(baton.pool);  return SVN_NO_ERROR;}svn_error_t *svn_diff_file_diff4(svn_diff_t **diff,                    const char *original,                    const char *modified,                    const char *latest,                    const char *ancestor,                    apr_pool_t *pool){  return svn_diff_file_diff4_2(diff, original, modified, latest, ancestor,                               svn_diff_file_options_create(pool), pool);}/** Display unified context diffs **/#define SVN_DIFF__UNIFIED_CONTEXT_SIZE 3typedef struct svn_diff__file_output_baton_t{  svn_stream_t *output_stream;  const char *header_encoding;  /* Cached markers, in header_encoding. */  const char *context_str;  const char *delete_str;  const char *insert_str;  const char *path[2];  apr_file_t *file[2];  apr_off_t   current_line[2];  char        buffer[2][4096];  apr_size_t  length[2];  char       *curp[2];  apr_off_t   hunk_start[2];  apr_off_t   hunk_length[2];  svn_stringbuf_t *hunk;  apr_pool_t *pool;} svn_diff__file_output_baton_t;typedef enum svn_diff__file_output_unified_type_e{  svn_diff__file_output_unified_skip,  svn_diff__file_output_unified_context,  svn_diff__file_output_unified_delete,  svn_diff__file_output_unified_insert} svn_diff__file_output_unified_type_e;static svn_error_t *svn_diff__file_output_unified_line(svn_diff__file_output_baton_t *baton,                                   svn_diff__file_output_unified_type_e type,                                   int idx){  char *curp;  char *eol;  apr_size_t length;  svn_error_t *err;  svn_boolean_t bytes_processed = FALSE;  svn_boolean_t had_cr = FALSE;  length = baton->length[idx];  curp = baton->curp[idx];  /* Lazily update the current line even if we're at EOF.   * This way we fake output of context at EOF   */  baton->current_line[idx]++;  if (length == 0 && apr_file_eof(baton->file[idx]))    {      return SVN_NO_ERROR;    }  do    {      if (length > 0)        {          if (!bytes_processed)            {              switch (type)                {                case svn_diff__file_output_unified_context:                  svn_stringbuf_appendcstr(baton->hunk, baton->context_str);                  baton->hunk_length[0]++;                  baton->hunk_length[1]++;                  break;                case svn_diff__file_output_unified_delete:                  svn_stringbuf_appendcstr(baton->hunk, baton->delete_str);                  baton->hunk_length[0]++;                  break;                case svn_diff__file_output_unified_insert:                  svn_stringbuf_appendcstr(baton->hunk, baton->insert_str);                  baton->hunk_length[1]++;                  break;                default:                  break;                }            }          eol = find_eol_start(curp, length);          if (eol != NULL)            {              apr_size_t len;              had_cr = (*eol == '\r');              eol++;              len = (apr_size_t)(eol - curp);              if (! had_cr || len < length)                {                  if (had_cr && *eol == '\n')                    {                      ++eol;                      ++len;                    }                  length -= len;                  if (type != svn_diff__file_output_unified_skip)                    {                      svn_stringbuf_appendbytes(baton->hunk, curp, len);                    }                                    baton->curp[idx] = eol;                  baton->length[idx] = length;                  err = SVN_NO_ERROR;                  break;                }            }          if (type != svn_diff__file_output_unified_skip)            {              svn_stringbuf_appendbytes(baton->hunk, curp, length);            }          bytes_processed = TRUE;        }      curp = baton->buffer[idx];      length = sizeof(baton->buffer[idx]);      err = svn_io_file_read(baton->file[idx], curp, &length, baton->pool);      /* If the last chunk ended with a CR, we look for an LF at the start         of this chunk. */      if (had_cr)        {          if (! err && length > 0 && *curp == '\n')            {              if (type != svn_diff__file_output_unified_skip)                {                  svn_stringbuf_appendbytes(baton->hunk, curp, 1);                }              ++curp;              --length;            }          baton->curp[idx] = curp;          baton->length[idx] = length;          break;        }    }  while (! err);  if (err && ! APR_STATUS_IS_EOF(err->apr_err))    return err;  if (err && APR_STATUS_IS_EOF(err->apr_err))    {      svn_error_clear(err);      /* Special case if we reach the end of file AND the last line is in the         changed range AND the file doesn't end with a newline */      if (bytes_processed && (type != svn_diff__file_output_unified_skip)          && ! had_cr)        {          const char *out_str;          SVN_ERR(svn_utf_cstring_from_utf8_ex2                  (&out_str,                   apr_psprintf(baton->pool,                                _("%s\\ No newline at end of file%s"),                                APR_EOL_STR, APR_EOL_STR),                   baton->header_encoding, baton->pool));          svn_stringbuf_appendcstr(baton->hunk, out_str);        }      baton->length[idx] = 0;    }  return SVN_NO_ERROR;}static svn_error_t *svn_diff__file_output_unified_flush_hunk(svn_diff__file_output_baton_t *baton){  apr_off_t target_line;  apr_size_t hunk_len;  int i;  if (svn_stringbuf_isempty(baton->hunk))    {      /* Nothing to flush */      return SVN_NO_ERROR;    }  target_line = baton->hunk_start[0] + baton->hunk_length[0]                + SVN_DIFF__UNIFIED_CONTEXT_SIZE;  /* Add trailing context to the hunk */  while (baton->current_line[0] < target_line)    {      SVN_ERR(svn_diff__file_output_unified_line              (baton, svn_diff__file_output_unified_context, 0));    }  /* If the file is non-empty, convert the line indexes from     zero based to one based */  for (i = 0; i < 2; i++)    {      if (baton->hunk_length[i] > 0)        baton->hunk_start[i]++;    }  /* Output the hunk header.  If the hunk length is 1, the file is a one line     file.  In this case, surpress the number of lines in the hunk (it is     1 implicitly)    */  SVN_ERR(svn_stream_printf_from_utf8(baton->output_stream,                                      baton->header_encoding,                                      baton->pool,                                      "@@ -%" APR_OFF_T_FMT,                                      baton->hunk_start[0]));  if (baton->hunk_length[0] != 1)    {      SVN_ERR(svn_stream_printf_from_utf8(baton->output_stream,                                          baton->header_encoding,                                          baton->pool, ",%" APR_OFF_T_FMT,                                          baton->hunk_length[0]));    }  SVN_ERR(svn_stream_printf_from_utf8(baton->output_stream,                                      baton->header_encoding,                                      baton->pool, " +%" APR_OFF_T_FMT,                                      baton->hunk_start[1]));  if (baton->hunk_length[1] != 1)    {      SVN_ERR(svn_stream_printf_from_utf8(baton->output_stream,                                          baton->header_encoding,                                          baton->pool, ",%" APR_OFF_T_FMT,                                          baton->hunk_length[1]));    }  SVN_ERR(svn_stream_printf_from_utf8(baton->output_stream,                                      baton->header_encoding,                                      baton->pool, " @@" APR_EOL_STR));  /* Output the hunk content */  hunk_len = baton->hunk->len;  SVN_ERR(svn_stream_write(baton->output_stream, baton->hunk->data,                           &hunk_len));  /* Prepare for the next hunk */  baton->hunk_length[0] = 0;  baton->hunk_length[1] = 0;  svn_stringbuf_setempty(baton->hunk);  return SVN_NO_ERROR;}static svn_error_t *svn_diff__file_output_unified_diff_modified(void *baton,  apr_off_t original_start, apr_off_t original_length,  apr_off_t modified_start, apr_off_t modified_length,  apr_off_t latest_start, apr_off_t latest_length){  svn_diff__file_output_baton_t *output_baton = baton;  apr_off_t target_line[2];  int i;  target_line[0] = original_start >= SVN_DIFF__UNIFIED_CONTEXT_SIZE                   ? original_start - SVN_DIFF__UNIFIED_CONTEXT_SIZE : 0;  target_line[1] = modified_start;  /* If the changed ranges are far enough apart (no overlapping or connecting     context), flush the current hunk, initialize the next hunk and skip the     lines not in context.  Also do this when this is the first hunk.   */  if (output_baton->current_line[0] < target_line[0]      && (output_baton->hunk_start[0] + output_baton->hunk_length[0]          + SVN_DIFF__UNIFIED_CONTEXT_SIZE < target_line[0]          || output_baton->hunk_length[0] == 0))    {      SVN_ERR(svn_diff__file_output_unified_flush_hunk(output_baton));      output_baton->hunk_start[0] = target_line[0];      output_baton->hunk_start[1] = target_line[1] + target_line[0]                                    - original_start;      /* Skip lines until we are at the beginning of the context we want to         display */      while (output_baton->current_line[0] < target_line[0])        {          SVN_ERR(svn_diff__file_output_unified_line                  (output_baton,                   svn_diff__file_output_unified_skip, 0));        }    }  /* Skip lines until we are at the start of the changed range */  while (output_baton->current_line[1] < target_line[1])    {      SVN_ERR(svn_diff__file_output_unified_line              (output_baton, svn_diff__file_output_unified_skip, 1));    }  /* Output the context preceding the changed range */  while (output_baton->current_line[0] < original_start)    {      SVN_ERR(svn_diff__file_output_unified_line              (output_baton, svn_diff__file_output_unified_context, 0));    }  target_line[0] = original_start + original_length;  target_line[1] = modified_start + modified_length;  /* Output the changed range */  for (i = 0; i < 2; i++)    {      while (output_baton->current_line[i] < target_line[i])        {          SVN_ERR(svn_diff__file_output_unified_line                  (output_baton, i == 0                   ? svn_diff__file_output_unified_delete                   : svn_diff__file_output_unified_insert, i));        }    }  return SVN_NO_ERROR;}/* Set *HEADER to a new string consisting of PATH, a tab, and PATH's mtime. */static svn_error_t *svn_diff__file_output_unified_default_hdr(const char **header,                                          const char *path,                                          apr_pool_t *pool){  apr_finfo_t file_info;  apr_time_exp_t exploded_time;  char time_buffer[64];  apr_size_t time_len;  SVN_ERR(svn_io_stat(&file_info, path, APR_FINFO_MTIME, pool));  apr_time_exp_lt(&exploded_time, file_info.mtime);  apr_strftime(time_buffer, &time_len, sizeof(time_buffer) - 1,               "%a %b %e %H:%M:%S %Y", &exploded_time);  *header = apr_psprintf(pool, "%s\t%s", path, time_buffer);  return SVN_NO_ERROR;}static const svn_diff_output_fns_t svn_diff__file_output_unified_vtable ={  NULL, /* output_common */  svn_diff__file_output_unified_diff_modified,  NULL, /* output_diff_latest */  NULL, /* output_diff_common */  NULL  /* output_conflict */};svn_error_t *svn_diff_file_output_unified2(svn_stream_t *output_stream,                              svn_diff_t *diff,                              const char *original_path,                              const char *modified_path,                              const char *original_header,                              const char *modified_header,                              const char *header_encoding,                              apr_pool_t *pool)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -