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

Re: I want to release a "git-1.0"

From
DTDmitry Torokhov <dtor_core@ameritech.net>
Date
May 30, 2005, 22:55 UTC
Message-ID
<200505301755.15371.dtor_core@ameritech.net>
In-Reply-To
<20050530221214.GA29556@redhat.com>
On Monday 30 May 2005 17:12, Dave Jones wrote:
> I realise you've got a nifty bunch of tools to apply a whole mbox of
> patches, but that's not ideal if all of my patches aren't in mboxes
> (some I create myself and toss in my spool, some I pull from bugzilla etc..)

I mercilessly hacked Linus's scripts from git-tools repo to work with non-mailbox patches, maybe you can make use of them too. Note that stripspace.c is not changed in any way whatsoever and mailsplit.c was changed to handle my personal preference of having patch description in the form of:

Input: make blah blah change
---
 
And Linus's script would eat that line.
-- 
Dmitry


#include <stdio.h>
#include <string.h>
#include <ctype.h>

/*
 * Remove empty lines from the beginning and end.
 *
 * Turn multiple consecutive empty lines into just one
 * empty line.
 */
static void cleanup(char *line)
{
	int len = strlen(line);

	if (len > 1 && line[len-1] == '\n') {
		do {
			unsigned char c = line[len-2];
			if (!isspace(c))
				break;
			line[len-2] = '\n';
			len--;
			line[len] = 0;
		} while (len > 1);
	}
}

int main(int argc, char **argv)
{
	int empties = -1;
	char line[1024];

	while (fgets(line, sizeof(line), stdin)) {
		cleanup(line);

		/* Not just an empty line? */
		if (line[0] != '\n') {
			if (empties > 0)
				putchar('\n');
			empties = 0;
			fputs(line, stdout);
			continue;
		}
		if (empties < 0)
			continue;
		empties++;
	}
	return 0;
}


/*
 * Totally braindamaged mbox splitter program.
 *
 * It just splits a mbox into a list of files: "0001" "0002" ..
 * so you can process them further from there.
 */
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>

static int usage(void)
{
	fprintf(stderr, "mailsplit <mbox> <directory>\n");
	exit(1);
}

static int linelen(const char *map, unsigned long size)
{
	int len = 0, c;

	do {
		c = *map;
		map++;
		size--;
		len++;
	} while (size && c != '\n');
	return len;
}

static int is_from_line(const char *line, int len)
{
	const char *colon;

	if (len < 20 || memcmp("From ", line, 5))
		return 0;

	colon = line + len - 2;
	line += 5;
	for (;;) {
		if (colon < line)
			return 0;
		if (*--colon == ':')
			break;
	}

	if (!isdigit(colon[-4]) ||
	    !isdigit(colon[-2]) ||
	    !isdigit(colon[-1]) ||
	    !isdigit(colon[ 1]) ||
	    !isdigit(colon[ 2]))
		return 0;

	/* year */
	if (strtol(colon+3, NULL, 10) <= 90)
		return 0;

	/* Ok, close enough */
	return 1;
}

static int parse_email(const void *map, unsigned long size)
{
	unsigned long offset;

	if (size < 6 || memcmp("From ", map, 5))
		goto corrupt;

	/* Make sure we don't trigger on this first line */
	map++; size--; offset=1;

	/*
	 * Search for a line beginning with "From ", and 
	 * having smething that looks like a date format.
	 */
	do {
		int len = linelen(map, size);
		if (is_from_line(map, len))
			return offset;
		map += len;
		size -= len;
		offset += len;
	} while (size);
	return offset;

corrupt:
	fprintf(stderr, "corrupt mailbox\n");
	exit(1);
}

int main(int argc, char **argv)
{
	int fd, nr;
	struct stat st;
	unsigned long size;
	void *map;

	if (argc != 3)
		usage();
	fd = open(argv[1], O_RDONLY);
	if (fd < 0) {
		perror(argv[1]);
		exit(1);
	}
	if (chdir(argv[2]) < 0)
		usage();
	if (fstat(fd, &st) < 0) {
		perror("stat");
		exit(1);
	}
	size = st.st_size;
	map = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
	if (-1 == (int)(long)map) {
		perror("mmap");
		exit(1);
	}
	close(fd);
	nr = 0;
	do {
		char name[10];
		unsigned long len = parse_email(map, size);
		assert(len <= size);
		sprintf(name, "%04d", ++nr);
		fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600);
		if (fd < 0) {
			perror(name);
			exit(1);
		}
		if (write(fd, map, len) != len) {
			perror("write");
			exit(1);
		}
		close(fd);
		map += len;
		size -= len;
	} while (size > 0);
	return 0;
}
Previous: Dave JonesNext: Junio C Hamano
Message 12 of 64 in “I want to release a "git-1.0"”
  1. Linus TorvaldsMay 30, 2005
  2. jeff millarMay 30, 2005
  3. Nicolas PitreMay 30, 2005
  4. Junio C HamanoJun 1, 2005
  5. Add -d flag to git-pull-* family.Junio C Hamano, Jun 1, 2005
  6. Nicolas PitreJun 1, 2005
  7. Junio C HamanoJun 1, 2005
  8. Junio C HamanoMay 30, 2005
  9. Junio C HamanoMay 30, 2005
  10. David GreavesMay 30, 2005
  11. Dave JonesMay 30, 2005
  12. Dmitry TorokhovMay 30, 2005
  13. Junio C HamanoMay 30, 2005
  14. Dmitry TorokhovMay 30, 2005
  15. Linus TorvaldsMay 31, 2005
  16. Ryan AndersonMay 30, 2005
  17. Linus TorvaldsMay 31, 2005
  18. Chris WedgwoodMay 30, 2005
  19. Chris WedgwoodMay 30, 2005
  20. Linus TorvaldsMay 31, 2005
  21. Junio C HamanoJun 1, 2005
  22. David LangJun 1, 2005
  23. Junio C HamanoJun 1, 2005
  24. David LangJun 1, 2005
  25. C. Scott AnanianJun 1, 2005
  26. Nicolas PitreJun 2, 2005
  27. Brian O'MahoneyJun 2, 2005
  28. Junio C HamanoJun 1, 2005
  29. Petr BaudisMay 31, 2005
  30. Eric W. BiedermanMay 31, 2005
  31. Linus TorvaldsJun 1, 2005
  32. Junio C HamanoJun 1, 2005
  33. Fix -B "very-different" logic.Junio C Hamano, Jun 2, 2005
  34. Linus TorvaldsJun 3, 2005
  35. Junio C HamanoJun 3, 2005
  36. 0/4 Fix -B "very-different" logic.Junio C Hamano, Jun 3, 2005
  37. 1/4 Tweak count-delta interfaceJunio C Hamano, Jun 3, 2005
  38. 2/4 diff: Fix docs and add -O to diff-helper.Junio C Hamano, Jun 3, 2005
  39. 3/4 diff: Clean up diff_scoreopt_parse().Junio C Hamano, Jun 3, 2005
  40. 4/4 diff: Update -B heuristics.Junio C Hamano, Jun 3, 2005
  41. Junio C HamanoJun 1, 2005
  42. Daniel BarkalowJun 1, 2005
  43. Junio C HamanoJun 1, 2005
  44. Petr BaudisJun 3, 2005
  45. Daniel BarkalowJun 3, 2005
  46. Eric W. BiedermanJun 2, 2005
  47. Kay SieversJun 2, 2005
  48. Linus TorvaldsJun 2, 2005
  49. several typos in tutorialAlexey Nezhdanov, Jun 2, 2005
  50. Vincent HanquezJun 2, 2005
  51. Alexey NezhdanovJun 2, 2005
  52. Vincent HanquezJun 2, 2005
  53. Alexey NezhdanovJun 2, 2005
  54. Alexey NezhdanovJun 2, 2005
  55. Adam KropelinJun 2, 2005
  56. Linus TorvaldsJun 3, 2005
  57. Linus TorvaldsJun 3, 2005
  58. Adam KropelinJun 3, 2005
  59. CVS migration section to the tutorial.Junio C Hamano, Jun 2, 2005
  60. Nicolas PitreJun 2, 2005
  61. Nicolas PitreJun 2, 2005
  62. Junio C HamanoJun 2, 2005
  63. Linus TorvaldsJun 2, 2005
  64. Junio C HamanoJun 2, 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.