Resolve a revision to a new RevOptions object with the SHA1 of the
        branch, tag, or ref if found.

        Args:
          rev_options: a RevOptions object.
961880
def resolve_revision(self, dest, url, rev_options):
        
        rev = rev_options.arg_rev
        sha, is_branch = self.get_revision_sha(dest, rev)

        if sha is not None:
            rev_options = rev_options.make_new(sha)
            rev_options.branch_name = rev if is_branch else None

            return rev_options

        # Do not show a warning for the common case of something that has
        # the form of a Git commit hash.
        if not looks_like_hash(rev):
            logger.warning(
                "Did not find branch or tag '%s', assuming revision or ref.",
                rev,
            )

        if not rev.startswith('refs/'):
            return rev_options

        # If it looks like a ref, we have to fetch it explicitly.
        self.run_command(
            ['fetch', '-q', url] + rev_options.to_args(),
            cwd=dest,
        )
        # Change the revision to the SHA of the ref we fetched
        sha = self.get_revision(dest, rev='FETCH_HEAD')
        rev_options = rev_options.make_new(sha)

        return rev_options
683331
def amendPrevious(self, targethash):
        ''

        prevBranch = loggit_all('rev-parse', '--symbolic-full-name', '--abbrev-ref', 'HEAD').strip()

        ret = loggit_all('commit', '-m', 'MERGE '+targethash) # commit index to viewed branch
        newChanges = loggit_all('rev-parse', 'HEAD').strip()

        ret += loggit_all('stash', 'save', '--keep-index') # stash everything else
        with GitUndo('stash', 'pop'):
            tmpBranch = randomBranchName()
            ret += loggit_all('checkout', '-b', tmpBranch) # create/switch to tmp branch
            with GitUndo('checkout', prevBranch), GitUndo('branch', '-D', tmpBranch):
                ret += loggit_all('reset', '--hard', targethash) # tmpbranch now at targethash
                ret += loggit_all('cherry-pick', '-n', newChanges)  # pick new change from original branch
                ret += loggit_all('commit', '--amend', '--no-edit')  # recommit to fix targethash (which will change)
                ret += loggit_all('rebase', '--onto', tmpBranch, 'HEAD@{1}', prevBranch)  # replay the rest

        return ret.splitlines()
557746
def commit(self, revision, is_amend=False):
        
        if not isinstance(revision, Revision):
            raise InvalidArgType()

        if not self.current_client:
            raise ClientNotSpecified()

        if is_amend:
            self.current_client.save(revision)
        else:
            self.current_client.write()
            self.current_client.save(revision)

        return self
778550
def make_new(self, rev):
        # type: (str) -> RevOptions
        
        return self.vcs.make_rev_options(rev, extra_args=self.extra_args)
402925
private static int findCommonAncestor(RevisionInternal rev, List<String> possibleRevIDs) {
        if (possibleRevIDs == null || possibleRevIDs.size() == 0) {
            return 0;
        }
        List<String> history = Database.parseCouchDBRevisionHistory(rev.getProperties());

        //rev is missing _revisions property
        assert (history != null);

        boolean changed = history.retainAll(possibleRevIDs);
        String ancestorID = history.size() == 0 ? null : history.get(0);

        if (ancestorID == null) {
            return 0;
        }

        int generation = RevisionUtils.parseRevIDNumber(ancestorID);

        return generation;
    }
608742
def new_from_sha(cls, repo, sha1):
        
        if sha1 == cls.NULL_BIN_SHA:
            # the NULL binsha is always the root commit
            return get_object_type_by_name(b'commit')(repo, sha1)
        # END handle special case
        oinfo = repo.odb.info(sha1)
        inst = get_object_type_by_name(oinfo.type)(repo, oinfo.binsha)
        inst.size = oinfo.size
        return inst
172157
def v2_translator(self, option):
        
        new_option = option
        new_value = getattr(self, option)

        renaming_pairs = {
            "dontfrag": "dont_fragment",
            "maxhops": "max_hops",
            "firsthop": "first_hop",
            "use_NSID": "set_nsid_bit",
            "cd": "set_cd_bit",
            "do": "set_do_bit",
            "qbuf": "include_qbuf",
            "recursion_desired": "set_rd_bit",
            "noabuf": "include_abuf"
        }
        if option in renaming_pairs.keys():
            warninglog = (
                "DeprecationWarning: {0} option has been deprecated and "
                "renamed to {1}."
            ).format(option, renaming_pairs[option])
            print(warninglog)
            new_option = renaming_pairs[option]

        # noabuf was changed to include_abuf so we need a double-negative
        if option == "noabuf":
            new_value = not new_value

        return new_option, new_value
75577
def get_revision(cls, id, revision, api=None):
        
        api = api if api else cls._API
        extra = {'resource': cls.__name__, 'query': {
            'id': id,
            'revision': revision
        }}
        logger.info('Get revision', extra=extra)
        app = api.get(url=cls._URL['get_revision'].format(
            id=id, revision=revision)).json()
        return App(api=api, **app)
428301
def resolve_tag_repo_ref!(tag)
      return unless tag.has_repo?
      repo = core.repo_manager.find_repository(tag.repo)
      # set latest version
      if tag.has_ref? === false
        if repo.has_package_versions?
          tag.set_ref repo.latest_package_version
        else
          tag.set_ref repo.current_ref
        end
      else
        unless repo.has_ref?(tag.ref)
          new_ref = repo.latest_version(tag.ref)
          raise "error" if new_ref.nil?
          tag.set_ref new_ref
        end
      end
    end
797782
def _extract_rev(self, line1, line2):
        

        try:
            if line1.startswith('--- ') and line2.startswith('+++ '):
                l1 = line1[4:].split(None, 1)
                old_filename = l1[0].lstrip('a/') if len(l1) >= 1 else None
                old_rev = l1[1] if len(l1) == 2 else 'old'

                l2 = line2[4:].split(None, 1)
                new_filename = l2[0].lstrip('b/') if len(l1) >= 1 else None
                new_rev = l2[1] if len(l2) == 2 else 'new'

                filename = old_filename if (old_filename !=
                                            'dev/null') else new_filename

                return filename, new_rev, old_rev
        except (ValueError, IndexError):
            pass

        return None, None, None
1040249
private RevisionInternal applyOptionsToRevision(EnumSet<TDContentOptions> options, RevisionInternal rev) {
        if (options != null && (
                options.contains(TDContentOptions.TDIncludeLocalSeq) ||
                        options.contains(TDContentOptions.TDIncludeRevs) ||
                        options.contains(TDContentOptions.TDIncludeRevsInfo) ||
                        options.contains(TDContentOptions.TDIncludeConflicts) ||
                        options.contains(TDContentOptions.TDBigAttachmentsFollow))) {

            Map<String, Object> dst = new HashMap<String, Object>();
            dst.putAll(rev.getProperties());
            if (options.contains(TDContentOptions.TDIncludeLocalSeq)) {
                dst.put("_local_seq", rev.getSequence());
                rev.setProperties(dst);
            }
            if (options.contains(TDContentOptions.TDIncludeRevs)) {
                List<RevisionInternal> revs = db.getRevisionHistory(rev);
                Map<String, Object> historyDict = RevisionUtils.makeRevisionHistoryDict(revs);
                dst.put("_revisions", historyDict);
                rev.setProperties(dst);
            }
            if (options.contains(TDContentOptions.TDIncludeRevsInfo)) {
                List<Object> revsInfo = new ArrayList<Object>();
                List<RevisionInternal> revs = db.getRevisionHistory(rev);
                for (RevisionInternal historicalRev : revs) {
                    Map<String, Object> revHistoryItem = new HashMap<String, Object>();
                    String status = "available";
                    if (historicalRev.isDeleted()) {
                        status = "deleted";
                    }
                    if (historicalRev.isMissing()) {
                        status = "missing";
                    }
                    revHistoryItem.put("rev", historicalRev.getRevID());
                    revHistoryItem.put("status", status);
                    revsInfo.add(revHistoryItem);
                }
                dst.put("_revs_info", revsInfo);
                rev.setProperties(dst);
            }
            if (options.contains(TDContentOptions.TDIncludeConflicts)) {
                RevisionList revs = db.getAllRevisions(rev.getDocID(), true);
                if (revs.size() > 1) {
                    List<String> conflicts = new ArrayList<String>();
                    for (RevisionInternal aRev : revs) {
                        if (aRev.equals(rev) || aRev.isDeleted()) {
                            // don't add in this case
                        } else {
                            conflicts.add(aRev.getRevID());
                        }
                    }
                    dst.put("_conflicts", conflicts);
                }
                rev.setProperties(dst);
            }
            if (options.contains(TDContentOptions.TDBigAttachmentsFollow)) {
                RevisionInternal nuRev = new RevisionInternal(dst);
                Status outStatus = new Status(Status.OK);
                if (!db.expandAttachments(nuRev, 0, false, getBooleanQuery("att_encoding_info"), outStatus))
                    return null;
                rev = nuRev;
            }
        }
        return rev;
    }
1023271
def set_revision_meta_attribute(revision, attribute, value)
      case value
      when Symbol
        value = self.send(value)
      when Proc
        value = value.call(self)
      end
      revision.send("#{attribute}=", value)
    end
818973
def query_revisions_by_revids(session, revids, **params):
    
    doc = session.get(action='query', prop='revisions',
                      revids=revids, **params)

    for page_doc in doc['query'].get('pages', {}).values():
        revisions = page_doc.get('revisions', [])
        if 'revisions' in page_doc:
            del page_doc['revisions']

        for revision_doc in revisions:
            revision_doc['page'] = page_doc
            yield revision_doc
711647
def checkout(self, revision, options):
        
        rev = revision.key
        self.repo.git.checkout(rev)
631438
def save(self, revision):
        
        if not isinstance(revision, Revision):
            raise InvalidArgType()

        self.state.update(revision)
931507
@InterfaceAudience.Private
    protected void queueRemoteRevision(RevisionInternal rev) {
        if (rev.isDeleted()) {
            deletedRevsToPull.add(rev);
        } else {
            revsToPull.add(rev);
        }
    }
630344
def revfile_path(self):
        
        return os.path.normpath(os.path.join(
            os.getcwd(),
            self.config.revision_file
        ))