commit a6634f5bb376e3456e7265503661f3e3ec7ac106
Author: Pavel Sanda <sa...@lyx.org>
Date:   Sun Jul 28 22:01:17 2019 +0200

    git VCS: add support for short hashes in inset info ("Abbreviated 
revision").
    
    Fixes bug #11620.
    
    Patch from Joel Kulesza.
---
 development/FORMAT       |    5 +++++
 lib/lyx2lyx/lyx_2_4.py   |   24 +++++++++++++++++++++++-
 src/LyXVC.h              |    3 ++-
 src/VCBackend.cpp        |   12 ++++++++++--
 src/VCBackend.h          |    2 ++
 src/insets/InsetInfo.cpp |    7 ++++++-
 src/version.h            |    4 ++--
 7 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index 61f990e..6888692 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,11 @@ changes happened in particular if possible. A good example 
would be
 
 -----------------------
 
+2019-07-26 Joel Kulesza <jkule...@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 <kor...@lyx.org>
         Jürgen Spitzmüller <sp...@lyx.org>
        * format incremented to 583: Support for the Chivo and CrimsonPro font 
families.
diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py
index e7962c6..7473699 100644
--- a/lib/lyx2lyx/lyx_2_4.py
+++ b/lib/lyx2lyx/lyx_2_4.py
@@ -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!
diff --git a/src/LyXVC.h b/src/LyXVC.h
index b304730..d3dc1c6 100644
--- a/src/LyXVC.h
+++ b/src/LyXVC.h
@@ -176,7 +176,8 @@ public:
                Tree = 2,
                Author = 3,
                Date = 4,
-               Time = 5
+               Time = 5,
+               FileAbbrev = 6
        };
 
        /**
diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp
index 0338e67..42fd36b 100644
--- a/src/VCBackend.cpp
+++ b/src/VCBackend.cpp
@@ -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()));
 
@@ -2168,6 +2174,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) {
                string line;
diff --git a/src/VCBackend.h b/src/VCBackend.h
index 570c4a2..2ee076f 100644
--- a/src/VCBackend.h
+++ b/src/VCBackend.h
@@ -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
diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index f9309c1..2e42ad0 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -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")
diff --git a/src/version.h b/src/version.h
index e957b7a..8e3e17a 100644
--- a/src/version.h
+++ b/src/version.h
@@ -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

Reply via email to