Reduce a patch down to just changed lines
@param  {String} patch The complete patch with surrounding context
@return {Object}       Stats about the changed lines
171005
function analyzePatch(patch) {
  const patchLines = patch.split('\n').reduce((reducedPatch, currentLine) => {
    if (currentLine.match(/^[-+]/)) {
      return reducedPatch.concat(currentLine.replace(/^[-+]+\s*/, ''));
    }
    return reducedPatch;
  }, []);
  return {
    lines: patchLines.length,
    chars: patchLines.join('').length
  };
}
714800
function grunt(gruntInst, verbose, patch) {
		var mw = (patch || core.base());
		mw.enabled = true;
		if (verbose) {
			mw.writeln = function (line) {
				if (mw.enabled) {
					gruntInst.verbose.writeln(line);
				}
			};
		}
		else {
			mw.writeln = function (line) {
				if (mw.enabled) {
					gruntInst.log.writeln(line);
				}
			};
		}
		if (!patch) {
			mw.toString = function () {
				return '<miniwrite-grunt>';
			};
		}
		return mw;
	}
618175
function updateLines(from, to, newText, selFrom, selTo) {
      if (suppressEdits) return;
      var old = [];
      doc.iter(from.line, to.line + 1, function(line) {
        old.push(newHL(line.text, line.markedSpans));
      });
      if (history) {
        history.addChange(from.line, newText.length, old);
        while (history.done.length > options.undoDepth) history.done.shift();
      }
      var lines = updateMarkedSpans(hlSpans(old[0]), hlSpans(lst(old)), from.ch, to.ch, newText);
      updateLinesNoUndo(from, to, lines, selFrom, selTo);
    }
340638
function getChanges(log, regex) {
      var changes = [];
      var match;

      while ((match = regex.exec(log))) {
        var change = '';

        for (var i = 1, len = match.length; i < len; i++) {
          change += match[i];
        }

        changes.push(change.trim());
      }

      return changes;
    }
710839
def patches
      patch = {}
      loaded_headers.each do |header|
        header.patches.each do |key, val|
          patch[key + header.offset] = val
        end
      end
      patch
    end
773350
def make_patch( expected, actual )
      diffs = Diff::LCS.sdiff( expected.split("\n"), actual.split("\n"),
        Diff::LCS::ContextDiffCallbacks )

      maxcol = diffs.flatten.
        collect {|d| [d.old_element.to_s.length, d.new_element.to_s.length ] }.
        flatten.max || 0
      maxcol += 4

      patch = "              %#{maxcol}s | %s\n" % [ "Expected", "Actual" ]
      patch << diffs.collect do |changeset|
        changeset.collect do |change|
          "%s [%03d, %03d]: %#{maxcol}s | %-#{maxcol}s" % [
            change.action,
            change.old_position,
            change.new_position,
            change.old_element.inspect,
            change.new_element.inspect,
          ]
        end.join("\n")
      end.join("\n---\n")
    end
726476
function applyPatches (versions) {
    versions = sortVersions(versions, 'ASC')

    let state = []
    // iterate patches to the final one => get previous commit state
    versions.forEach((v) => {
      v.changes.forEach((c) => {
        if (c.operation === 'insert') {
          return state.push({
            entityId: c.entityId,
            entitySet: c.entitySet,
            entity: parse(c.serializedDoc),
            path: c.path
          })
        }

        if (c.operation === 'remove') {
          state = state.filter((e) => e.entityId !== c.entityId)
          return
        }

        const entityState = state.find((e) => e.entityId === c.entityId)
        applyPatch(entityState.entity, parse(c.serializedPatch), c.entitySet, documentModel)
      })
    })
    return state
  }
457252
def patch(self, patch: int) -> None:
        
        self.filter_negatives(patch)
        self._patch = patch
951734
def patch_lines(x):
    
    for idx in range(len(x)-1):
        x[idx] = np.vstack([x[idx], x[idx+1][0,:]])
    return x
701198
function (increment) {
        increment = increment || Semver.PATCH; // default is patch
        switch (increment) {
            /* jshint indent: false */
            case Semver.MAJOR:
                this.major++;
                this.minor = this.patch = 0;
                break;
            case Semver.MINOR:
                this.minor++;
                this.patch = 0;
                break;
            case Semver.PATCH:
                this.patch++;
                break;
        }
        return this;
    }
47425
function patch(element, previous, dataset) {
  if (!previous && !dataset) {
    return dataset;
  }
  var name;
  previous = previous || {};
  dataset = dataset || {};

  for (name in previous) {
    if (dataset[name] === undefined) {
      delete element.dataset[name];
    }
  }

  for (name in dataset) {
    if (previous[name] === dataset[name]) {
      continue;
    }
    element.dataset[name] = dataset[name];
  }

  return dataset;
}
46509
def patch_addContext(self, patch, text):
    
    if len(text) == 0:
      return
    pattern = text[patch.start2 : patch.start2 + patch.length1]
    padding = 0

    # Look for the first and last matches of pattern in text.  If two different
    # matches are found, increase the pattern length.
    while (text.find(pattern) != text.rfind(pattern) and (self.Match_MaxBits ==
        0 or len(pattern) < self.Match_MaxBits - self.Patch_Margin -
        self.Patch_Margin)):
      padding += self.Patch_Margin
      pattern = text[max(0, patch.start2 - padding) :
                     patch.start2 + patch.length1 + padding]
    # Add one chunk for good luck.
    padding += self.Patch_Margin

    # Add the prefix.
    prefix = text[max(0, patch.start2 - padding) : patch.start2]
    if prefix:
      patch.diffs[:0] = [(self.DIFF_EQUAL, prefix)]
    # Add the suffix.
    suffix = text[patch.start2 + patch.length1 :
                  patch.start2 + patch.length1 + padding]
    if suffix:
      patch.diffs.append((self.DIFF_EQUAL, suffix))

    # Roll back the start points.
    patch.start1 -= len(prefix)
    patch.start2 -= len(prefix)
    # Extend lengths.
    patch.length1 += len(prefix) + len(suffix)
    patch.length2 += len(prefix) + len(suffix)
1366086
function(patch) {
			// patch [key, null] means 'remove'
			if (patch === null) {
				this.remove();
				return _getResolvedPromise(this);
			}
			// TODO: make sure that root node is not collapsed or modified
			// copy (most) attributes to node.ATTR or node.data.ATTR
			var name,
				promise,
				v,
				IGNORE_MAP = { children: true, expanded: true, parent: true }; // TODO: should be global

			for (name in patch) {
				v = patch[name];
				if (!IGNORE_MAP[name] && !$.isFunction(v)) {
					if (NODE_ATTR_MAP[name]) {
						this[name] = v;
					} else {
						this.data[name] = v;
					}
				}
			}
			// Remove and/or create children
			if (patch.hasOwnProperty("children")) {
				this.removeChildren();
				if (patch.children) {
					// only if not null and not empty list
					// TODO: addChildren instead?
					this._setChildren(patch.children);
				}
				// TODO: how can we APPEND or INSERT child nodes?
			}
			if (this.isVisible()) {
				this.renderTitle();
				this.renderStatus();
			}
			// Expand collapse (final step, since this may be async)
			if (patch.hasOwnProperty("expanded")) {
				promise = this.setExpanded(patch.expanded);
			} else {
				promise = _getResolvedPromise(this);
			}
			return promise;
		}
1132093
func Patch(url string, v ...interface{}) (*Resp, error) {
	return std.Patch(url, v...)
}
667963
function patchArray(original, newA, basePath) {
  let patches = [];
  const oldA = original.slice();
  let tmpIdx = -1;

  function findIndex(a, id, idx) {
    if (a[idx] && isUndef(a[idx].qInfo)) {
      return null;
    } if (a[idx] && a[idx].qInfo.qId === id) {
      // shortcut if identical
      return idx;
    }
    for (let ii = 0, ll = a.length; ii < ll; ii += 1) {
      if (a[ii] && a[ii].qInfo.qId === id) {
        return ii;
      }
    }
    return -1;
  }

  if (compare(newA, oldA)) {
    // array is unchanged
    return patches;
  }

  if (!isUndef(newA[0]) && isUndef(newA[0].qInfo)) {
    // we cannot create patches without unique identifiers, replace array...
    patches.push({
      op: 'replace',
      path: basePath,
      value: newA,
    });
    return patches;
  }

  for (let i = oldA.length - 1; i >= 0; i -= 1) {
    tmpIdx = findIndex(newA, oldA[i].qInfo && oldA[i].qInfo.qId, i);
    if (tmpIdx === -1) {
      patches.push({
        op: 'remove',
        path: `${basePath}/${i}`,
      });
      oldA.splice(i, 1);
    } else {
      patches = patches.concat(JSONPatch.generate(oldA[i], newA[tmpIdx], `${basePath}/${i}`));
    }
  }

  for (let i = 0, l = newA.length; i < l; i += 1) {
    tmpIdx = findIndex(oldA, newA[i].qInfo && newA[i].qInfo.qId);
    if (tmpIdx === -1) {
      patches.push({
        op: 'add',
        path: `${basePath}/${i}`,
        value: newA[i],
      });
      oldA.splice(i, 0, newA[i]);
    } else if (tmpIdx !== i) {
      patches.push({
        op: 'move',
        path: `${basePath}/${i}`,
        from: `${basePath}/${tmpIdx}`,
      });
      oldA.splice(i, 0, oldA.splice(tmpIdx, 1)[0]);
    }
  }
  return patches;
}
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;
    }
1218514
def discover(patches, verbose, name):
    """"""
    patches = _get_mongopatcher().discover(directory=patches)
    if name:
        import re
        patches = [p for p in patches if re.match(name, p.target_version)]
    if not patches:
        print('No patches found')
    else:
        print('Patches available:')
        for patch in patches:
            if verbose:
                print()
                print(patch.target_version)
                print("~" * len(patch.target_version))
                print(tabulate(patch.patchnote))
            else:
                print(' - %s' % patch.target_version)