def add(repo, args, targetdir,<EOL>execute=False, generator=False,<EOL>includes=[], script=False,<EOL>source=None):
<EOL>if not execute:<EOL><INDENT>files = add_files(args=args,<EOL>targetdir=targetdir,<EOL>source=source,<EOL>script=script,<EOL>generator=generator)<EOL><DEDENT>else:<EOL><INDENT>files = run_executable(repo, args, includes)<EOL><DEDENT>if files is None or len(files) == <NUM_LIT:0>:<EOL><INDENT>return repo<EOL><DEDENT>filtered_files = []<EOL>package = repo.package<EOL>for h in files:<EOL><INDENT>found = False<EOL>for i, r in  enumerate(package['<STR_LIT>']):<EOL><INDENT>if h['<STR_LIT>'] == r['<STR_LIT>']:<EOL><INDENT>found = True<EOL>if h['<STR_LIT>'] == r['<STR_LIT>']:<EOL><INDENT>change = False<EOL>for attr in ['<STR_LIT:source>']:<EOL><INDENT>if h[attr] != r[attr]:<EOL><INDENT>r[attr] = h[attr]<EOL>change = True<EOL><DEDENT><DEDENT>if change:<EOL><INDENT>filtered_files.append(h)<EOL><DEDENT>continue<EOL><DEDENT>else:<EOL><INDENT>filtered_files.append(h)<EOL>package['<STR_LIT>'][i] = h<EOL><DEDENT>break<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>filtered_files.append(h)<EOL>package['<STR_LIT>'].append(h)<EOL><DEDENT><DEDENT>if len(filtered_files) == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>repo.manager.add_files(repo, filtered_files)<EOL>rootdir = repo.rootdir<EOL>with cd(rootdir):<EOL><INDENT>datapath = "<STR_LIT>"<EOL>with open(datapath, '<STR_LIT:w>') as fd:<EOL><INDENT>fd.write(json.dumps(package, indent=<NUM_LIT:4>))<EOL><DEDENT><DEDENT>return len(filtered_files)<EOL>
Add files to the repository by explicitly specifying them or by
specifying a pattern over files accessed during execution of an
executable.

Parameters
----------

repo: Repository

args: files or command line
     (a) If simply adding files, then the list of files that must
     be added (including any additional arguments to be passed to
     git
     (b) If files to be added are an output of a command line, then
     args is the command lined
targetdir: Target directory to store the files
execute: Args are not files to be added but scripts that must be run.
includes: patterns used to select files to
script: Is this a script?
generator: Is this a generator
source: Link to the original source of the data