cp_mv.c File Reference

cp and mv actions. More...

#include <fcntl.h>
#include <search.h>
#include "global.h"
#include "cp_mv.h"
#include "status.h"
#include "est_ops.h"
#include "url.h"
#include "checksum.h"
#include "options.h"
#include "props.h"
#include "cache.h"
#include "helper.h"
#include "waa.h"
Include dependency graph for cp_mv.c:

Go to the source code of this file.

Data Structures

struct  cm___candidate_t
 Structure for candidate retrieval. More...
struct  cm___match_t
 -. More...

Defines

#define MAX_DUPL_ENTRIES   (HASH__LIST_MAX -1)
 Maximum number of entries that are stored.
#define CM___MATCH_NUM   (sizeof(cm___match_array)/sizeof(cm___match_array[0]))

Typedefs

typedef int( cm___register_fn )(struct estat *, struct cm___match_t *)
 Enters the given entry into the database.
typedef int( cm___get_list_fn )(struct estat *, struct cm___match_t *, struct cm___candidate_t **, int *count)
 Queries the database for the given entry.
typedef char *( cm___format_fn )(struct cm___match_t *match, struct cm___candidate_t *cand)
 Format function for verbose output.

Enumerations

enum  cm___match_e { CM___NAME_F = 0, CM___NAME_D, CM___DIRLIST }
 

Enumeration for (some) matching criteria.

More...

Functions

datum cm___md5_datum (const struct estat *sts)
 Gets a datum from a struct estat::md5.
datum cm___name_datum (const struct estat *sts)
 Gets a datum from the name of an entry; the \0 gets included (for easier dumping).
datum cm___inode_datum (const struct estat *sts)
 Gets a datum from the filesystem addressing - device and inode.
static int cm___cand_compare (const void *_a, const void *_b)
 Compare function for cm___candidate_t.
static int cm___cand_comp_count (const void *_a, const void *_b)
 Compare function for cm___candidate_t.
int cm___hash_register (struct estat *sts, struct cm___match_t *match)
 -.
int cm___match_children (struct estat *sts, struct cm___match_t *match, struct cm___candidate_t **list, int *found)
 -.
int cm___hash_list (struct estat *sts, struct cm___match_t *match, struct cm___candidate_t **output, int *found)
 -.
char * cm___output_pct (struct cm___match_t *match, struct cm___candidate_t *cand)
 Puts cm___candidate_t::match_count formatted into buffer.
int cm___register_entry (struct estat *sts)
 Inserts the given entry in all allowed matching databases.
static int cm___match (struct estat *entry)
 Shows possible copyfrom sources for the given entry.
int cm__find_dir_source (struct estat *dir)
int cm__find_file_source (struct estat *file)
int cm__find_copied (struct estat *root)
 After loading known entries try to find some match for every new entry.
int cm__detect (struct estat *root, int argc, char *argv[])
 -.
int cm___string_to_rev_path (char *string, char **out_url, svn_revnum_t *orev)
 Converts the (internally stored) string into revision/URL.
int cm___rev_path_to_string (char *url, svn_revnum_t revision, char **string)
 Formats the revision and url for storage in the hash table.
int cm___absolute_path (char *path, char **output)
 Returns the absolute path.
int cm___not_below_wcpath (char *path, char **out)
 Checks whether a path is below wc_path, and returns the relative part.
int cm___dump_list (FILE *output, int argc, char *normalized[])
 Dump a list of copyfrom relations to the stream.
int cm___make_copy (struct estat *root, char *cp_src, svn_revnum_t revision, char *cp_dest, int paths_are_wc_relative)
 Make the copy in the tree started at root.
int cm___ignore_impl_copied (struct estat *cur)
 Sets all entries that are just implicitly copied to ignored.
int cm__uncopy (struct estat *root, int argc, char *argv[])
 -.
int cm__work (struct estat *root, int argc, char *argv[])
 -.
int cm___get_base_source (struct estat *sts, char *name, char **src_url, svn_revnum_t *src_rev, int alloc_extra, int register_for_cleanup)
 Get the source of an entry with RF_COPY_BASE set.
int cm___get_sub_source_rek (struct estat *cur, int length_to_add, char **dest_buffer, svn_revnum_t *src_rev, char **eobuffer)
 Recursively creating the URL.
int cm___get_sub_source (struct estat *sts, char *name, char **src_url, svn_revnum_t *src_rev)
 Get the source of an entry with RF_COPY_SUB set.
int cm__get_source (struct estat *sts, char *name, char **src_url, svn_revnum_t *src_rev, int register_for_cleanup)
 -.

Variables

int copydetect_count
 How many entries could be correlated.
cm___register_fn cm___hash_register
 Inserts into hash tables.
cm___get_list_fn cm___hash_list
 Queries the database for the given entry.
cm___get_list_fn cm___match_children
 Match directories by their children.
cm___format_fn cm___output_pct
 Outputs percent of match.
struct cm___match_t cm___match_array []
 Array with ways for simple matches.



typedef datum( cm___to_datum_t )(const struct estat *sts)
 Function and type declarations for entry-to-hash-key conversions.
cm___to_datum_t cm___md5_datum
cm___to_datum_t cm___inode_datum
cm___to_datum_t cm___name_datum

Detailed Description

cp and mv actions.

Various thoughts ...

Definition in file cp_mv.c.


Define Documentation

#define CM___MATCH_NUM   (sizeof(cm___match_array)/sizeof(cm___match_array[0]))

Definition at line 435 of file cp_mv.c.

Referenced by cm___match(), cm___register_entry(), and cm__detect().

#define MAX_DUPL_ENTRIES   (HASH__LIST_MAX -1)

Maximum number of entries that are stored.

The -1 is for overflow detection "...".

Definition at line 304 of file cp_mv.c.

Referenced by cm___match().


Typedef Documentation

typedef char*( cm___format_fn)(struct cm___match_t *match, struct cm___candidate_t *cand)

Format function for verbose output.

Formats the candidate cand in match match into a buffer, and returns this buffer.

Definition at line 353 of file cp_mv.c.

typedef int( cm___get_list_fn)(struct estat *, struct cm___match_t *, struct cm___candidate_t **, int *count)

Queries the database for the given entry.

Output is (the address of) an array of cm___candidates_t, and the number of elements.

Definition at line 348 of file cp_mv.c.

typedef int( cm___register_fn)(struct estat *, struct cm___match_t *)

Enters the given entry into the database.

Definition at line 343 of file cp_mv.c.

typedef datum( cm___to_datum_t)(const struct estat *sts)

Function and type declarations for entry-to-hash-key conversions.

Definition at line 330 of file cp_mv.c.


Enumeration Type Documentation

Enumeration for (some) matching criteria.

Enumerator:
CM___NAME_F 
CM___NAME_D 
CM___DIRLIST 

Definition at line 398 of file cp_mv.c.


Function Documentation

int cm___absolute_path ( char *  path,
char **  output 
)

Returns the absolute path.

Definition at line 1056 of file cp_mv.c.

References BUG_ON, cch__add(), DEBUGP, cache_t::entries, hlp__pathcopy(), cache_entry_t::len, cache_t::lru, start_path_len, and STOPIF.

Referenced by cm___make_copy().

Here is the call graph for this function:

Here is the caller graph for this function:

static int cm___cand_comp_count ( const void *  _a,
const void *  _b 
) [static]

Compare function for cm___candidate_t.

Definition at line 486 of file cp_mv.c.

References cm___candidate_t::match_count.

Referenced by cm___match_children().

Here is the caller graph for this function:

static int cm___cand_compare ( const void *  _a,
const void *  _b 
) [static]

Compare function for cm___candidate_t.

Definition at line 477 of file cp_mv.c.

References cm___candidate_t::sts.

Referenced by cm___match(), and cm___match_children().

Here is the caller graph for this function:

int cm___dump_list ( FILE *  output,
int  argc,
char *  normalized[] 
)

Dump a list of copyfrom relations to the stream.

TODO: filter by wildcards (?)

Definition at line 1102 of file cp_mv.c.

References cm___string_to_rev_path(), hsh__close(), hsh__fetch(), hsh__first(), hsh__new(), hsh__next(), IF_FREE, opt__is_verbose(), STOPIF, STOPIF_CODE_ERR, WAA__COPYFROM_EXT, and wc_path.

Referenced by cm__work().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm___get_base_source ( struct estat sts,
char *  name,
char **  src_url,
svn_revnum_t *  src_rev,
int  alloc_extra,
int  register_for_cleanup 
)

Get the source of an entry with RF_COPY_BASE set.

See cm__get_source() for details.

Definition at line 1519 of file cp_mv.c.

References BUG_ON, cm___string_to_rev_path(), DEBUGP, HASH_REMEMBER_FILENAME, hlp__strnalloc(), hsh__close(), hsh__fetch(), hsh__new(), hsh__register_delete(), IF_FREE, ops__build_path(), PATH_SEPARATOR, STOPIF, estat::url, WAA__COPYFROM_EXT, and wc_path.

Referenced by cm___get_sub_source_rek(), and cm__get_source().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm___get_sub_source ( struct estat sts,
char *  name,
char **  src_url,
svn_revnum_t *  src_rev 
)

Get the source of an entry with RF_COPY_SUB set.

See cm__get_source() for details.

This function needs no cleanup.

Definition at line 1668 of file cp_mv.c.

References cm___get_sub_source_rek(), and STOPIF.

Referenced by cm__get_source().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm___get_sub_source_rek ( struct estat cur,
int  length_to_add,
char **  dest_buffer,
svn_revnum_t *  src_rev,
char **  eobuffer 
)

Recursively creating the URL.

As most of the parameters are constant, we could store them statically ... don't know whether it would make much difference, this function doesn't get called very often. length_to_add is increased while going up the tree; eobuffer gets handed back down.

Definition at line 1612 of file cp_mv.c.

References BUG_ON, cm___get_base_source(), DEBUGP, estat::flags, estat::name, estat::parent, and RF_COPY_BASE.

Referenced by cm___get_sub_source().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm___hash_list ( struct estat sts,
struct cm___match_t match,
struct cm___candidate_t **  output,
int *  found 
)

-.

The other members are touched by upper layers, so we have to re-initialize them.

Definition at line 615 of file cp_mv.c.

References cm___match_t::db, hsh__list_get(), cm___match_t::key, cm___candidate_t::sts, and cm___match_t::to_key.

Here is the call graph for this function:

int cm___hash_register ( struct estat sts,
struct cm___match_t match 
)

-.

Definition at line 495 of file cp_mv.c.

References cm___match_t::db, hsh__insert_pointer(), and cm___match_t::to_key.

Here is the call graph for this function:

int cm___ignore_impl_copied ( struct estat cur  ) 

Sets all entries that are just implicitly copied to ignored.

Explicitly added entries (because of add, or prop-set) are kept.

Returns a 0 or 1, with 1 saying that all entries below are ignored, and so whether cur can (perhaps) be completely ignored, too.

Definition at line 1273 of file cp_mv.c.

References estat::by_inode, DEBUGP, estat::flags, estat::name, ops__has_children(), RF_ADD, RF_CHECK, RF_COPY_SUB, RF_PUSHPROPS, and estat::to_be_ignored.

Referenced by cm__uncopy().

Here is the call graph for this function:

Here is the caller graph for this function:

datum cm___inode_datum ( const struct estat sts  ) 

Gets a datum from the filesystem addressing - device and inode.

Definition at line 463 of file cp_mv.c.

References sstat_t::dev, sstat_t::ino, and estat::st.

int cm___make_copy ( struct estat root,
char *  cp_src,
svn_revnum_t  revision,
char *  cp_dest,
int  paths_are_wc_relative 
)

Make the copy in the tree started at root.

The destination must not already exist in the tree; it can exist in the filesystem.

If revision is not 0 (which corresponds to BASE), the correct list of entries must be taken from the corresponding repository.

Uninitialization is done via root==NULL.

If the flag paths_are_wc_relative is set, the paths cp_src and cp_dest are taken as-is. Else they're are converted to wc-relative paths by making them absolute (eventually using start_path as anchor), and cutting the wc-root off.

Definition at line 1178 of file cp_mv.c.

References BUG_ON, cm___absolute_path(), cm___not_below_wcpath(), cm___rev_path_to_string(), estat::flags, hsh__close(), hsh__new(), hsh__store_charp(), OPS__CREATE, ops__traverse(), estat::repos_rev, RF___IS_COPY, RF_ADD, RF_COPY_BASE, RF_COPY_SUB, RF_ISNEW, STOPIF, STOPIF_CODE_ERR, estat::url, url__full_url(), waa__copy_entries(), WAA__COPYFROM_EXT, and wc_path.

Referenced by cm__work().

Here is the call graph for this function:

Here is the caller graph for this function:

static int cm___match ( struct estat entry  )  [static]
int cm___match_children ( struct estat sts,
struct cm___match_t match,
struct cm___candidate_t **  list,
int *  found 
)

-.

The big question is - should this work recursively? Would mean that the topmost directory would be descended, and the results had to be cached.

Definition at line 515 of file cp_mv.c.

References BUG_ON, estat::by_inode, cm___cand_comp_count(), cm___cand_compare(), CM___NAME_D, CM___NAME_F, cm___match_t::db, DEBUGP, estat::entry_count, HASH__LIST_MAX, hsh__list_get(), cm___candidate_t::match_count, sstat_t::mode, estat::name, ops__correlate_dirs(), estat::parent, estat::st, STOPIF, cm___candidate_t::sts, and cm___match_t::to_key.

Here is the call graph for this function:

datum cm___md5_datum ( const struct estat sts  ) 

Gets a datum from a struct estat::md5.

Definition at line 439 of file cp_mv.c.

References cs__md5tohex_buffered(), and estat::md5.

Here is the call graph for this function:

datum cm___name_datum ( const struct estat sts  ) 

Gets a datum from the name of an entry; the \0 gets included (for easier dumping).

Definition at line 451 of file cp_mv.c.

References estat::name.

int cm___not_below_wcpath ( char *  path,
char **  out 
) [inline]

Checks whether a path is below wc_path, and returns the relative part.

If that isn't possible (because path is not below wc_path), EINVAL is returned. The case path==wc_path is not allowed, either.

Definition at line 1085 of file cp_mv.c.

References PATH_SEPARATOR, wc_path, and wc_path_len.

Referenced by cm___make_copy().

Here is the caller graph for this function:

char* cm___output_pct ( struct cm___match_t match,
struct cm___candidate_t cand 
)

Puts cm___candidate_t::match_count formatted into buffer.

Definition at line 643 of file cp_mv.c.

References BUG_ON, and cm___candidate_t::match_count.

int cm___register_entry ( struct estat sts  ) 

Inserts the given entry in all allowed matching databases.

Definition at line 658 of file cp_mv.c.

References CM___MATCH_NUM, DEBUGP, estat::entry_status, cm___match_t::entry_type, FS_NEW, cm___match_t::insert, cm___match_t::is_enabled, sstat_t::mode, cm___match_t::name, estat::name, estat::st, and STOPIF.

Referenced by cm__detect().

Here is the caller graph for this function:

int cm___rev_path_to_string ( char *  url,
svn_revnum_t  revision,
char **  string 
)

Formats the revision and url for storage in the hash table.

*string must not be free()ed by the caller.

Definition at line 1029 of file cp_mv.c.

References BUG_ON, cch__entry_set(), and STOPIF.

Referenced by cm___make_copy().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm___string_to_rev_path ( char *  string,
char **  out_url,
svn_revnum_t *  orev 
)

Converts the (internally stored) string into revision/URL.

The string is not freed; that has to be done by the caller.

Definition at line 998 of file cp_mv.c.

References DEBUGP, and hlp__skip_ws().

Referenced by cm___dump_list(), and cm___get_base_source().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm__detect ( struct estat root,
int  argc,
char *  argv[] 
)

-.

Todo:
Do we really need to load the URLs here? They're needed for associating the entries - but maybe we should do that two-way:
  • just read intnum , and store it again
  • or process to (struct url_t*).

Well, reading the URLs doesn't cost that much ...

Definition at line 918 of file cp_mv.c.

References CHCHECK_NONE, CM___MATCH_NUM, cm___register_entry(), cm__find_copied(), copydetect_count, cm___match_t::db, DEBUGP, cm___match_t::filename, HASH_TEMPORARY, hsh__close(), hsh__new(), cm___match_t::is_enabled, cm___match_t::is_expensive, cm___match_t::name, OPT__CHANGECHECK, OPT__COPYFROM_EXP, opt__is_verbose(), opt__set_int(), opt_recursive, PRIO_MUSTHAVE, STOPIF, STOPIF_CODE_EPIPE, STOPIF_CODE_ERR, url__load_list(), waa__find_common_base(), waa__read_or_build_tree(), and wc_path.

Here is the call graph for this function:

int cm__find_copied ( struct estat root  ) 

After loading known entries try to find some match for every new entry.

Definition at line 869 of file cp_mv.c.

References estat::by_inode, cm__find_dir_source(), cm__find_file_source(), DEBUGP, estat::entry_status, FS_CHANGED, FS_CHILD_CHANGED, FS_NEW, sstat_t::mode, estat::name, estat::st, and STOPIF.

Referenced by cm__detect().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm__find_dir_source ( struct estat dir  ) 

Definition at line 834 of file cp_mv.c.

References cm___match(), and STOPIF.

Referenced by cm__find_copied().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm__find_file_source ( struct estat file  ) 

Definition at line 846 of file cp_mv.c.

References cm___match(), cs__compare_file(), DEBUGP, estat::name, ops__build_path(), and STOPIF.

Referenced by cm__find_copied().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm__get_source ( struct estat sts,
char *  name,
char **  src_url,
svn_revnum_t *  src_rev,
int  register_for_cleanup 
)

-.

Returns the source of the given entry.

Wrapper around cm___get_base_source() and cm___get_sub_source().

If *src_url is needed, it is allocated and must be free()ed after use.

If name is not given, it has to be calculated.

Both src_name and src_rev are optional. These are always set; if no source is defined, they're set to NULL, NULL and SVN_INVALID_REVNUM.

Uninitializing should be done via calling with sts==NULL; in this case the register_for_cleanup value is used as success flag.

If no source could be found, ENOENT is returned.

Definition at line 1712 of file cp_mv.c.

References cm___get_base_source(), cm___get_sub_source(), DEBUGP, estat::flags, estat::name, RF_COPY_BASE, and RF_COPY_SUB.

Referenced by cm__uncopy(), df__do_diff(), main(), rev__install_file(), st__print_entry_info(), and st__print_status().

Here is the call graph for this function:

Here is the caller graph for this function:

int cm__uncopy ( struct estat root,
int  argc,
char *  argv[] 
)
int cm__work ( struct estat root,
int  argc,
char *  argv[] 
)

Variable Documentation

cm___get_list_fn cm___hash_list

Queries the database for the given entry.

Definition at line 360 of file cp_mv.c.

cm___register_fn cm___hash_register

Inserts into hash tables.

Definition at line 358 of file cp_mv.c.

cm___to_datum_t cm___inode_datum

Definition at line 332 of file cp_mv.c.

Initial value:
{
    [CM___NAME_F] = { .name="name", .to_key=cm___name_datum, 
        .insert=cm___hash_register, .get_list=cm___hash_list,
        .entry_type=S_IFREG,  .filename=WAA__FILE_NAME_EXT},
    [CM___NAME_D] = { .name="name", .to_key=cm___name_datum, 
        .insert=cm___hash_register, .get_list=cm___hash_list,
        .entry_type=S_IFDIR,  .filename=WAA__DIR_NAME_EXT},

    [CM___DIRLIST] = { .name="dirlist", 
        .get_list=cm___match_children, .format=cm___output_pct,
        .entry_type=S_IFDIR, },

    { .name="md5", .to_key=cm___md5_datum, .is_expensive=1,
        .insert=cm___hash_register, .get_list=cm___hash_list,
        .entry_type=S_IFREG, .filename=WAA__FILE_MD5s_EXT},

    { .name="inode", .to_key=cm___inode_datum, 
        .insert=cm___hash_register, .get_list=cm___hash_list,
        .entry_type=S_IFDIR, .filename=WAA__FILE_INODE_EXT},
    { .name="inode", .to_key=cm___inode_datum, 
        .insert=cm___hash_register, .get_list=cm___hash_list,
        .entry_type=S_IFREG, .filename=WAA__DIR_INODE_EXT},
}

Array with ways for simple matches.

We keep file and directory matching separated; a file cannot be the copyfrom source of a directory, and vice-versa.

The important match types are at the start, as they're directly accessed, too.

Definition at line 411 of file cp_mv.c.

cm___get_list_fn cm___match_children

Match directories by their children.

Definition at line 362 of file cp_mv.c.

cm___to_datum_t cm___md5_datum

Definition at line 331 of file cp_mv.c.

cm___to_datum_t cm___name_datum

Definition at line 333 of file cp_mv.c.

cm___format_fn cm___output_pct

Outputs percent of match.

Definition at line 364 of file cp_mv.c.

How many entries could be correlated.

Definition at line 314 of file cp_mv.c.

Referenced by cm___match(), and cm__detect().


Generated for fsvs by  doxygen 1.6.1