]> git.lyx.org Git - lyx.git/commitdiff
git VCS: add support for short hashes in inset info ("Abbreviated revision").
authorPavel Sanda <sanda@lyx.org>
Sun, 28 Jul 2019 20:01:17 +0000 (22:01 +0200)
committerPavel Sanda <sanda@lyx.org>
Sun, 28 Jul 2019 20:01:17 +0000 (22:01 +0200)
Fixes bug #11620.

Patch from Joel Kulesza.

development/FORMAT
lib/lyx2lyx/lyx_2_4.py
src/LyXVC.h
src/VCBackend.cpp
src/VCBackend.h
src/insets/InsetInfo.cpp
src/version.h

index 61f990e4db406542b173eb9850eb28c48f47a7cd..688869231e9a781385910ff9d7fb3ffe766d3307 100644 (file)
@@ -7,6 +7,11 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2019-07-26 Joel Kulesza <jkulesza@gmail.com>
+       * Format incremented to 584: support for revision InsetInfo addition of
+        revision-abbrev. This entry is added to accommodate git abbreviated
+        hashes.
+
 2019-07-17  Kornel Benko <kornel@lyx.org>
         Jürgen Spitzmüller <spitz@lyx.org>
        * format incremented to 583: Support for the Chivo and CrimsonPro font families.
index e7962c64b4ac264e0f784784d2471ae747adf1d0..7473699e08b25fa149ad22281ba7451bf299f508 100644 (file)
@@ -1056,6 +1056,26 @@ def revert_vcsinfo(document):
         document.body[tp] = "type \"buffer\""
         document.body[arg] = "arg \"vcs-" + argv + "\""
 
+def revert_vcsinfo_rev_abbrev(document):
+    " Convert abbreviated revisions to regular revisions. "
+
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset Info", i+1)
+        if i == -1:
+            return
+        j = find_end_of_inset(document.body, i+1)
+        if j == -1:
+            document.warning("Malformed LyX document: Could not find end of Info inset.")
+            continue
+        tp = find_token(document.body, 'type', i, j)
+        tpv = get_quoted_value(document.body, "type", tp)
+        if tpv != "vcs":
+            continue
+        arg = find_token(document.body, 'arg', i, j)
+        argv = get_quoted_value(document.body, "arg", arg)
+        if( argv == "revision-abbrev" ):
+            document.body[arg] = "arg \"revision\""
 
 def revert_dateinfo(document):
     " Revert date info insets to static text. "
@@ -3147,9 +3167,11 @@ convert = [
            [581, [convert_osf]],
            [582, [convert_AdobeFonts,convert_latexFonts,convert_notoFonts,convert_CantarellFont,convert_FiraFont]],# old font re-converterted due to extra options
            [583, [convert_ChivoFont,convert_Semibolds,convert_NotoRegulars,convert_CrimsonProFont]],
+           [584, []],
           ]
 
-revert =  [[582, [revert_ChivoFont,revert_CrimsonProFont]],
+revert =  [[583, [revert_vcsinfo_rev_abbrev]],
+           [582, [revert_ChivoFont,revert_CrimsonProFont]],
            [581, [revert_CantarellFont,revert_FiraFont]],
            [580, [revert_texfontopts,revert_osf]],
            [579, [revert_minionpro, revert_plainNotoFonts_xopts, revert_notoFonts_xopts, revert_IBMFonts_xopts, revert_AdobeFonts_xopts, revert_font_opts]], # keep revert_font_opts last!
index b304730700bb9baad739418e9624883cb236cb60..d3dc1c6ff8d4887976aa500626e1f7548f0c958b 100644 (file)
@@ -176,7 +176,8 @@ public:
                Tree = 2,
                Author = 3,
                Date = 4,
-               Time = 5
+               Time = 5,
+               FileAbbrev = 6
        };
 
        /**
index 0338e674c2387bc56c0f8bf174b68aca9fff0f14..42fd36be318c17358fb5cb8f7b87198cede63a93 100644 (file)
@@ -2125,14 +2125,20 @@ string GIT::revisionInfo(LyXVC::RevisionInfo const info)
 
        // fill the rest of the attributes for a single file
        if (rev_file_cache_.empty())
-               if (!getFileRevisionInfo())
+               if (!getFileRevisionInfo()) {
                        rev_file_cache_ = "?";
+                       rev_file_abbrev_cache_ = "?";
+    }
 
        switch (info) {
                case LyXVC::File:
                        if (rev_file_cache_ == "?")
                                return string();
                        return rev_file_cache_;
+               case LyXVC::FileAbbrev:
+                       if (rev_file_abbrev_cache_ == "?")
+                               return string();
+                       return rev_file_abbrev_cache_;
                case LyXVC::Author:
                        return rev_author_cache_;
                case LyXVC::Date:
@@ -2156,7 +2162,7 @@ bool GIT::getFileRevisionInfo()
                return false;
        }
 
-       doVCCommand("git log -n 1 --pretty=format:%H%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
+       doVCCommand("git log -n 1 --pretty=format:%H%n%h%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
                    + " > " + quoteName(tmpf.toFilesystemEncoding()),
                    FileName(owner_->filePath()));
 
@@ -2167,6 +2173,8 @@ bool GIT::getFileRevisionInfo()
 
        if (ifs)
                getline(ifs, rev_file_cache_);
+       if (ifs)
+               getline(ifs, rev_file_abbrev_cache_);
        if (ifs)
                getline(ifs, rev_author_cache_);
        if (ifs) {
index 570c4a295f2ccfe3c91c1c4be68a5cba29f7401f..2ee076f2e1d0b2b4ad8ad70a587a4dfa1e6e0419 100644 (file)
@@ -560,6 +560,8 @@ private:
        bool getFileRevisionInfo();
        /// cache for file revision number, "?" if already unsuccessful, isNumber==true
        std::string rev_file_cache_;
+       /// cache for abbreviated file revision number, "?" if already unsuccessful, isNumber==true
+       std::string rev_file_abbrev_cache_;
        /// cache for author of last commit
        std::string rev_author_cache_;
        /// cache for date of last commit
index f9309c118c9a4ee9f7b1f426f2d5f2d78b89795c..2e42ad0e0ad239ab08f3687b84e2ef461233d83f 100644 (file)
@@ -278,6 +278,7 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
                        break;
                }
                result.push_back(make_pair("revision", _("Revision[[Version Control]]")));
+               result.push_back(make_pair("revision-abbrev", _("Abbreviated revision[[Version Control]]")));
                result.push_back(make_pair("tree-revision", _("Tree revision")));
                result.push_back(make_pair("author", _("Author")));
                result.push_back(make_pair("date", _("Date")));
@@ -385,7 +386,7 @@ bool InsetInfoParams::validateArgument(Buffer const * buf, docstring const & arg
                        || name == "path" || name == "class");
 
        case VCS_INFO:
-               if (name == "revision" || name == "tree-revision"
+               if (name == "revision" || name == "revision-abbrev" || name == "tree-revision"
                    || name == "author" || name == "date" || name == "time")
                        return buf->lyxvc().inUse();
                return false;
@@ -529,6 +530,8 @@ docstring InsetInfo::toolTip(BufferView const &, int, int) const
        case InsetInfoParams::VCS_INFO:
                if (params_.name == "revision")
                        result = _("Version control revision");
+               else if (params_.name == "revision-abbrev")
+                       result = _("Version control abbreviated revision");
                else if (params_.name == "tree-revision")
                        result = _("Version control tree revision");
                else if (params_.name == "author")
@@ -1099,6 +1102,8 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
                LyXVC::RevisionInfo itype = LyXVC::Unknown;
                if (params_.name == "revision")
                        itype = LyXVC::File;
+               else if (params_.name == "revision-abbrev")
+                       itype = LyXVC::FileAbbrev;
                else if (params_.name == "tree-revision")
                        itype = LyXVC::Tree;
                else if (params_.name == "author")
index e957b7ad2172fe7a7ec524b77f50edd97f46c358..8e3e17a0ec9da889581ff5d9598158c49a3226d5 100644 (file)
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 583 // Kornel: Add Chivo sans serif font
-#define LYX_FORMAT_TEX2LYX 583
+#define LYX_FORMAT_LYX 584 // Kornel: Add Chivo sans serif font
+#define LYX_FORMAT_TEX2LYX 584
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER