git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Re: Re: Re: Remove need to untrack before tracking new branch

From
MSMartin Schlemmer <azarah@nosferatu.za.org>
Date
Apr 14, 2005, 09:55 UTC
Message-ID
<1113472557.23299.99.camel@nosferatu.lan>
In-Reply-To
<1113471609.23299.95.camel@nosferatu.lan>
On Thu, 2005-04-14 at 11:40 +0200, Martin Schlemmer wrote:
Show 32 quoted lines
> On Thu, 2005-04-14 at 11:11 +0200, Petr Baudis wrote:
> > Please trim the replied mails a bit, snipping old and irrelevant parts.
> > This is insane. :-)
> > 
> > Dear diary, on Thu, Apr 14, 2005 at 10:38:25AM CEST, I got a letter
> > where Martin Schlemmer <azarah@nosferatu.za.org> told me that...
> > ..snip..
> > > Normalize show-diff output, add --update-modes target to update-cache,
> > > and make sure we only show real changes after changing the tracked
> > > branch, as well as update the file modes according to the cache.
> > 
> > I'm lost. Why do you do --update-modes? That makes no sense to me.
> > You introduce them to the cache out-of-order w.r.t. commits, that means
> > in the normal git usage they are already unrevertable.
> > 
> 
> Right, afterwards I thought I did add it to the wrong place.
> 
> 
> > What are you trying to do? Mode changes _are_ real changes. You _don't_
> > want to silence them. What you want is to even show them more explicitly
> > in show-diff.
> > 
> 
> No, you do not understand.  If you actually change the mode, it will
> show.  What now happens, is that say I track the 'linus' branch, then
> untrack, and then track 'pasky' again, the Patches will be applied, but
> not the mode changes which are stored in the cache ...
>
> So basically the modes that are stored in the cache are not applied ...
> Although, yes, I prob should add the relevant code to checkout-cache.
> 
Ok, this should be a better one I think.
----

Normalize show-diff output, add --update-modes target to update-cache, and make sure we only show real changes after changing the tracked branch, as well as update the file modes according to the cache.

Signed-off-by: Martin Schlemmer <azarah@nosferatu.za.org>

checkout-cache.c: f06871cdbc1b18ea93bdf4e17126aeb4cca1373e --- f06871cdbc1b18ea93bdf4e17126aeb4cca1373e/checkout-cache.c +++ uncommitted/checkout-cache.c

@@ -34,7 +34,7 @@
  */
 #include "cache.h"

-static int force = 0, quiet = 0;
+static int force = 0, quiet = 0, update_mode = 0;

 static void create_directories(const char *path)
 {
@@ -99,6 +99,8 @@
                unsigned changed = cache_match_stat(ce, &st);
                if (!changed)
                        return 0;
+               if (update_mode && changed & MODE_CHANGED)
+                       chmod(ce->name, ce->st_mode);
                if (!force) {
                        if (!quiet)
                                fprintf(stderr, "checkout-cache: %s already exists\n", ce->name);
@@ -158,6 +160,10 @@
                                quiet = 1;
                                continue;
                        }
+                       if (!strcmp(arg, "-m")) {
+                               update_mode = 1;
+                               continue;
+                       }
                }
                checkout_file(arg);
        }
gitcancel.sh:  ec58f7444a42cd3cbaae919fc68c70a3866420c0
--- ec58f7444a42cd3cbaae919fc68c70a3866420c0/gitcancel.sh
+++ uncommitted/gitcancel.sh
@@ -12,7 +12,8 @@

 # FIXME: Does not revert mode changes!

-show-diff | patch -p0 -R
+show-diff | patch -p1 -R
 rm -f .git/add-queue .git/rm-queue .git/merged

+checkout-cache -q -m -a
 update-cache --refresh
gittrack.sh:  03d6db1fb3a70605ef249c632c04e542457f0808
--- 03d6db1fb3a70605ef249c632c04e542457f0808/gittrack.sh
+++ uncommitted/gittrack.sh
@@ -51,6 +51,8 @@

        read-tree $(tree-id "$name")
        gitdiff.sh local "$name" | gitapply.sh
+       checkout-cache -q -m -a
+       update-cache --refresh

 else
        [ "$tracking" ] || \
@@ -61,6 +63,8 @@
        if [ -s ".git/HEAD.local" ]; then
                gitdiff.sh "$tracking" local | gitapply.sh
                read-tree $(tree-id local)
+               checkout-cache -q -m -a
+               update-cache --refresh

                head=$(cat .git/HEAD)
                branchhead=$(cat .git/heads/$tracking)
show-diff.c:  a531ca4078525d1c8dcf84aae0bfa89fed6e5d96
--- a531ca4078525d1c8dcf84aae0bfa89fed6e5d96/show-diff.c
+++ uncommitted/show-diff.c
@@ -5,13 +5,18 @@
  */
 #include "cache.h"

-static void show_differences(char *name,
+static void show_differences(struct cache_entry *ce,
        void *old_contents, unsigned long long old_size)
 {
        static char cmd[1000];
+       static char sha1[41];
+       int n;
        FILE *f;

-       snprintf(cmd, sizeof(cmd), "diff -L %s -u -N  - %s", name, name);
+       for (n = 0; n < 20; n++)
+               snprintf(&(sha1[n*2]), 3, "%02x", ce->sha1[n]);
+       snprintf(cmd, sizeof(cmd), "diff -L %s/%s -L uncommitted/%s -u -N  - %s",
+               sha1, ce->name, ce->name, ce->name);
        f = popen(cmd, "w");
        if (old_size)
                fwrite(old_contents, old_size, 1, f);
@@ -99,7 +104,7 @@
                        continue;

                new = read_sha1_file(ce->sha1, type, &size);
-               show_differences(ce->name, new, size);
+               show_differences(ce, new, size);
                free(new);
        }
        return 0;
-- 
Martin Schlemmer



checkout-cache.c:  f06871cdbc1b18ea93bdf4e17126aeb4cca1373e
--- f06871cdbc1b18ea93bdf4e17126aeb4cca1373e/checkout-cache.c
+++ uncommitted/checkout-cache.c
@@ -34,7 +34,7 @@
  */
 #include "cache.h"
 
-static int force = 0, quiet = 0;
+static int force = 0, quiet = 0, update_mode = 0;
 
 static void create_directories(const char *path)
 {
@@ -99,6 +99,8 @@
 		unsigned changed = cache_match_stat(ce, &st);
 		if (!changed)
 			return 0;
+		if (update_mode && changed & MODE_CHANGED)
+			chmod(ce->name, ce->st_mode);
 		if (!force) {
 			if (!quiet)
 				fprintf(stderr, "checkout-cache: %s already exists\n", ce->name);
@@ -158,6 +160,10 @@
 				quiet = 1;
 				continue;
 			}
+			if (!strcmp(arg, "-m")) {
+				update_mode = 1;
+				continue;
+			}
 		}
 		checkout_file(arg);
 	}
gitcancel.sh:  ec58f7444a42cd3cbaae919fc68c70a3866420c0
--- ec58f7444a42cd3cbaae919fc68c70a3866420c0/gitcancel.sh
+++ uncommitted/gitcancel.sh
@@ -12,7 +12,8 @@
 
 # FIXME: Does not revert mode changes!
 
-show-diff | patch -p0 -R
+show-diff | patch -p1 -R
 rm -f .git/add-queue .git/rm-queue .git/merged
 
+checkout-cache -q -m -a
 update-cache --refresh
gittrack.sh:  03d6db1fb3a70605ef249c632c04e542457f0808
--- 03d6db1fb3a70605ef249c632c04e542457f0808/gittrack.sh
+++ uncommitted/gittrack.sh
@@ -51,6 +51,8 @@
 
 	read-tree $(tree-id "$name")
 	gitdiff.sh local "$name" | gitapply.sh
+	checkout-cache -q -m -a
+	update-cache --refresh
 
 else
 	[ "$tracking" ] || \
@@ -61,6 +63,8 @@
 	if [ -s ".git/HEAD.local" ]; then
 		gitdiff.sh "$tracking" local | gitapply.sh
 		read-tree $(tree-id local)
+		checkout-cache -q -m -a
+		update-cache --refresh
 
 		head=$(cat .git/HEAD)
 		branchhead=$(cat .git/heads/$tracking)
show-diff.c:  a531ca4078525d1c8dcf84aae0bfa89fed6e5d96
--- a531ca4078525d1c8dcf84aae0bfa89fed6e5d96/show-diff.c
+++ uncommitted/show-diff.c
@@ -5,13 +5,18 @@
  */
 #include "cache.h"
 
-static void show_differences(char *name,
+static void show_differences(struct cache_entry *ce,
 	void *old_contents, unsigned long long old_size)
 {
 	static char cmd[1000];
+	static char sha1[41];
+	int n;
 	FILE *f;
 
-	snprintf(cmd, sizeof(cmd), "diff -L %s -u -N  - %s", name, name);
+	for (n = 0; n < 20; n++)
+		snprintf(&(sha1[n*2]), 3, "%02x", ce->sha1[n]);
+	snprintf(cmd, sizeof(cmd), "diff -L %s/%s -L uncommitted/%s -u -N  - %s",
+		sha1, ce->name, ce->name, ce->name);
 	f = popen(cmd, "w");
 	if (old_size)
 		fwrite(old_contents, old_size, 1, f);
@@ -99,7 +104,7 @@
 			continue;
 
 		new = read_sha1_file(ce->sha1, type, &size);
-		show_differences(ce->name, new, size);
+		show_differences(ce, new, size);
 		free(new);
 	}
 	return 0;
Previous: Martin SchlemmerNext: Alex Riesen
Message 7 of 16 in “Re: Re: Re: Remove need to untrack before tracking new branch”
  1. Petr BaudisApr 13, 2005
  2. Martin SchlemmerApr 14, 2005
  3. Martin SchlemmerApr 14, 2005
  4. Martin SchlemmerApr 14, 2005
  5. Petr BaudisApr 14, 2005
  6. Martin SchlemmerApr 14, 2005
  7. Martin SchlemmerApr 14, 2005
  8. Alex RiesenApr 14, 2005
  9. Martin SchlemmerApr 15, 2005
  10. Paul JacksonApr 15, 2005
  11. Alex RiesenApr 15, 2005
  12. Petr BaudisApr 14, 2005
  13. Martin SchlemmerApr 14, 2005
  14. Petr BaudisApr 14, 2005
  15. Martin SchlemmerApr 14, 2005
  16. Martin SchlemmerApr 14, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.