Filewatcher File Search
FTP Search
  
Directory (beta)
  
Content Search (beta)
   
pkg://bazaar-debug-1.4.2-2mdv2008.0.i586.rpm:1431198/usr/src/debug/thelove@canonical.com---dists--bazaar--1.4/src/baz/libarch/replay.c  info  downloads

/* replay.c:
 *
 * vim:smartindent ts=8:sts=2:sta:et:ai:shiftwidth=2
 ****************************************************************
 * Copyright (C) 2003 Tom Lord
 *
 * See the file "COPYING" for further information about
 * the copyright and warranty status of this work.
 */


#include "hackerlab/bugs/exception.h"
#include "hackerlab/char/str.h"
#include "hackerlab/fs/file-names.h"
#include "hackerlab/vu/safe.h"
#include "libfsutils/tmp-files.h"
#include "libfsutils/rmrf.h"
#include "libarch/apply-changeset.h"
#include "libarch/namespace.h"
#include "libarch/chatter.h"
#include "libarch/replay.h"


/* __STDC__ prototypes for static functions */
static void replay_callback (void * vfd, char * fmt, va_list ap);



int
arch_replay_exact (int chatter_fd,
                   int no_patch_noise,
                   t_uchar const * tree_root,
                   struct arch_archive * arch,
                   t_uchar const * revision,
                   int reverse,
                   int forward,
                   int escape_classes)
{
  t_uchar * patch_dir_stem = 0;
  t_uchar * patch_dir = 0;
  struct arch_apply_changeset_report * report;
  int status;
  arch_project_tree_t * tree;
  arch_apply_changeset_report_callback report_callback = NULL;
  void * report_thunk = NULL;
  
  tree = arch_project_tree_new (talloc_context, tree_root);

  patch_dir_stem = str_alloc_cat_many (0, ",,patch.", revision, "--", arch->official_name, str_end);
  patch_dir = talloc_tmp_file_name (talloc_context, tree_root, patch_dir_stem);

  {
    arch_patch_id * revision_patch = arch_patch_id_new_archive (arch->official_name, revision);
  arch_get_patch (arch, revision_patch, patch_dir);
    talloc_free (revision_patch);
  }

  arch_chatter (chatter_fd, "* patching for revision %s/%s\n", arch->official_name, revision);
  if ((chatter_fd >= 0) && !no_patch_noise)
    {
      report_callback = replay_callback;
      report_thunk = (void *)(long)chatter_fd;
    }

  report = arch_apply_changeset (patch_dir, patch_dir, tree, arch_unspecified_id_tagging, arch_inventory_unrecognized, reverse, forward, escape_classes, report_callback, report_thunk);
  arch_project_tree_delete (tree);
  status = arch_conflicts_occurred (report);
  rmrf_file (patch_dir);

  lim_free (0, patch_dir_stem);
  talloc_free (patch_dir);
  return status;
}


int
arch_replay_list (int chatter_fd,
                  int no_patch_noise,
                  t_uchar const * tree_root,
                  struct arch_archive * arch,
                  rel_table revisions,
                  int reverse,
                  int forward,
                  int escape_classes)
{
  int x;
  int status = 0;

  for (x = 0; x < rel_n_records (revisions); ++x)
    {
      if (arch_replay_exact (chatter_fd, no_patch_noise, tree_root, arch, revisions[x][0],
                             reverse, forward,escape_classes))
        {
          t_uchar * conflicts_in_file = 0;
          t_uchar * patches_remaining_file = 0;
          int out_fd;
          int y;

          conflicts_in_file = file_name_in_vicinity (0, tree_root, ",,replay.conflicts-in");
          out_fd = safe_open (conflicts_in_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
          safe_printfmt (out_fd, "%s/%s\n", arch->official_name, revisions[x][0]);
          safe_close (out_fd);

          patches_remaining_file = file_name_in_vicinity (0, tree_root, ",,replay.remaining");
          out_fd = safe_open (patches_remaining_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
          for (y = x + 1; y < rel_n_records (revisions); ++y)
            {
              safe_printfmt (out_fd, "%s/%s\n", arch->official_name, revisions[y][0]);
            }
          safe_close (out_fd);

          lim_free (0, conflicts_in_file);
          lim_free (0, patches_remaining_file);

          status = 1;
          break;
        }
    }
  return status;
}


int
arch_replay_fqlist (int chatter_fd,
                    int no_patch_noise,
                    t_uchar * tree_root,
                    t_uchar * default_archive,
                    rel_table revisions,
                    int reverse,
                    int forward,
                    int escape_classes)
{
  int x;
  int status = 0;
  struct arch_archive * connected_archive = 0;

  for (x = 0; !status && (x < rel_n_records (revisions)); ++x)
    {
      t_uchar * archive = 0;
      t_uchar * revision = 0;

      archive = arch_parse_package_name (arch_ret_archive, default_archive, revisions[x][0]);
      revision = arch_parse_package_name (arch_ret_non_archive, 0, revisions[x][0]);

      if (!connected_archive || str_cmp (connected_archive->official_name, archive))
        {
          arch_archive_close (connected_archive);
          connected_archive = arch_archive_connect_branch (archive, NULL);
          if (!connected_archive)
            {
              safe_printfmt (2, "Could not connect to archive %s ", archive);
              exit (2);
            }
        }

      if (!connected_archive
          || arch_replay_exact (chatter_fd, no_patch_noise, tree_root, connected_archive, revision,
                                reverse, forward, escape_classes))
        {
          t_uchar * conflicts_in_file = 0;
          t_uchar * patches_remaining_file = 0;
          int out_fd;
          int y;

          conflicts_in_file = file_name_in_vicinity (0, tree_root, ",,replay.conflicts-in");
          out_fd = safe_open (conflicts_in_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
          safe_printfmt (out_fd, "%s\n", revisions[x][0]);
          safe_close (out_fd);

          patches_remaining_file = file_name_in_vicinity (0, tree_root, ",,replay.remaining");
          out_fd = safe_open (patches_remaining_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
          for (y = x + 1; y < rel_n_records (revisions); ++y)
            {
              safe_printfmt (out_fd, "%s\n", revisions[y][0]);
            }
          safe_close (out_fd);

          lim_free (0, conflicts_in_file);
          lim_free (0, patches_remaining_file);

          status = 1;
        }

      lim_free (0, archive);
      lim_free (0, revision);
    }

  arch_archive_close (connected_archive);
  return status;
}




static void
replay_callback (void * vfd, char * fmt, va_list ap)
{
  safe_printfmt_va_list ((int)(t_ulong)vfd, fmt, ap);
  safe_flush ((int)(t_ulong)vfd);
}



/* tag: Tom Lord Tue Jun  3 18:03:29 2003 (replay.c)
 */
Results 1 - 1
Help - FTP Sites List - Software Dir.
Searching half a billion files worldwide
© 1997-2008 Oliver Maruhn