Produces an ordered list of patches that need to be applied.

 May raise MismatchError in case if signatures of any permanent
 patches that are present in the definition don't match
 ones of the patches applied to the database.
327641
def plan
      ref = @dao.applied_patches
      @patches.select do |patch|
        signature = ref[patch.name]
        next false if signature == patch.signature
        next true if signature.nil? || patch.volatile?
        raise MismatchError, patch
      end
    end
194531
public static Map<String, Object> computePatch(Object patched, Object original) {
    FieldsMask fieldsMask = new FieldsMask();
    ArrayMap<String, Object> result = computePatchInternal(fieldsMask, patched, original);
    if (fieldsMask.numDifferences != 0) {
      result.put("@gd:fields", fieldsMask.buf.toString());
    }
    return result;
  }
367627
def _patched_method(self, method, *args, **kwargs):
        
        self._validate()
        result = method(*args, **kwargs)
        self._validate()
        return result
527095
def apply_patches(document, patches):
  """"""
  for i, patch in enumerate(patches):
    try:
      result = apply_patch(document, patch)
      if patch.op == "test" and result is False:
        raise JSONPatchError("Test patch {0} failed. Cancelling entire set.".format(i + 1))
    except Exception as ex:
      raise JSONPatchError("An error occurred with patch {0}: {1}".format(i + 1, ex)) from ex
350105
def get_model_indexes(model, add_reserver_flag=True):
    
    import uliweb.orm as orm
    from sqlalchemy.engine.reflection import Inspector

    indexes = []
    engine = model.get_engine().engine
    insp = Inspector.from_engine(engine)
    for index in insp.get_indexes(model.tablename):
        d = {}
        d['name'] = index['name']
        d['unique'] = index['unique']
        d['fields'] = index['column_names']
        if add_reserver_flag:
            d['_reserved'] = True
        indexes.append(d)

    return indexes
406950
def supported_fixes():
    
    yield ('E101', docstring_summary(reindent.__doc__))

    instance = FixPEP8(filename=None, options=None, contents='')
    for attribute in dir(instance):
        code = re.match('fix_([ew][0-9][0-9][0-9])', attribute)
        if code:
            yield (
                code.group(1).upper(),
                re.sub(r'\s+', ' ',
                       docstring_summary(getattr(instance, attribute).__doc__))
            )

    for (code, function) in sorted(global_fixes()):
        yield (code.upper() + (4 - len(code)) * ' ',
               re.sub(r'\s+', ' ', docstring_summary(function.__doc__)))

    for code in sorted(CODE_TO_2TO3):
        yield (code.upper() + (4 - len(code)) * ' ',
               re.sub(r'\s+', ' ', docstring_summary(fix_2to3.__doc__)))
895160
def getPatches(self) :
        """"""
        if not self.mustValidate :
            return self.getStore()

        res = {}
        res.update(self.patchStore)
        for k, v in self.subStores.items() :
            res[k] = v.getPatches()
        
        return res
1306584
def make_patch(self):
        ''''''
        paths = [p.make_patch().get_path() for p in self.pieces]
        vertices = np.concatenate([p.vertices for p in paths])
        codes = np.concatenate([p.codes for p in paths])
        return PathPatch(Path(vertices, codes))
659227
public LinkedList<Patch> patch_deepCopy(LinkedList<Patch> patches) {
        LinkedList<Patch> patchesCopy = new LinkedList<Patch>();
        for (Patch aPatch : patches) {
            Patch patchCopy = new Patch();
            for (Diff aDiff : aPatch.diffs) {
                Diff diffCopy = new Diff(aDiff.operation, aDiff.text);
                patchCopy.diffs.add(diffCopy);
            }
            patchCopy.start1 = aPatch.start1;
            patchCopy.start2 = aPatch.start2;
            patchCopy.length1 = aPatch.length1;
            patchCopy.length2 = aPatch.length2;
            patchesCopy.add(patchCopy);
        }
        return patchesCopy;
    }
885274
def patch_file(patch_stream: TextIO, fromcsv_stream: TextIO, tocsv_stream: TextIO,
               strict: bool = True, sep: str = ','):
    
    diff = patch.load(patch_stream)

    from_records = records.load(fromcsv_stream, sep=sep)
    to_records = patch.apply(diff, from_records, strict=strict)

    # what order should the columns be in?
    if to_records:
        # have data, use a nice ordering
        all_columns = to_records[0].keys()
        index_columns = diff['_index']
        fieldnames = _nice_fieldnames(all_columns, index_columns)
    else:
        # no data, use the original order
        fieldnames = from_records.fieldnames

    records.save(to_records, fieldnames, tocsv_stream)
21264
def _get_fields(self, fields, excludes, hotfixes):
        '''
        
        '''
        final_fields = {}
        fields = fields or []
        excludes = excludes or []

        for f in self.model._meta.fields:
            # If the field name is already present, skip
            if f.name in self.fields:
                continue

            # If field is not present in explicit field listing, skip
            if fields and f.name not in fields:
                continue

            # If field is in exclude list, skip
            if excludes and f.name in excludes:
                continue

            # If field is a relation, skip.
            if getattr(f, 'rel'):
                continue

            attr = {'model_attr': f.name}
            if f.has_default():
                attr['null_value'] = f.default

            if f.name in hotfixes:
                attr.update(hotfixes[f.name])

            final_fields[f.name] = django_field_to_index(f, **attr)

        return final_fields
318798
public java.util.List<PatchBaselineIdentity> getBaselineIdentities() {
        if (baselineIdentities == null) {
            baselineIdentities = new com.amazonaws.internal.SdkInternalList<PatchBaselineIdentity>();
        }
        return baselineIdentities;
    }
1147156
public List<String> getSuggestedReplacements() {
    List<String> l = new ArrayList<>();
    for (SuggestedReplacement repl : suggestedReplacements) {
      l.add(repl.getReplacement());
    }
    return Collections.unmodifiableList(l);
  }
249724
function addPatch(patches, patch) {
	var lastPatch = patches[patches.length -1];
	if(lastPatch) {
		// same number of deletes and counts as the index is back
		if(lastPatch.deleteCount === lastPatch.insert.length && (patch.index - lastPatch.index === lastPatch.deleteCount) ) {
			lastPatch.insert.push.apply(lastPatch.insert, patch.insert);
			lastPatch.deleteCount += patch.deleteCount;
			return;
		}
	}
	patches.push(patch);
}
188846
def generate_patches(self):
        
        start_pos = self.start_position or Position(None, None)
        end_pos = self.end_position or Position(None, None)

        path_list = Query._walk_directory(self.root_directory)
        path_list = Query._sublist(path_list, start_pos.path, end_pos.path)
        path_list = (
            path for path in path_list if
            Query._path_looks_like_code(path) and
            (self.path_filter(path)) or
            (self.inc_extensionless and helpers.is_extensionless(path))
        )
        for path in path_list:
            try:
                lines = list(open(path))
            except (IOError, UnicodeDecodeError):
                # If we can't open the file--perhaps it's a symlink whose
                # destination no loner exists--then short-circuit.
                continue

            for patch in self.suggestor(lines):
                if path == start_pos.path:
                    if patch.start_line_number < start_pos.line_number:
                        continue  # suggestion is pre-start_pos
                if path == end_pos.path:
                    if patch.end_line_number >= end_pos.line_number:
                        break  # suggestion is post-end_pos

                old_lines = lines[
                    patch.start_line_number:patch.end_line_number]
                if patch.new_lines is None or patch.new_lines != old_lines:
                    patch.path = path
                    yield patch
                    # re-open file, in case contents changed
                    lines[:] = list(open(path))
1243085
def apply_patch(self):
        
        patch = self.patches.get(self.storage.__class__.__name__)
        if patch:
            patch.apply(self)
239374
private PatchingResult applyPatch(final String patchId, final Patch patch, final IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {

        final Identity identity = patch.getIdentity();
        final Patch.PatchType patchType = identity.getPatchType();
        final InstallationManager.InstallationModification modification = context.getModification();
        if (patchType == Patch.PatchType.CUMULATIVE) {
            // Invalidate all installed patches (one-off, cumulative) - we never need to invalidate the release base
            final List<String> invalidation = new ArrayList<String>(modification.getPatchIDs());
            if (!invalidation.isEmpty()) {
                try {
                    // Before rolling back the one-off patches, validate that the state until that point is consistent
                    validateRollbackState(invalidation.get(invalidation.size() - 1),
                            modification.getUnmodifiedInstallationState());
                } catch (PatchingException e) {
                    throw e;
                } catch (Exception e) {
                    throw new PatchingException(e);
                }
                // Invalidate the installed patches first
                for (final String rollback : invalidation) {
                    rollback(rollback, context);
                }
            }
        }

        // Add to installed patches list
        modification.addInstalledPatch(patchId);

        // Then apply the current patch
        for (final PatchElement element : patch.getElements()) {
            // Apply the content modifications
            final IdentityPatchContext.PatchEntry target = context.resolveForElement(element);
            final PatchElementProvider provider = element.getProvider();
            final Patch.PatchType elementPatchType = provider.getPatchType();
            final String elementPatchId = element.getId();
            // See if we can skip this element
            if (target.isApplied(elementPatchId)) {
                // TODO if it is already applied, we can just skip the entry (maybe based ont the type of the patch)
                // This needs some further testing, maybe we need to compare our history with the patch if they are consistent
                throw PatchLogger.ROOT_LOGGER.alreadyApplied(elementPatchId);
            }
            // Check upgrade conditions
            checkUpgradeConditions(provider, target);
            apply(elementPatchId, element.getModifications(), target);
            target.apply(elementPatchId, elementPatchType);
        }
        // Apply the patch to the identity
        final IdentityPatchContext.PatchEntry identityEntry = context.getIdentityEntry();
        apply(patchId, patch.getModifications(), identityEntry);
        identityEntry.apply(patchId, patchType);

        // Port forward missing module changes
        if (patchType == Patch.PatchType.CUMULATIVE) {
            portForward(patch, context);
        }

        // We need the resulting version for rollback
        if (patchType == Patch.PatchType.CUMULATIVE) {
            final Identity.IdentityUpgrade upgrade = identity.forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
            identityEntry.setResultingVersion(upgrade.getResultingVersion());
        }

        // Execute the tasks
        final IdentityApplyCallback callback = new IdentityApplyCallback(patch, identityEntry.getDirectoryStructure());
        try {
            return executeTasks(context, callback);
        } catch (Exception e) {
            context.cancel(callback);
            throw rethrowException(e);
        }
    }