Hello,

I'm maintaining a Git Gui (https://github.com/Murmele/Gittyup) and there we 
are able to stage single lines of files.
The problem is that it does not work for specific cases as seen below. If 
you compare line 4-6 in the HEAD diff and line 4-6 in the staged patch it 
can be seen that in the first case an empty line will be remove at the 
beginning and in the staged patch the new line will be removed at the end 
of the three deletions.
Is it somehow possible to change this behaviour so that this case does not 
occur? Or is there another way to find out which line of the patch is 
staged or not?

The algorithm I used can be seen here: 
https://github.com/Murmele/Gittyup/blob/0b979594a82a665e53a5582ba8e538c70b8d2fce/src/ui/DiffView/HunkWidget.cpp#L850-L1003

diff to head with staged and unstaged changes:
```
martin% git diff HEAD                                 
diff --git a/src/kdefrontend/GuiTools.cpp b/src/kdefrontend/GuiTools.cpp 
index 3e0a2fdbb..1b08493ab 100644 
--- a/src/kdefrontend/GuiTools.cpp 
+++ b/src/kdefrontend/GuiTools.cpp 
@@ -305,9 +305,12 @@ QImage GuiTools::importPDFFile(const QString& 
fileName) { 
       document->setRenderHint(Poppler::Document::TextHinting); 
       document->setRenderHint(Poppler::Document::TextSlightHinting); 
       document->setRenderHint(Poppler::Document::ThinLineSolid); 
- 
-       const static int dpi = QApplication::desktop()->logicalDpiX(); 
-       QImage image = page->renderToImage(dpi, dpi); 
+       const double scaling = 1.5;     // scale to reasonable size 
+       QImage image; 
+       if (dpi) 
+               image = page->renderToImage((double)dpi, (double)dpi); 
+       else 
+               image = page->renderToImage(scaling * 
QApplication::desktop()->logicalDpiX(), scaling * 
QApplication::desktop()->logicalDpiY()); 
 
       delete page; 
       delete document;
```
staged diff
```
martin% git diff --cached 
diff --git a/src/kdefrontend/GuiTools.cpp b/src/kdefrontend/GuiTools.cpp 
index 3e0a2fdbb..0ff9e32a7 100644 
--- a/src/kdefrontend/GuiTools.cpp 
+++ b/src/kdefrontend/GuiTools.cpp 
@@ -306,9 +306,6 @@ QImage GuiTools::importPDFFile(const QString& fileName) 
{ 
       document->setRenderHint(Poppler::Document::TextSlightHinting); 
       document->setRenderHint(Poppler::Document::ThinLineSolid); 
 
-       const static int dpi = QApplication::desktop()->logicalDpiX(); 
-       QImage image = page->renderToImage(dpi, dpi); 
- 
       delete page; 
       delete document; 
```

Best regards,
Martin

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/git-users/6d3201ec-6c71-4d79-bbae-fc9d249fc11cn%40googlegroups.com.

Reply via email to