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

Re: conflict status

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 4, 2009, 07:56 UTC
Message-ID
<7vhbwoypu4.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4F52523A-2CEA-4CD3-A094-A2627E2A4403@users.sourceforge.net>
Michael Wild <themiwi@users.sourceforge.net> writes:
Show 14 quoted lines
> # get all conflicts
> conflicts="$(git-status | awk '/unmerged:/{print $3;next}')"
>
> for f in $conflicts; do
>   # extract the file mode for base, local and remote
>   base_mode=$(git ls-files -u -- "$f" | awk '{if ($3==1) print $1;}')
>   local_mode=$(git ls-files -u -- "$f" | awk '{if ($3==2) print $1;}')
>   remote_mode=$(git ls-files -u -- "$f" | awk '{if ($3==3) print $1;}')
>   # create the status flags
>   describe_state "$local_mode"
>   describe_state "$remote_mode"
>   # append the file name
>   echo " $f"
> done

Looks an awfully inefficient way to say "git ls-files -u" to me. If you do not see stage 2, you do not have it. If you do not see stage 3, they do not have it.

If you really really want to condense the object name information out, you could do something like this.

-- >8 --
#!/bin/sh
git ls-files -u -z |
perl -e '
	$/ = "\0";
        my ($last_path, @stage);
        sub describe_mode {
        	my $ours = $_[0];
		my $sign;
                if (!defined $ours) {
                	$sign = "d";
		} elsif (defined $stage[1]) {
                	$sign = "m";
		} else {
			$sign = "c";
                }
		return $sign;
        }
	sub flush_path {
        	printf("%s %s %s\n",
                	describe_mode($stage[2]),
                	describe_mode($stage[3]),
			$last_path);
		$last_path = undef;
        	@stage = ();
        }
        while (<>) {
		chomp;
        	my ($mode, $sha1, $stage, $path) =
                	/^([0-7]+) ([0-9a-f]{40}) ([1-3])\t(.*)$/;
		if (defined $last_path) {
			flush_path() if ($path ne $last_path);
                }
                $stage[$stage] = 1;
                $last_path = $path;
	}
        if (defined $last_path) {
                flush_path() if ($path ne $last_path);
        }
'
-- 8< --
I however do not think it is all that interesting, though.
Previous: Michael Wild
Message 8 of 8 in “conflict status”
  1. Michael WildAug 3, 2009
  2. Sverre RabbelierAug 3, 2009
  3. Thomas RastAug 3, 2009
  4. Junio C HamanoAug 3, 2009
  5. Michael WildAug 4, 2009
  6. Jakub NarebskiAug 4, 2009
  7. Michael WildAug 4, 2009
  8. Junio C HamanoAug 4, 2009

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.