Exemplo n.º 1
0
static int backupProc( const std::vector<std::string> &args )
{
   if ( args.size() < 3 )
   {
      std::cout << "gitbk backup src dest" << std::endl;
      return 1;
   }

   if ( !boost::filesystem::is_directory( args[1] ) )
   {
      std::cout << '\'' << args[1] << "' is not directory!" << std::endl;
      return 1;
   }

   path_init( args[args.size()-1] );

   load_hash_set( );

   hash_mutex = new boost::shared_mutex;
   std::auto_ptr<boost::shared_mutex> mp( hash_mutex );

   for ( unsigned i = 1; i < args.size()-1; ++i )
      backup( args[i] );

   free_hash_set( );

   return 0;
}
Exemplo n.º 2
0
int pruneProc( const std::vector<std::string> &args )
{
   if ( args.size() < 2 )
   {
      std::cout << "gitbk prune <repo path>" << std::endl;
      return 1;
   }

   path_init( args[1] );


   load_hash_set( false );

   {
      signal( SIGALRM, sigroutine );
      static const struct itimerval v =
      {
         { 0, 50000 },
         { 0, 50000 },
      };
      setitimer( ITIMER_REAL, &v, nullptr );
   }

   recordAllHash( );

   signal( SIGALRM, SIG_IGN );
   std::cout << "\rCounting objects " << s_object_count << std::endl;

   if ( store_hash_set( false ) )
   {
      const int n = sysconf( _SC_NPROCESSORS_ONLN );

      for ( int i = 0; i < n; ++i )
         ++count_threads;

      boost::thread_group tgroup;
      for ( int i = 0; i < n; ++i )
         tgroup.create_thread( boost::bind(&delete_file, 256*i/n, (256*(i+1)/n) ) );

      tgroup.create_thread( &remove_process );

      tgroup.join_all( );

      printf( "\n" );
   }

   free_hash_set( );

   return 0;
}
Exemplo n.º 3
0
void create_table(cube *(*construct_cube)(cube*),
                      hash_cube_t (*hash_cube)(cube*),
                      cube *(*reconstruct_stickers)(hash_cube_t*),
                      int total_count
                      ) {
  hash_set_t hash_set = new_hash_set(hash_cube_index, hash_cube_equals);
  queue q = new_queue();

  cube *c0 = construct_cube(init_cube());
  hash_cube_t h0 = hash_cube(c0);
  delete_cube(c0);

  enqueue(&q, h0);
  insert(&hash_set, &h0);

  int count = 0;
  int depth = 0;
  while (queue_size(&q) != 0) {
    int n = queue_size(&q);
    for (int i = 0; i < n; ++i) {
      ++count;
      if (count % 1000 == 0) {
        fprintf(stderr, "%f\n", (float) count / total_count);
      }

      hash_cube_t val = dequeue(&q);
      cube *c1 = reconstruct_stickers(&val);
      print_cube_flat(c1);
      printf(",%d\n", depth);

      for (int i = 0; i < 18; ++i) {
        cube *c2 = cube_expand[i](c1);
        hash_cube_t h1 = hash_cube(c2);
        if (!contains(&hash_set, &h1)) {
          enqueue(&q, h1);
          insert(&hash_set, &h1);
        }
        delete_cube(c2);
      }
      delete_cube(c1);
    }
    ++depth;
  }

  free_queue(&q);
  free_hash_set(&hash_set);
}