1
0
mirror of https://github.com/git/git.git synced 2024-09-30 19:33:01 +02:00
Commit Graph

17 Commits

Author SHA1 Message Date
Johannes Sixt
c7f7457026 git-gui: "Stage Line": Treat independent changes in adjacent lines better
Assume that we want to commit these states:

  Old state == HEAD    Intermediate state   New state
  --------------------------------------------------------
  context before       context before       context before
  old 1                new 1                new 1
  old 2                old 2                new 2
  context after        context after        context after

that is, want to commit two changes in this order:

  1. transform "old 1" into "new 1"
  2. transform "old 2" into "new 2"

[This discussion and this patch is about this very case and one other case
as outlined below; any other intermediate states that one could imagine are
not affected by this patch.]

Now assume further, that we have not staged and commited anything, but we
have already changed the working file to the new state. Then we will see
this hunk in the "Unstaged Changes":

  @@ -1,4 +1,4 @@
   context before
  -old 1
  -old 2
  +new 1
  +new 2
   context after

The obvious way to stage the intermediate state is to apply "Stage This
Line" to "-old 1" and "+new 1". Unfortunately, this resulted in this
intermediate state:

  context before
  old 2
  new 1
  context after

which is not what we wanted. In fact, it was impossible to stage the
intermediate state using "Stage Line". The crux was that if a "+" line was
staged, then the "-" lines were converted to context lines and arranged
*before* the "+" line in the forged hunk that we fed to 'git apply'.

With this patch we now treat "+" lines that are staged differently. In
particular, the "-" lines before the "+" block are moved *after* the
staged "+" line. Now it is possible to get the correct intermediate state
by staging "-old 1" and "+new 1". Problem solved.

But there is a catch.

Noticing that we didn't get the right intermediate state by staging
"-old 1" and "+new 1", we could have had the idea to stage the complete
hunk and to *unstage* "-old 2" and "+new 2". But... the result is the same.
The reason is that there is the exact symmetric problem with unstaging the
last "-" and "+" line that are in adjacent blocks of "-" and "+" lines.

This patch does *not* change the way in which "-" lines are *unstaged*.

Why? Because if we did (i.e. move "+" lines before the "-" line after
converting them to context lines), then it would be impossible to stage
this intermediate state:

  context before
  old 1
  new 2
  context after

that is, it would be impossible to stage the two independet changes in the
opposite order.

Let's look at this case a bit further: The obvious way to get this
intermediate state would be to apply "Stage This Line" to "-old 2" and
"+new 2". Before this patch, this worked as expected. With this patch, it
does not work as expected, but it can still be achieved by first staging
the entire hunk, then *unstaging* "-old 1" and "+new 1".

In summary, this patch makes a common case possible, at the expense that
a less common case is made more complicated for the user.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-07-26 16:43:08 -07:00
Johannes Sixt
fa6b5b3944 git-gui: Fix "Stage/Unstage Line" with one line of context.
To "Stage/Unstage Line" we construct a patch that contains exactly one
change (either addition or removal); the hunk header was forged by counting
the old side and adjusting the count by +/-1 for the new side. But when we
counted the context we never counted the changed line itself. If the hunk
had only one removal line and one line of context, like this:

    @@ -1,3 +1,2 @@
     context 1
    -removal
     context 2

We had constructed this patch:

    @@ -1,2 +1,1 @@
     context 1
    -removal
     context 2

which does not apply because git apply deduces that it must apply at the
end of the file. ("context 2" is considered garbage and ignored.) The fix
is that removal lines must be counted towards the context of the old side.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-07-26 16:43:08 -07:00
Johannes Sixt
5821988f97 git-gui: Implement "Stage/Unstage Line"
This adds a context menu entry below "Stage/Unstage Hunk" that stages or
unstages just the line under the mouse pointer.

This is by itself useful, for example, if there are unrelated changes in
the same hunk and the hunk cannot be split by reducing the context.

The feature can also be used to split a hunk by staging a number of
additions (or unstaging a number of removals) until there are enough
context lines that the hunk gets split.

The implementation reads the complete hunk that the line lives in, and
constructs a new hunk by picking existing context lines, removing unneeded
change lines and transforming other change lines to context lines. The
resulting hunk is fed through 'git apply' just like in the "Stage/Unstage
Hunk" case.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-07-02 01:06:38 -04:00
Shawn O. Pearce
a41e45ea1c git-gui: Refresh file status description after hunk application
If we apply a hunk in either direction this may change the file's
status.  For example if a file is completely unstaged, and has at
least two hunks in it and the user stages one hunk the file will
change from "Modified, not staged" to "Portions staged for commit".

Resetting the file path causes our trace on this variable to fire;
that trace is used to update the file header in the diff viewer to
the file's current status.

Noticed by Johannes Sixt.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-01-16 01:29:39 -05:00
Shawn O. Pearce
a4750dd266 git-gui: Handle file mode changes (644->755) in diff viewer
Johannes Sixt pointed out the diff headers "old mode ..." and
"new mode ..." were not being parsed properly by git-gui.  We
now include them in the diff viewer for a file.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-12-14 01:51:22 -05:00
Shawn O. Pearce
31bb1d1b2d git-gui: Paper bag fix missing translated strings
The Tcl expression "[append [mc Foo] Bar]" does not return the string
"FooBar" after translation; instead it is setting the variable Foo to
the value Bar, or if Foo is already defined it is appending Bar onto
the end of it.  This is *not* what we wanted to have happen here.

Tcl's join function is actually the correct function but its default
joinStr argument is a single space.  Unfortunately all of our call
sites do not want an extra space added to their string.  So we need
a small wrapper function to make the call to join with an empty
join string.  In C this is (roughly) the job of the strcat function.
Since strcat is not yet used at the global level it is a reasonable
name to use here.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-09-14 01:51:18 -04:00
Michele Ballabio
c8c4854bec git-gui: add some strings to translation
Most of these changes were suggested by Shawn Pearce in an answer
to Johannes Schindelin.

Some strings for the blame module were added too.

[sp: Minor edits in blame module formatting]

Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-09-13 20:43:26 -04:00
Shawn O. Pearce
5f51ccd259 Merge branch 'maint'
* maint:
  git-gui: Trim trailing slashes from untracked submodule names
  git-gui: Assume untracked directories are Git submodules
  git-gui: handle "deleted symlink" diff marker
  git-gui: show unstaged symlinks in diff viewer
2007-09-09 21:02:57 -04:00
Shawn O. Pearce
3b9dfde3d6 git-gui: Assume untracked directories are Git submodules
If `git ls-files --others` returned us the name of a directory then
it is because Git has decided that this directory itself contains a
valid Git repository and its files shouldn't be listed as untracked
for this repository.

In such a case we should label the object as a Git repository and
not just as a directory.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-09-09 20:39:42 -04:00
Michele Ballabio
4ed1a190d0 git-gui: handle "deleted symlink" diff marker
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-09-09 19:47:26 -04:00
Michele Ballabio
2d19f8e921 git-gui: show unstaged symlinks in diff viewer
git-gui has a minor problem with regards to symlinks that point
to directories.

	git init
	mkdir realdir
	ln -s realdir linkdir
	git gui

Now clicking on file names in the "unstaged changes" window,
there's a problem coming from the "linkdir" symlink: git-gui
complains with

	error reading "file4": illegal operation on a directory

...even though git-gui can add that same symlink to the index just
fine.

This patch fix this by adding a check.

[sp: Minor fix to use {link} instead of "link" in condition
     and to only open the path if it is not a symlink.]

Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-09-09 19:47:22 -04:00
Christian Stimming
1ac17950e9 Mark strings for translation.
The procedure [mc ...] will translate the strings through msgcat.
Strings must be enclosed in quotes, not in braces, because otherwise
xgettext cannot extract them properly, although on the Tcl side both
delimiters would work fine.

[jes: I merged the later patches to that end.]

Signed-off-by: Christian Stimming <stimming@tuhh.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2007-09-02 16:54:48 +01:00
Shawn O. Pearce
6eb420ef61 git-gui: Always disable the Tcl EOF character when reading
On Windows (which includes Cygwin) Tcl defaults to leaving the EOF
character of input file streams set to the ASCII EOF character, but
if that character were to appear in the data stream then Tcl will
close the channel early.  So we have to disable eofchar on Windows.
Since the default is disabled on all platforms except Windows, we
can just disable it everywhere to prevent any sort of read problem.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-07-17 01:50:10 -04:00
Shawn O. Pearce
0b81261622 git-gui: Always use absolute path to all git executables
Rather than making the C library search for git every time we want
to execute it we now search for the main git wrapper at startup, do
symlink resolution, and then always use the absolute path that we
found to execute the binary later on.  This should save us some
cycles, especially on stat challenged systems like Cygwin/Win32.

While I was working on this change I also converted all of our
existing pipes ([open "| git ..."]) to use two new pipe wrapper
functions.  These functions take additional options like --nice
and --stderr which instructs Tcl to take special action, like
running the underlying git program through `nice` (if available)
or redirect stderr to stdout for capture in Tcl.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-07-09 01:17:09 -04:00
Shawn O. Pearce
699d5601f5 git-gui: Refactor our ui_status_value update technique
I'm really starting to dislike global variables.  The ui_status_value
global varible is just one of those that seems to appear in a lot of
code and in many cases we didn't even declare it "global" within the
proc that updates it so we haven't always been getting all of the
updates we expected to see.

This change introduces two new global procs:

  ui_status $msg;   # Sets the status bar to show $msg.
  ui_ready;         # Changes the status bar to show "Ready."

The second (special) form is used because we often update the area
with this message once we are done processing a block of work and
want the user to know we have completed it.

I'm not fixing the cases that appear in lib/branch.tcl right now
as I'm actually in the middle of a huge refactoring of that code
to support making a detached HEAD checkout.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-07-08 21:12:57 -04:00
Shawn O. Pearce
b8848f7753 git-gui: Allow as few as 0 lines of diff context
Johannes Sixt pointed out that dropping to 0 lines of context
does allow the user to get more fine-grained hunk selection,
especially since we don't currently support "highlight and
apply (or revert)".

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-05-31 23:32:54 -04:00
Shawn O. Pearce
f522c9b5ed git-gui: Refactor into multiple files to save my sanity
I'm finding it difficult to work with a 6,000+ line Tcl script
and not go insane while looking for a particular block of code.
Since most of the program is organized into different units of
functionality and not all users will need all units immediately
on startup we can improve things by splitting procs out into
multiple files and let auto_load handle things for us.

This should help not only to better organize the source, but
it may also improve startup times for some users as the Tcl
parser does not need to read as much script before it can show
the UI.  In many cases the user can avoid reading at least half
of git-gui now.

Unfortunately we now need a library directory in our runtime
location.  This is currently assumed to be $(sharedir)/git-gui/lib
and its expected that the Makefile invoker will setup some sort of
reasonable sharedir value for us, or let us assume its going to be
$(gitexecdir)/../share.

We now also require a tclsh (in TCL_PATH) to just run the Makefile,
as we use tclsh to generate the tclIndex for our lib directory.  I'm
hoping this is not an unncessary burden on end-users who are building
from source.

I haven't really made any functionality changes here, this is just a
huge migration of code from one file to many smaller files.  All of
the new changes are to setup the library path and install the library
files.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-05-07 23:35:48 -04:00